From 4fbb0b9a0babe01ac71ff4a6d7ccf7be8650f73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sun, 4 Dec 2022 23:00:10 +0100 Subject: [PATCH] Update to `assets_manager 0.9 --- Cargo.lock | 8 ++++---- client/i18n/src/lib.rs | 19 +++++++++++-------- common/assets/Cargo.toml | 2 +- common/src/comp/body/ship.rs | 5 ++++- common/src/comp/inventory/item/mod.rs | 6 +++--- common/src/comp/inventory/item/tool.rs | 5 ++++- common/src/comp/inventory/loadout_builder.rs | 4 ++-- common/src/comp/inventory/trade_pricing.rs | 5 ++++- common/src/generation.rs | 2 +- common/src/recipe.rs | 15 ++++++++++++--- common/src/terrain/structure.rs | 4 ++-- voxygen/Cargo.toml | 2 +- voxygen/src/audio/music.rs | 2 +- voxygen/src/render/renderer/shaders.rs | 2 +- voxygen/src/scene/figure/load.rs | 2 +- 15 files changed, 52 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6cf1a6425..91dc5092bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,9 +259,9 @@ dependencies = [ [[package]] name = "assets_manager" -version = "0.8.4" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881c75fa0f271acf5440031d68d05398cea3e17dc8a418300839eaf0fed57cd2" +checksum = "5cf9ce861ea14ebc2339372bafa6b7607adabfddd5679fee761956b3f76243eb" dependencies = [ "ab_glyph", "ahash 0.8.0", @@ -6468,7 +6468,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "rand 0.8.5", "static_assertions", ] @@ -6883,7 +6883,7 @@ dependencies = [ "crossbeam-channel", "futures-core", "futures-util", - "hashbrown 0.9.1", + "hashbrown 0.12.3", "lazy_static", "lz-fear", "prometheus", diff --git a/client/i18n/src/lib.rs b/client/i18n/src/lib.rs index be1bc8890b..74da0e45bb 100644 --- a/client/i18n/src/lib.rs +++ b/client/i18n/src/lib.rs @@ -16,7 +16,7 @@ use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use std::{borrow::Cow, io}; -use assets::{source::DirEntry, AssetExt, AssetGuard, AssetHandle, ReloadWatcher}; +use assets::{source::DirEntry, AssetExt, AssetGuard, AssetHandle, ReloadWatcher, SharedString}; use tracing::warn; // Re-export because I don't like prefix use common_assets as assets; @@ -148,7 +148,7 @@ impl Language { } impl assets::Compound for Language { - fn load(cache: assets::AnyCache, path: &str) -> Result { + fn load(cache: assets::AnyCache, path: &SharedString) -> Result { let manifest = cache .load::(&[path, ".", "_manifest"].concat())? .cloned(); @@ -180,7 +180,7 @@ impl assets::Compound for Language { }; let resource = FluentResource::try_new(src).map_err(|(_ast, errs)| { - ResourceErr::parsing_error(errs, id.to_owned(), &source.src) + ResourceErr::parsing_error(errs, id.to_string(), &source.src) })?; bundle @@ -445,12 +445,15 @@ impl LocalizationHandle { struct FindManifests; impl assets::DirLoadable for FindManifests { - fn select_ids( - source: &S, - specifier: &str, - ) -> io::Result> { + fn select_ids( + cache: assets::AnyCache, + specifier: &SharedString, + ) -> io::Result> { + use assets::Source; + let mut specifiers = Vec::new(); + let source = cache.source(); source.read_dir(specifier, &mut |entry| { if let DirEntry::Directory(spec) = entry { let manifest_spec = [spec, ".", "_manifest"].concat(); @@ -469,7 +472,7 @@ impl assets::DirLoadable for FindManifests { struct LocalizationList(Vec); impl assets::Compound for LocalizationList { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load(cache: assets::AnyCache, specifier: &SharedString) -> Result { // List language directories let languages = assets::load_dir::(specifier, false) .unwrap_or_else(|e| panic!("Failed to get manifests from {}: {:?}", specifier, e)) diff --git a/common/assets/Cargo.toml b/common/assets/Cargo.toml index e32406915d..5bba91fee8 100644 --- a/common/assets/Cargo.toml +++ b/common/assets/Cargo.toml @@ -7,7 +7,7 @@ version = "0.10.0" [dependencies] lazy_static = "1.4.0" -assets_manager = {version = "0.8.1", features = ["bincode", "ron", "json"]} +assets_manager = {version = "0.9", features = ["bincode", "ron", "json"]} ron = { version = "0.8", default-features = false } dot_vox = "4.0" wavefront = "0.2" # TODO: Use vertex-colors branch when we have models that have them diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index 1c722d6b5a..45d08c68f8 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -206,7 +206,10 @@ pub mod figuredata { } impl assets::Compound for ShipSpec { - fn load(cache: assets::AnyCache, _: &str) -> Result { + fn load( + cache: assets::AnyCache, + _: &assets::SharedString, + ) -> Result { let manifest: AssetHandle> = AssetExt::load("common.manifests.ship_manifest")?; let mut colliders = HashMap::new(); diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index c0879c1abd..74080d2a82 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -658,7 +658,7 @@ impl PartialEq for Item { } impl assets::Compound for ItemDef { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result { if specifier.starts_with("veloren.core.") { return Err(format!( "Attempted to load an asset from a specifier reserved for core veloren functions. \ @@ -796,7 +796,7 @@ impl Item { pub fn new_from_asset_glob(asset_glob: &str) -> Result, Error> { let specifier = asset_glob.strip_suffix(".*").unwrap_or(asset_glob); let defs = assets::load_dir::(specifier, true)?; - defs.ids().map(Item::new_from_asset).collect() + defs.ids().map(|id| Item::new_from_asset(id)).collect() } /// Creates a new instance of an `Item from the provided asset identifier if @@ -1253,7 +1253,7 @@ pub fn all_item_defs_expect() -> Vec { /// Returns all item asset specifiers pub fn try_all_item_defs() -> Result, Error> { let defs = assets::load_dir::("common.items", true)?; - Ok(defs.ids().map(|id| id.to_owned()).collect()) + Ok(defs.ids().map(|id| id.to_string()).collect()) } #[cfg(test)] diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 5a08be555e..78bd405fa1 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -434,7 +434,10 @@ impl Asset for AbilityMap { } impl assets::Compound for AbilityMap { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load( + cache: assets::AnyCache, + specifier: &assets::SharedString, + ) -> Result { let manifest = cache.load::>(specifier)?.read(); Ok(AbilityMap( diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 637b493770..c5523b215e 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -1272,7 +1272,7 @@ mod tests { let loadout = LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset"); loadout - .validate(vec![loadout_id.to_owned()]) + .validate(vec![loadout_id.to_string()]) .unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}")); } } @@ -1287,7 +1287,7 @@ mod tests { let loadout = LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset"); loadout - .validate(vec![loadout_id.to_owned()]) + .validate(vec![loadout_id.to_string()]) .unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}")); } } diff --git a/common/src/comp/inventory/trade_pricing.rs b/common/src/comp/inventory/trade_pricing.rs index 39cb10aee5..58024af6b9 100644 --- a/common/src/comp/inventory/trade_pricing.rs +++ b/common/src/comp/inventory/trade_pricing.rs @@ -466,7 +466,10 @@ impl EqualitySet { } impl assets::Compound for EqualitySet { - fn load(cache: assets::AnyCache, id: &str) -> Result { + fn load( + cache: assets::AnyCache, + id: &assets::SharedString, + ) -> Result { #[derive(Debug, Deserialize)] enum EqualitySpec { LootTable(String), diff --git a/common/src/generation.rs b/common/src/generation.rs index cd6b7be045..764165c793 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -145,7 +145,7 @@ impl EntityConfig { /// Return all entity config specifiers pub fn try_all_entity_configs() -> Result, Error> { let configs = assets::load_dir::("common.entity", true)?; - Ok(configs.ids().map(|id| id.to_owned()).collect()) + Ok(configs.ids().map(|id| id.to_string()).collect()) } #[derive(Clone)] diff --git a/common/src/recipe.rs b/common/src/recipe.rs index 9382fea6d7..9d6fa5a8a6 100644 --- a/common/src/recipe.rs +++ b/common/src/recipe.rs @@ -473,7 +473,10 @@ impl assets::Asset for ItemList { } impl assets::Compound for RecipeBook { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load( + cache: assets::AnyCache, + specifier: &assets::SharedString, + ) -> Result { #[inline] fn load_item_def(spec: &(String, u32)) -> Result<(Arc, u32), assets::Error> { let def = Arc::::load_cloned(&spec.0)?; @@ -828,7 +831,10 @@ enum RawComponentOutput { } impl assets::Compound for ComponentRecipeBook { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load( + cache: assets::AnyCache, + specifier: &assets::SharedString, + ) -> Result { #[inline] fn create_recipe_key(raw_recipe: &RawComponentRecipe) -> ComponentKey { match &raw_recipe.output { @@ -903,7 +909,10 @@ pub fn default_component_recipe_book() -> AssetHandle { } impl assets::Compound for ReverseComponentRecipeBook { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load( + cache: assets::AnyCache, + specifier: &assets::SharedString, + ) -> Result { let forward = cache.load::(specifier)?.cloned(); let mut recipes = HashMap::new(); for (_, recipe) in forward.iter() { diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 78eeea91ed..1c97296c52 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -68,7 +68,7 @@ impl std::ops::Deref for StructuresGroup { } impl assets::Compound for StructuresGroup { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result { let specs = cache.load::(specifier)?.read(); Ok(StructuresGroup( @@ -136,7 +136,7 @@ impl ReadVol for Structure { } impl assets::Compound for BaseStructure { - fn load(cache: assets::AnyCache, specifier: &str) -> Result { + fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result { let dot_vox_data = cache.load::(specifier)?.read(); let dot_vox_data = &dot_vox_data.0; diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index d369d05583..ade7cd5771 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -96,7 +96,7 @@ server = { package = "veloren-server", path = "../server", optional = true, defa clap = { version = "3.2.20", features = ["derive"] } # Utility -assets_manager = {version = "0.8", features = ["ab_glyph"]} +assets_manager = {version = "0.9", features = ["ab_glyph"]} backtrace = "0.3.40" bincode = "1.3.1" chrono = { version = "0.4.22", features = ["serde"] } diff --git a/voxygen/src/audio/music.rs b/voxygen/src/audio/music.rs index d4b7e90d9c..f7e477959e 100644 --- a/voxygen/src/audio/music.rs +++ b/voxygen/src/audio/music.rs @@ -552,7 +552,7 @@ impl assets::Asset for SoundtrackCollection { } impl assets::Compound for SoundtrackCollection { - fn load(_: assets::AnyCache, id: &str) -> Result { + fn load(_: assets::AnyCache, id: &assets::SharedString) -> Result { let manifest: AssetHandle> = AssetExt::load(id)?; let mut soundtrack = SoundtrackCollection::default(); for item in manifest.read().tracks.iter().cloned() { diff --git a/voxygen/src/render/renderer/shaders.rs b/voxygen/src/render/renderer/shaders.rs index 4270219422..c2d4b645a2 100644 --- a/voxygen/src/render/renderer/shaders.rs +++ b/voxygen/src/render/renderer/shaders.rs @@ -24,7 +24,7 @@ pub 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::AnyCache, _: &str) -> Result { + fn load(_: assets::AnyCache, _: &assets::SharedString) -> Result { let shaders = [ "include.constants", "include.globals", diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index d9d7a9c623..9392125476 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -125,7 +125,7 @@ macro_rules! make_vox_spec { } impl assets::Compound for $Spec { - fn load(_: assets::AnyCache, _: &str) -> Result { + fn load(_: assets::AnyCache, _: &assets::SharedString) -> Result { Ok($Spec { $( $field: AssetExt::load($asset_path)?, )* })