diff options
| author | Arne Dußin | 2021-02-24 16:12:32 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-24 16:12:32 +0100 |
| commit | 05aa0f9399cbebce6eb4cf14eb198f6cb33ea7fd (patch) | |
| tree | a165b8fe0ca299190232ab15e4a3ab56578aea78 | |
| parent | 6b52a88dad43467ae0ea23e96248e934a995570b (diff) | |
| download | graf_karto-05aa0f9399cbebce6eb4cf14eb198f6cb33ea7fd.tar.gz graf_karto-05aa0f9399cbebce6eb4cf14eb198f6cb33ea7fd.zip | |
Icons now use a default configuration should they have no ron file
Previously, every icon needed to have a ron file associated. It was pointed out,
that most of the time the anchor should just be in the middle of the icon and a
default pixels per meter can be used. When a ron file is created, both of these
have to be specified, but that should change in the future as well.
| -rw-r--r-- | src/client/map/icon_texture_manager.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/client/map/icon_texture_manager.rs b/src/client/map/icon_texture_manager.rs index c6b7fea..b64638c 100644 --- a/src/client/map/icon_texture_manager.rs +++ b/src/client/map/icon_texture_manager.rs @@ -10,6 +10,9 @@ use std::fs::{self, File}; /// The directory containing all files related to icons. pub const ICON_DIR: &str = "assets/icons"; +/// Default amount of pixels per meter, which is used, when an icon does not have +/// an associated ron-file, which sets them explicitly. +pub const ICON_DEFAULT_PPM: f64 = 256.; #[derive(Deserialize)] pub(super) struct IconFileInfo { @@ -65,9 +68,18 @@ impl IconTextureManager { let mut file = file.path(); file.set_extension("ron"); - let ron = File::open(file).expect("Could not read ron file for icon information."); - let icon_info: IconFileInfo = - from_reader(ron).expect("Could not parse icon info from reader."); + + /* Try to read the ron file containing information about this icon. + * If no ron-file is found, the anchor is set to the middle of the + * texture, and the default pixels per meter value is used. */ + let icon_info = if let Ok(ron) = File::open(file) { + from_reader(ron).expect("Could not parse icon info from reader.") + } else { + IconFileInfo { + anchor: Vec2::new(texture.width as f64, texture.height as f64), + pixels_per_m: ICON_DEFAULT_PPM, + } + }; texture_data.push((texture, icon_info)); } |
