diff --git a/common/src/assets.rs b/common/src/assets.rs index 0eae5ceb33..a10339d3a0 100644 --- a/common/src/assets.rs +++ b/common/src/assets.rs @@ -4,11 +4,18 @@ use dot_vox::DotVoxData; use image::DynamicImage; use lazy_static::lazy_static; use serde::Deserialize; -use std::{borrow::Cow, fs, io, path::{Path, PathBuf}, sync::Arc}; +use std::{ + borrow::Cow, + fs, io, + path::{Path, PathBuf}, + sync::Arc, +}; pub use assets_manager::{ - Asset, AssetCache, BoxedError, Compound, Error, source, - loader::{self, BytesLoader, BincodeLoader, Loader, JsonLoader, LoadFrom, RonLoader, StringLoader}, + loader::{ + self, BincodeLoader, BytesLoader, JsonLoader, LoadFrom, Loader, RonLoader, StringLoader, + }, + source, Asset, AssetCache, BoxedError, Compound, Error, }; lazy_static! { @@ -16,9 +23,7 @@ lazy_static! { static ref ASSETS: AssetCache = AssetCache::new(&*ASSETS_PATH).unwrap(); } -pub fn start_hot_reloading() { - ASSETS.enhance_hot_reloading(); -} +pub fn start_hot_reloading() { ASSETS.enhance_hot_reloading(); } pub type AssetHandle = assets_manager::Handle<'static, T>; pub type AssetDir = assets_manager::DirReader<'static, T, source::FileSystem>; @@ -79,21 +84,15 @@ pub fn load_dir(specifier: &str) -> Result, Error> { } impl AssetExt for T { - fn load(specifier: &str) -> Result, Error> { - ASSETS.load(specifier) - } + fn load(specifier: &str) -> Result, Error> { ASSETS.load(specifier) } - fn load_owned(specifier: &str) -> Result { - ASSETS.load_owned(specifier) - } + fn load_owned(specifier: &str) -> Result { ASSETS.load_owned(specifier) } } pub struct Image(pub Arc); impl Image { - pub fn to_image(&self) -> Arc { - self.0.clone() - } + pub fn to_image(&self) -> Arc { self.0.clone() } } pub struct ImageLoader; @@ -105,8 +104,9 @@ impl Loader for ImageLoader { } impl Asset for Image { - const EXTENSIONS: &'static [&'static str] = &["png", "jpg"]; type Loader = ImageLoader; + + const EXTENSIONS: &'static [&'static str] = &["png", "jpg"]; } pub struct DotVoxAsset(pub DotVoxData); @@ -128,14 +128,15 @@ impl Asset for Ron where T: Send + Sync + for<'de> Deserialize<'de> + 'static, { - const EXTENSION: &'static str = "ron"; type Loader = RonLoader; + + const EXTENSION: &'static str = "ron"; } - impl Asset for DotVoxAsset { - const EXTENSION: &'static str = "vox"; type Loader = DotVoxLoader; + + const EXTENSION: &'static str = "vox"; } lazy_static! { @@ -242,9 +243,7 @@ fn get_dir_files(files: &mut Vec, path: &Path, specifier: &str) -> io::R pub struct Directory(Vec); impl Directory { - pub fn iter(&self) -> impl Iterator { - self.0.iter() - } + pub fn iter(&self) -> impl Iterator { self.0.iter() } } impl Compound for Directory { @@ -256,4 +255,4 @@ impl Compound for Directory { Ok(Directory(files)) } -} \ No newline at end of file +} diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index e2b401c1ce..b2375f04b7 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -16,8 +16,8 @@ use arraygen::Arraygen; use serde::{Deserialize, Serialize}; use specs::{Component, FlaggedStorage}; use specs_idvs::IdvStorage; -use tracing::error; use std::time::Duration; +use tracing::error; use vek::Vec3; #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)] @@ -239,14 +239,14 @@ impl Default for CharacterAbility { } impl Asset for CharacterAbility { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + const EXTENSION: &'static str = "ron"; + fn default_value(specifier: &str, err: assets::Error) -> Result { error!( ?err, - "Error loading CharacterAbility: {} for the ability \ - map: replacing with default", + "Error loading CharacterAbility: {} for the ability map: replacing with default", specifier ); diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index f670597369..eee67542ec 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -126,8 +126,9 @@ impl< SpeciesMeta: Send + Sync + for<'de> serde::Deserialize<'de> + 'static, > Asset for AllBodies { - const EXTENSION: &'static str = "json"; type Loader = assets::JsonLoader; + + const EXTENSION: &'static str = "json"; } impl Body { diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index d5613f539d..749d4593cf 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -159,13 +159,27 @@ impl PartialEq for Item { } impl assets::Compound for ItemDef { - fn load(cache: &assets_manager::AssetCache, specifier: &str) -> Result { + fn load( + cache: &assets_manager::AssetCache, + specifier: &str, + ) -> Result { let raw = cache.load_owned::(specifier)?; - let RawItemDef { name, description, kind, quality} = raw; + let RawItemDef { + name, + description, + kind, + quality, + } = raw; let item_definition_id = specifier.replace('\\', "."); - Ok(ItemDef { item_definition_id, name, description, kind, quality }) + Ok(ItemDef { + item_definition_id, + name, + description, + kind, + quality, + }) } } @@ -179,16 +193,15 @@ struct RawItemDef { } impl assets::Asset for RawItemDef { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } impl Item { // TODO: consider alternatives such as default abilities that can be added to a // loadout when no weapon is present - pub fn empty() -> Self { - Item::new_from_asset_expect("common.items.weapons.empty.empty") - } + pub fn empty() -> Self { Item::new_from_asset_expect("common.items.weapons.empty.empty") } pub fn new(inner_item: Arc) -> Self { Item { @@ -212,7 +225,8 @@ impl Item { let specifiers = assets::Directory::load(asset_glob)?; - specifiers.read() + specifiers + .read() .iter() .map(|spec| Self::new_from_asset(&spec)) .collect() @@ -334,7 +348,8 @@ impl Item { 3 => "common.loot_tables.loot_table_armor_cloth", 4 => "common.loot_tables.loot_table_armor_heavy", _ => "common.loot_tables.loot_table_armor_misc", - }).read(); + }) + .read(); chosen.choose() }, SpriteKind::ChestBurried => { @@ -343,7 +358,8 @@ impl Item { 2 => "common.loot_tables.loot_table_armor_light", 3 => "common.loot_tables.loot_table_armor_cloth", _ => "common.loot_tables.loot_table_armor_misc", - }).read(); + }) + .read(); chosen.choose() }, SpriteKind::Mud => { @@ -352,14 +368,16 @@ impl Item { 1 => "common.loot_tables.loot_table_weapon_common", 2 => "common.loot_tables.loot_table_armor_misc", _ => "common.loot_tables.loot_table_rocks", - }).read(); + }) + .read(); chosen.choose() }, SpriteKind::Crate => { chosen = Lottery::::load_expect(match rng.gen_range(0, 4) { 0 => "common.loot_tables.loot_table_crafting", _ => "common.loot_tables.loot_table_food", - }).read(); + }) + .read(); chosen.choose() }, SpriteKind::Beehive => "common.items.crafting_ing.honey", diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 137d0121df..3d489a09ee 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -144,26 +144,31 @@ impl Default for AbilitySet { pub struct AbilityMap(HashMap>); impl Asset for AbilityMap { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } impl assets::Compound for AbilityMap { - fn load(cache: &assets_manager::AssetCache, specifier: &str) -> Result { + fn load( + cache: &assets_manager::AssetCache, + specifier: &str, + ) -> Result { let manifest = cache.load::>(specifier)?.read(); Ok(AbilityMap( - manifest.0 + manifest + .0 .iter() .map(|(kind, set)| { ( kind.clone(), // expect cannot fail because CharacterAbility always // provides a default value in case of failure - set.map_ref(|s| cache.load_expect(&s).cloned()) + set.map_ref(|s| cache.load_expect(&s).cloned()), ) }) - .collect() + .collect(), )) } } diff --git a/common/src/lottery.rs b/common/src/lottery.rs index 25220badb0..4aaa7db851 100644 --- a/common/src/lottery.rs +++ b/common/src/lottery.rs @@ -9,8 +9,9 @@ pub struct Lottery { } impl assets::Asset for Lottery { - const EXTENSION: &'static str = "ron"; type Loader = assets::LoadFrom, assets::RonLoader>; + + const EXTENSION: &'static str = "ron"; } impl From> for Lottery { diff --git a/common/src/npc.rs b/common/src/npc.rs index 8bcf736d28..87f4e72fc7 100644 --- a/common/src/npc.rs +++ b/common/src/npc.rs @@ -88,7 +88,10 @@ pub fn get_npc_name(npc_type: NpcKind) -> String { let BodyNames { keyword, names } = &npc_names[npc_type]; // If no pretty name is found, fall back to the keyword. - names.choose(&mut rand::thread_rng()).unwrap_or(keyword).clone() + names + .choose(&mut rand::thread_rng()) + .unwrap_or(keyword) + .clone() } /// Randomly generates a body associated with this NPC kind. diff --git a/common/src/recipe.rs b/common/src/recipe.rs index 103dd98cd0..7eb6d354ae 100644 --- a/common/src/recipe.rs +++ b/common/src/recipe.rs @@ -70,13 +70,16 @@ impl RecipeBook { struct RawRecipeBook(HashMap)>); impl assets::Asset for RawRecipeBook { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } impl assets::Compound for RecipeBook { - - fn load(cache: &assets_manager::AssetCache, specifier: &str) -> Result { + fn load( + cache: &assets_manager::AssetCache, + specifier: &str, + ) -> Result { #[inline] fn load_item_def(spec: &(String, u32)) -> Result<(Arc, u32), assets::Error> { let def = Arc::::load_cloned(&spec.0)?; @@ -85,11 +88,11 @@ impl assets::Compound for RecipeBook { let raw = cache.load::(specifier)?.read(); - let recipes = raw.0.iter() + let recipes = raw + .0 + .iter() .map(|(name, (output, inputs))| { - let inputs = inputs.iter() - .map(load_item_def) - .collect::>()?; + let inputs = inputs.iter().map(load_item_def).collect::>()?; let output = load_item_def(output)?; Ok((name.clone(), Recipe { inputs, output })) }) diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 799c920533..57235240c5 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -53,17 +53,20 @@ pub struct StructuresGroup(Vec); impl std::ops::Deref for StructuresGroup { type Target = [Structure]; - fn deref(&self) -> &[Structure] { - &self.0 - } + fn deref(&self) -> &[Structure] { &self.0 } } impl assets::Compound for StructuresGroup { - fn load(cache: &assets_manager::AssetCache, specifier: &str) -> Result { + fn load( + cache: &assets_manager::AssetCache, + specifier: &str, + ) -> Result { let specs = cache.load::(specifier)?.read(); Ok(StructuresGroup( - specs.0.iter() + specs + .0 + .iter() .map(|sp| { let base = cache.load::>(&sp.specifier)?.cloned(); Ok(Structure { @@ -71,7 +74,7 @@ impl assets::Compound for StructuresGroup { base, }) }) - .collect::>()? + .collect::>()?, )) } } @@ -112,7 +115,10 @@ impl ReadVol for Structure { } impl assets::Compound for BaseStructure { - fn load(cache: &assets_manager::AssetCache, specifier: &str) -> Result { + fn load( + cache: &assets_manager::AssetCache, + specifier: &str, + ) -> Result { let dot_vox_data = cache.load::(specifier)?.read(); let dot_vox_data = &dot_vox_data.0; @@ -182,6 +188,7 @@ struct StructureSpec { struct StructuresGroupSpec(Vec); impl assets::Asset for StructuresGroupSpec { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; -} \ No newline at end of file + + const EXTENSION: &'static str = "ron"; +} diff --git a/voxygen/src/audio/ambient.rs b/voxygen/src/audio/ambient.rs index a041d3fb76..c8dfe4c907 100644 --- a/voxygen/src/audio/ambient.rs +++ b/voxygen/src/audio/ambient.rs @@ -4,7 +4,10 @@ use crate::{ scene::Camera, }; use client::Client; -use common::{assets::{self, AssetExt, AssetHandle}, vol::ReadVol}; +use common::{ + assets::{self, AssetExt, AssetHandle}, + vol::ReadVol, +}; use common_sys::state::State; use serde::Deserialize; use std::time::Instant; @@ -130,14 +133,16 @@ impl AmbientMgr { } impl assets::Asset for AmbientCollection { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + const EXTENSION: &'static str = "ron"; + fn default_value(_: &str, error: assets::Error) -> Result { warn!( - "Error reading music config file, music will not be available: {:#?}", error + "Error reading music config file, music will not be available: {:#?}", + error ); Ok(AmbientCollection::default()) } -} \ No newline at end of file +} diff --git a/voxygen/src/audio/music.rs b/voxygen/src/audio/music.rs index f0a0df3bf1..e3d5b7ec09 100644 --- a/voxygen/src/audio/music.rs +++ b/voxygen/src/audio/music.rs @@ -232,14 +232,16 @@ impl MusicMgr { } impl assets::Asset for SoundtrackCollection { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + const EXTENSION: &'static str = "ron"; + fn default_value(_: &str, error: assets::Error) -> Result { warn!( - "Error reading music config file, music will not be available: {:#?}", error + "Error reading music config file, music will not be available: {:#?}", + error ); Ok(SoundtrackCollection::default()) } -} \ No newline at end of file +} diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 96403477f5..de1e1bdc26 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -368,14 +368,16 @@ impl SfxMgr { } impl assets::Asset for SfxTriggers { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + const EXTENSION: &'static str = "ron"; + fn default_value(_: &str, error: assets::Error) -> Result { warn!( - "Error reading sfx config file, sfx will not be available: {:#?}", error + "Error reading sfx config file, sfx will not be available: {:#?}", + error ); Ok(SfxTriggers::default()) } -} \ No newline at end of file +} diff --git a/voxygen/src/audio/soundcache.rs b/voxygen/src/audio/soundcache.rs index bb8eb22958..943b584fa4 100644 --- a/voxygen/src/audio/soundcache.rs +++ b/voxygen/src/audio/soundcache.rs @@ -23,9 +23,10 @@ impl assets::Loader for SoundLoader { } impl assets::Asset for WavSound { - const EXTENSION: &'static str = "wav"; type Loader = SoundLoader; + const EXTENSION: &'static str = "wav"; + fn default_value(specifier: &str, error: assets::Error) -> Result { warn!(?specifier, ?error, "Failed to load sound"); @@ -40,9 +41,9 @@ impl WavSound { rodio::Decoder::new(cursor).unwrap() } - /// Returns a `WavSound` containing empty .wav data. This intentionally doesn't - /// load from the filesystem so we have a reliable fallback when there - /// is a failure to read a file. + /// Returns a `WavSound` containing empty .wav data. This intentionally + /// doesn't load from the filesystem so we have a reliable fallback when + /// there is a failure to read a file. /// /// The data below is the result of passing a very short, silent .wav file /// to `Sound::load()`. @@ -69,8 +70,9 @@ impl assets::Loader for SoundLoader { } impl assets::Asset for OggSound { - const EXTENSION: &'static str = "ogg"; type Loader = SoundLoader; + + const EXTENSION: &'static str = "ogg"; } /// Wrapper for decoded audio data @@ -79,4 +81,4 @@ impl OggSound { let cursor = io::Cursor::new(self); rodio::Decoder::new(cursor).unwrap() } -} \ No newline at end of file +} diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index d804c1b302..dadfc98965 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -84,8 +84,9 @@ impl ImageSpec { #[derive(Serialize, Deserialize)] struct ItemImagesSpec(HashMap); impl assets::Asset for ItemImagesSpec { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } // TODO: when there are more images don't load them all into memory @@ -97,7 +98,7 @@ pub struct ItemImgs { impl ItemImgs { pub fn new(ui: &mut Ui, not_found: Id) -> Self { - let manifest = ItemImagesSpec::load_expect("voxygen.item_image_manifest"); + let manifest = ItemImagesSpec::load_expect("voxygen.item_image_manifest"); let map = manifest .read() .0 diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index a66e24c033..3662b0695d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -659,7 +659,8 @@ impl Hud { // Load item images. let item_imgs = ItemImgs::new(&mut ui, imgs.not_found); // Load fonts. - let fonts = Fonts::load(&global_state.i18n.read().fonts, &mut ui).expect("Impossible to load fonts!"); + let fonts = Fonts::load(&global_state.i18n.read().fonts, &mut ui) + .expect("Impossible to load fonts!"); // Get the server name. let server = &client.server_info().name; // Get the id, unwrap is safe because this CANNOT be None at this @@ -2289,9 +2290,7 @@ impl Hud { } if self.show.esc_menu { - match EscMenu::new(&self.imgs, &self.fonts, i18n) - .set(self.ids.esc_menu, ui_widgets) - { + match EscMenu::new(&self.imgs, &self.fonts, i18n).set(self.ids.esc_menu, ui_widgets) { Some(esc_menu::Event::OpenSettings(tab)) => { self.show.open_setting_tab(tab); }, diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 6b39396687..8cb16b4e2d 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -135,8 +135,9 @@ impl Localization { } impl assets::Asset for Localization { - const EXTENSION: &'static str = "ron"; type Loader = LocalizationLoader; + + const EXTENSION: &'static str = "ron"; } pub struct LocalizationLoader; @@ -166,9 +167,7 @@ pub fn list_localizations() -> Vec { assets::load_dir::("voxygen.i18n") .unwrap() .iter_all() - .filter_map(|(_, lang)| { - lang.ok().map(|e| e.read().metadata.clone()) - }) + .filter_map(|(_, lang)| lang.ok().map(|e| e.read().metadata.clone())) .collect() } diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index a8794f937a..48d2a9a44d 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -157,19 +157,17 @@ fn main() { // Load the profile. let profile = Profile::load(); - let i18n = Localization::load( - &i18n_asset_key(&settings.language.selected_language), - ) - .unwrap_or_else(|error| { - let selected_language = &settings.language.selected_language; - warn!( - ?error, - ?selected_language, - "Impossible to load language: change to the default language (English) instead.", - ); - settings.language.selected_language = i18n::REFERENCE_LANG.to_owned(); - Localization::load_expect(&i18n_asset_key(&settings.language.selected_language)) - }); + let i18n = Localization::load(&i18n_asset_key(&settings.language.selected_language)) + .unwrap_or_else(|error| { + let selected_language = &settings.language.selected_language; + warn!( + ?error, + ?selected_language, + "Impossible to load language: change to the default language (English) instead.", + ); + settings.language.selected_language = i18n::REFERENCE_LANG.to_owned(); + Localization::load_expect(&i18n_asset_key(&settings.language.selected_language)) + }); i18n.read().log_missing_entries(); // Create window diff --git a/voxygen/src/menu/char_selection/ui/mod.rs b/voxygen/src/menu/char_selection/ui/mod.rs index 787e7be17a..29afbfe713 100644 --- a/voxygen/src/menu/char_selection/ui/mod.rs +++ b/voxygen/src/menu/char_selection/ui/mod.rs @@ -263,11 +263,7 @@ enum Message { } impl Controls { - fn new( - fonts: Fonts, - imgs: Imgs, - selected: Option, - ) -> Self { + fn new(fonts: Fonts, imgs: Imgs, selected: Option) -> Self { let version = common::util::DISPLAY_VERSION_LONG.clone(); let alpha = format!("Veloren {}", common::util::DISPLAY_VERSION.as_str()); @@ -1467,8 +1463,8 @@ impl CharSelectionUi { let font = ui::ice::load_font(&i18n.fonts.get("cyri").unwrap().asset_key); self.ui.clear_fonts(font); - self.controls.fonts = Fonts::load(&i18n.fonts, &mut self.ui) - .expect("Impossible to load fonts!"); + self.controls.fonts = + Fonts::load(&i18n.fonts, &mut self.ui).expect("Impossible to load fonts!"); } pub fn set_scale_mode(&mut self, scale_mode: ui::ScaleMode) { diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 20b57bea76..37ffc6472a 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -48,7 +48,8 @@ impl PlayState for MainMenuState { } // Updated localization in case the selected language was changed - self.main_menu_ui.update_language(global_state.i18n, &global_state.settings); + self.main_menu_ui + .update_language(global_state.i18n, &global_state.settings); // Set scale mode in case it was change self.main_menu_ui .set_scale_mode(global_state.settings.gameplay.ui_scale); @@ -264,10 +265,8 @@ impl PlayState for MainMenuState { &global_state.settings.language.selected_language, )); global_state.i18n.read().log_missing_entries(); - self.main_menu_ui.update_language( - global_state.i18n, - &global_state.settings, - ); + self.main_menu_ui + .update_language(global_state.i18n, &global_state.settings); }, #[cfg(feature = "singleplayer")] MainMenuEvent::StartSingleplayer => { diff --git a/voxygen/src/menu/main/ui/mod.rs b/voxygen/src/menu/main/ui/mod.rs index 5a4ec32cb9..f394c4ee9c 100644 --- a/voxygen/src/menu/main/ui/mod.rs +++ b/voxygen/src/menu/main/ui/mod.rs @@ -10,7 +10,7 @@ use crate::{ ui::{ self, fonts::IcedFonts as Fonts, - ice::{style, widget, Element, IcedUi as Ui, load_font}, + ice::{load_font, style, widget, Element, IcedUi as Ui}, img_ids::{ImageGraphic, VoxelGraphic}, Graphic, }, @@ -513,8 +513,8 @@ impl<'a> MainMenuUi { let i18n = &*i18n.read(); let font = load_font(&i18n.fonts.get("cyri").unwrap().asset_key); self.ui.clear_fonts(font); - self.controls.fonts = Fonts::load(&i18n.fonts, &mut self.ui) - .expect("Impossible to load fonts!"); + self.controls.fonts = + Fonts::load(&i18n.fonts, &mut self.ui).expect("Impossible to load fonts!"); let language_metadatas = crate::i18n::list_localizations(); self.controls.selected_language_index = language_metadatas .iter() diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 7e08d87524..f1ae11e340 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -102,14 +102,13 @@ pub type ColLightInfo = ( pub struct Glsl(String); impl From for Glsl { - fn from(s: String) -> Glsl { - Glsl(s) - } + fn from(s: String) -> Glsl { Glsl(s) } } impl assets::Asset for Glsl { - const EXTENSION: &'static str = "glsl"; type Loader = assets::LoadFrom; + + const EXTENSION: &'static str = "glsl"; } struct Shaders { @@ -164,7 +163,10 @@ struct Shaders { impl assets::Compound for Shaders { // TODO: Taking the specifier argument as a base for shaders specifiers // would allow to use several shaders groups easily - fn load(_: &assets::AssetCache, _: &str) -> Result { + fn load( + _: &assets::AssetCache, + _: &str, + ) -> Result { Ok(Shaders { constants: AssetExt::load("voxygen.shaders.include.constants")?, globals: AssetExt::load("voxygen.shaders.include.globals")?, @@ -185,8 +187,12 @@ impl assets::Compound for Shaders { figure_vert: AssetExt::load("voxygen.shaders.figure-vert")?, terrain_point_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-vert")?, - terrain_directed_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-directed-vert")?, - figure_directed_shadow_vert: AssetExt::load("voxygen.shaders.light-shadows-figure-vert")?, + terrain_directed_shadow_vert: AssetExt::load( + "voxygen.shaders.light-shadows-directed-vert", + )?, + figure_directed_shadow_vert: AssetExt::load( + "voxygen.shaders.light-shadows-figure-vert", + )?, directed_shadow_frag: AssetExt::load("voxygen.shaders.light-shadows-directed-frag")?, skybox_vert: AssetExt::load("voxygen.shaders.skybox-vert")?, @@ -323,12 +329,7 @@ impl Renderer { point_shadow_pipeline, terrain_directed_shadow_pipeline, figure_directed_shadow_pipeline, - ) = create_pipelines( - &mut factory, - &shaders.read(), - &mode, - shadow_views.is_some(), - )?; + ) = create_pipelines(&mut factory, &shaders.read(), &mode, shadow_views.is_some())?; let ( tgt_color_view, @@ -1994,7 +1995,9 @@ fn create_pipelines( &match mode.fluid { FluidMode::Cheap => shaders.fluid_frag_cheap, FluidMode::Shiny => shaders.fluid_frag_shiny, - }.read().0, + } + .read() + .0, &include_ctx, gfx::state::CullFace::Nothing, )?; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 777e84e5fd..13676cba11 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -128,8 +128,9 @@ struct SpriteConfig { struct SpriteSpec(sprite::sprite_kind::PureCases>>); impl assets::Asset for SpriteSpec { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } /// Function executed by worker threads dedicated to chunk meshing. @@ -276,7 +277,8 @@ impl Terrain { #[allow(clippy::float_cmp)] // TODO: Pending review in #587 pub fn new(renderer: &mut Renderer) -> Self { // Load all the sprite config data. - let sprite_config = Arc::::load_expect("voxygen.voxel.sprite_manifest").cloned(); + let sprite_config = + Arc::::load_expect("voxygen.voxel.sprite_manifest").cloned(); // Create a new mpsc (Multiple Produced, Single Consumer) pair for communicating // with worker threads that are meshing chunks. diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 4362242392..779e26f0cc 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -119,11 +119,7 @@ impl SessionState { self.hud.new_message(m); }, client::Event::InventoryUpdated(inv_event) => { - let sfx_triggers = self - .scene - .sfx_mgr - .triggers - .read(); + let sfx_triggers = self.scene.sfx_mgr.triggers.read(); let sfx_trigger_item = sfx_triggers.get_key_value(&SfxEvent::from(&inv_event)); global_state.audio.emit_sfx_item(sfx_trigger_item); @@ -167,7 +163,11 @@ impl SessionState { client::Event::Kicked(reason) => { global_state.info_message = Some(format!( "{}: {}", - global_state.i18n.read().get("main.login.kicked").to_string(), + global_state + .i18n + .read() + .get("main.login.kicked") + .to_string(), reason )); return Ok(TickAction::Disconnect); @@ -674,8 +674,13 @@ impl PlayState for SessionState { Ok(TickAction::Continue) => {}, // Do nothing Ok(TickAction::Disconnect) => return PlayStateResult::Pop, // Go to main menu Err(err) => { - global_state.info_message = - Some(global_state.i18n.read().get("common.connection_lost").to_owned()); + global_state.info_message = Some( + global_state + .i18n + .read() + .get("common.connection_lost") + .to_owned(), + ); error!("[session] Failed to tick the scene: {:?}", err); return PlayStateResult::Pop; @@ -1010,9 +1015,9 @@ impl PlayState for SessionState { HudEvent::ChangeLanguage(new_language) => { global_state.settings.language.selected_language = new_language.language_identifier; - global_state.i18n = Localization::load_expect( - &i18n_asset_key(&global_state.settings.language.selected_language), - ); + global_state.i18n = Localization::load_expect(&i18n_asset_key( + &global_state.settings.language.selected_language, + )); global_state.i18n.read().log_missing_entries(); self.hud.update_fonts(&global_state.i18n.read()); }, diff --git a/voxygen/src/ui/ice/cache.rs b/voxygen/src/ui/ice/cache.rs index d21df16692..2757450571 100644 --- a/voxygen/src/ui/ice/cache.rs +++ b/voxygen/src/ui/ice/cache.rs @@ -5,7 +5,10 @@ use crate::{ }; use common::assets::{self, AssetExt}; use glyph_brush::GlyphBrushBuilder; -use std::{borrow::Cow, cell::{RefCell, RefMut}}; +use std::{ + borrow::Cow, + cell::{RefCell, RefMut}, +}; use vek::*; // Multiplied by current window size @@ -31,13 +34,12 @@ impl assets::Loader for FontLoader { } impl assets::Asset for FontAsset { - const EXTENSION: &'static str = "ttf"; type Loader = FontLoader; + + const EXTENSION: &'static str = "ttf"; } -pub fn load_font(specifier: &str) -> Font { - FontAsset::load_expect(specifier).read().0.clone() -} +pub fn load_font(specifier: &str) -> Font { FontAsset::load_expect(specifier).read().0.clone() } #[derive(Clone, Copy, Default)] pub struct FontId(pub(super) glyph_brush::FontId); @@ -142,12 +144,11 @@ impl Cache { pub struct RawFont(pub Vec); impl From> for RawFont { - fn from(raw: Vec) -> RawFont { - RawFont(raw) - } + fn from(raw: Vec) -> RawFont { RawFont(raw) } } impl assets::Asset for RawFont { - const EXTENSION: &'static str = "ttf"; type Loader = assets::LoadFrom, assets::BytesLoader>; + + const EXTENSION: &'static str = "ttf"; } diff --git a/voxygen/src/ui/ice/mod.rs b/voxygen/src/ui/ice/mod.rs index ea02cfaa92..47515babe6 100644 --- a/voxygen/src/ui/ice/mod.rs +++ b/voxygen/src/ui/ice/mod.rs @@ -4,7 +4,7 @@ pub mod component; mod renderer; pub mod widget; -pub use cache::{Font, FontId, RawFont, load_font}; +pub use cache::{load_font, Font, FontId, RawFont}; pub use graphic::{Id, Rotation}; pub use iced::Event; pub use iced_winit::conversion::window_event; diff --git a/world/src/index.rs b/world/src/index.rs index a964780cfe..928a51d371 100644 --- a/world/src/index.rs +++ b/world/src/index.rs @@ -26,8 +26,8 @@ pub struct IndexOwned { colors: Arc, index: Arc, - /// Stored separatly so `colors` is only updated when `reload_colors_if_changed` - /// is called + /// Stored separatly so `colors` is only updated when + /// `reload_colors_if_changed` is called colors_handle: AssetHandle>, } diff --git a/world/src/layer/mod.rs b/world/src/layer/mod.rs index 72ecaf8fa1..22c023023f 100644 --- a/world/src/layer/mod.rs +++ b/world/src/layer/mod.rs @@ -183,7 +183,8 @@ pub fn apply_caves_to(canvas: &mut Canvas) { && cave_base < surface_z as i32 - 25 { let lottery = Lottery::::load_expect("common.cave_scatter").read(); - let kind = *lottery.choose_seeded(RandomField::new(info.index().seed + 1).get(wpos2d.into())); + let kind = *lottery + .choose_seeded(RandomField::new(info.index().seed + 1).get(wpos2d.into())); canvas.map(Vec3::new(wpos2d.x, wpos2d.y, cave_base), |block| { block.with_sprite(kind) }); diff --git a/world/src/layer/tree.rs b/world/src/layer/tree.rs index a3b960da03..ee1e9ba8f3 100644 --- a/world/src/layer/tree.rs +++ b/world/src/layer/tree.rs @@ -7,7 +7,7 @@ use crate::{ }; use common::{ assets::AssetHandle, - terrain::{Structure, StructuresGroup, Block, BlockKind}, + terrain::{Block, BlockKind, Structure, StructuresGroup}, vol::ReadVol, }; use hashbrown::HashMap; @@ -24,7 +24,8 @@ lazy_static! { static ref BAOBABS: AssetHandle = Structure::load_group("baobabs"); static ref FRUIT_TREES: AssetHandle = Structure::load_group("fruit_trees"); static ref BIRCHES: AssetHandle = Structure::load_group("birch"); - static ref MANGROVE_TREES: AssetHandle = Structure::load_group("mangrove_trees"); + static ref MANGROVE_TREES: AssetHandle = + Structure::load_group("mangrove_trees"); static ref QUIRKY: AssetHandle = Structure::load_group("quirky"); static ref QUIRKY_DRY: AssetHandle = Structure::load_group("quirky_dry"); static ref SWAMP_TREES: AssetHandle = Structure::load_group("swamp_trees"); diff --git a/world/src/lib.rs b/world/src/lib.rs index ebf75b7864..d93e5255f6 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -72,8 +72,9 @@ pub struct Colors { } impl assets::Asset for Colors { - const EXTENSION: &'static str = "ron"; type Loader = assets::RonLoader; + + const EXTENSION: &'static str = "ron"; } impl World { diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index abe73568cd..b1e847b972 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -246,8 +246,9 @@ pub enum WorldFile { } impl assets::Asset for WorldFile { - const EXTENSION: &'static str = "bin"; type Loader = assets::BincodeLoader; + + const EXTENSION: &'static str = "bin"; } /// Data for the most recent map type. Update this when you add a new map @@ -413,22 +414,24 @@ impl WorldSim { map.into_modern() }, - FileOpts::LoadAsset(ref specifier) => { - match WorldFile::load_owned(&specifier) { - Ok(map) => map.into_modern(), - Err(err) => { - match err { - assets::Error::Io(e) => { - warn!(?e, ?specifier, "Couldn't read asset specifier for maps"); - } - assets::Error::Conversion(e) => { - warn!(?e, "Couldn't parse modern map. Maybe you meant to try a legacy load?"); - } - assets::Error::NoDefaultValue => unreachable!(), - } - return None; + FileOpts::LoadAsset(ref specifier) => match WorldFile::load_owned(&specifier) { + Ok(map) => map.into_modern(), + Err(err) => { + match err { + assets::Error::Io(e) => { + warn!(?e, ?specifier, "Couldn't read asset specifier for maps"); + }, + assets::Error::Conversion(e) => { + warn!( + ?e, + "Couldn't parse modern map. Maybe you meant to try a legacy \ + load?" + ); + }, + assets::Error::NoDefaultValue => unreachable!(), } - } + return None; + }, }, FileOpts::Generate | FileOpts::Save => return None, };