Update to `assets_manager 0.9

This commit is contained in:
Benoît du Garreau 2022-12-04 23:00:10 +01:00
parent 4a5bc05050
commit 4fbb0b9a0b
15 changed files with 52 additions and 31 deletions

8
Cargo.lock generated
View File

@ -259,9 +259,9 @@ dependencies = [
[[package]] [[package]]
name = "assets_manager" name = "assets_manager"
version = "0.8.4" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "881c75fa0f271acf5440031d68d05398cea3e17dc8a418300839eaf0fed57cd2" checksum = "5cf9ce861ea14ebc2339372bafa6b7607adabfddd5679fee761956b3f76243eb"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash 0.8.0", "ahash 0.8.0",
@ -6468,7 +6468,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
"rand 0.8.5", "rand 0.8.5",
"static_assertions", "static_assertions",
] ]
@ -6883,7 +6883,7 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"futures-core", "futures-core",
"futures-util", "futures-util",
"hashbrown 0.9.1", "hashbrown 0.12.3",
"lazy_static", "lazy_static",
"lz-fear", "lz-fear",
"prometheus", "prometheus",

View File

@ -16,7 +16,7 @@ use hashbrown::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{borrow::Cow, io}; 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; use tracing::warn;
// Re-export because I don't like prefix // Re-export because I don't like prefix
use common_assets as assets; use common_assets as assets;
@ -148,7 +148,7 @@ impl Language {
} }
impl assets::Compound for Language { impl assets::Compound for Language {
fn load(cache: assets::AnyCache, path: &str) -> Result<Self, assets::BoxedError> { fn load(cache: assets::AnyCache, path: &SharedString) -> Result<Self, assets::BoxedError> {
let manifest = cache let manifest = cache
.load::<raw::Manifest>(&[path, ".", "_manifest"].concat())? .load::<raw::Manifest>(&[path, ".", "_manifest"].concat())?
.cloned(); .cloned();
@ -180,7 +180,7 @@ impl assets::Compound for Language {
}; };
let resource = FluentResource::try_new(src).map_err(|(_ast, errs)| { 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 bundle
@ -445,12 +445,15 @@ impl LocalizationHandle {
struct FindManifests; struct FindManifests;
impl assets::DirLoadable for FindManifests { impl assets::DirLoadable for FindManifests {
fn select_ids<S: assets::Source + ?Sized>( fn select_ids(
source: &S, cache: assets::AnyCache,
specifier: &str, specifier: &SharedString,
) -> io::Result<Vec<assets::SharedString>> { ) -> io::Result<Vec<SharedString>> {
use assets::Source;
let mut specifiers = Vec::new(); let mut specifiers = Vec::new();
let source = cache.source();
source.read_dir(specifier, &mut |entry| { source.read_dir(specifier, &mut |entry| {
if let DirEntry::Directory(spec) = entry { if let DirEntry::Directory(spec) = entry {
let manifest_spec = [spec, ".", "_manifest"].concat(); let manifest_spec = [spec, ".", "_manifest"].concat();
@ -469,7 +472,7 @@ impl assets::DirLoadable for FindManifests {
struct LocalizationList(Vec<LanguageMetadata>); struct LocalizationList(Vec<LanguageMetadata>);
impl assets::Compound for LocalizationList { impl assets::Compound for LocalizationList {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, assets::BoxedError> { fn load(cache: assets::AnyCache, specifier: &SharedString) -> Result<Self, assets::BoxedError> {
// List language directories // List language directories
let languages = assets::load_dir::<FindManifests>(specifier, false) let languages = assets::load_dir::<FindManifests>(specifier, false)
.unwrap_or_else(|e| panic!("Failed to get manifests from {}: {:?}", specifier, e)) .unwrap_or_else(|e| panic!("Failed to get manifests from {}: {:?}", specifier, e))

View File

@ -7,7 +7,7 @@ version = "0.10.0"
[dependencies] [dependencies]
lazy_static = "1.4.0" 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 } ron = { version = "0.8", default-features = false }
dot_vox = "4.0" dot_vox = "4.0"
wavefront = "0.2" # TODO: Use vertex-colors branch when we have models that have them wavefront = "0.2" # TODO: Use vertex-colors branch when we have models that have them

View File

@ -206,7 +206,10 @@ pub mod figuredata {
} }
impl assets::Compound for ShipSpec { impl assets::Compound for ShipSpec {
fn load(cache: assets::AnyCache, _: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
_: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
let manifest: AssetHandle<Ron<ShipCentralSpec>> = let manifest: AssetHandle<Ron<ShipCentralSpec>> =
AssetExt::load("common.manifests.ship_manifest")?; AssetExt::load("common.manifests.ship_manifest")?;
let mut colliders = HashMap::new(); let mut colliders = HashMap::new();

View File

@ -658,7 +658,7 @@ impl PartialEq for Item {
} }
impl assets::Compound for ItemDef { impl assets::Compound for ItemDef {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, BoxedError> { fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result<Self, BoxedError> {
if specifier.starts_with("veloren.core.") { if specifier.starts_with("veloren.core.") {
return Err(format!( return Err(format!(
"Attempted to load an asset from a specifier reserved for core veloren functions. \ "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<Vec<Self>, Error> { pub fn new_from_asset_glob(asset_glob: &str) -> Result<Vec<Self>, Error> {
let specifier = asset_glob.strip_suffix(".*").unwrap_or(asset_glob); let specifier = asset_glob.strip_suffix(".*").unwrap_or(asset_glob);
let defs = assets::load_dir::<RawItemDef>(specifier, true)?; let defs = assets::load_dir::<RawItemDef>(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 /// Creates a new instance of an `Item from the provided asset identifier if
@ -1253,7 +1253,7 @@ pub fn all_item_defs_expect() -> Vec<String> {
/// Returns all item asset specifiers /// Returns all item asset specifiers
pub fn try_all_item_defs() -> Result<Vec<String>, Error> { pub fn try_all_item_defs() -> Result<Vec<String>, Error> {
let defs = assets::load_dir::<RawItemDef>("common.items", true)?; let defs = assets::load_dir::<RawItemDef>("common.items", true)?;
Ok(defs.ids().map(|id| id.to_owned()).collect()) Ok(defs.ids().map(|id| id.to_string()).collect())
} }
#[cfg(test)] #[cfg(test)]

View File

@ -434,7 +434,10 @@ impl Asset for AbilityMap<String> {
} }
impl assets::Compound for AbilityMap { impl assets::Compound for AbilityMap {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
specifier: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
let manifest = cache.load::<AbilityMap<String>>(specifier)?.read(); let manifest = cache.load::<AbilityMap<String>>(specifier)?.read();
Ok(AbilityMap( Ok(AbilityMap(

View File

@ -1272,7 +1272,7 @@ mod tests {
let loadout = let loadout =
LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset"); LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset");
loadout loadout
.validate(vec![loadout_id.to_owned()]) .validate(vec![loadout_id.to_string()])
.unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}")); .unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}"));
} }
} }
@ -1287,7 +1287,7 @@ mod tests {
let loadout = let loadout =
LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset"); LoadoutSpec::load_cloned(loadout_id).expect("failed to load loadout asset");
loadout loadout
.validate(vec![loadout_id.to_owned()]) .validate(vec![loadout_id.to_string()])
.unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}")); .unwrap_or_else(|e| panic!("{loadout_id} is broken: {e:?}"));
} }
} }

View File

@ -466,7 +466,10 @@ impl EqualitySet {
} }
impl assets::Compound for EqualitySet { impl assets::Compound for EqualitySet {
fn load(cache: assets::AnyCache, id: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
id: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
enum EqualitySpec { enum EqualitySpec {
LootTable(String), LootTable(String),

View File

@ -145,7 +145,7 @@ impl EntityConfig {
/// Return all entity config specifiers /// Return all entity config specifiers
pub fn try_all_entity_configs() -> Result<Vec<String>, Error> { pub fn try_all_entity_configs() -> Result<Vec<String>, Error> {
let configs = assets::load_dir::<EntityConfig>("common.entity", true)?; let configs = assets::load_dir::<EntityConfig>("common.entity", true)?;
Ok(configs.ids().map(|id| id.to_owned()).collect()) Ok(configs.ids().map(|id| id.to_string()).collect())
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -473,7 +473,10 @@ impl assets::Asset for ItemList {
} }
impl assets::Compound for RecipeBook { impl assets::Compound for RecipeBook {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
specifier: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
#[inline] #[inline]
fn load_item_def(spec: &(String, u32)) -> Result<(Arc<ItemDef>, u32), assets::Error> { fn load_item_def(spec: &(String, u32)) -> Result<(Arc<ItemDef>, u32), assets::Error> {
let def = Arc::<ItemDef>::load_cloned(&spec.0)?; let def = Arc::<ItemDef>::load_cloned(&spec.0)?;
@ -828,7 +831,10 @@ enum RawComponentOutput {
} }
impl assets::Compound for ComponentRecipeBook { impl assets::Compound for ComponentRecipeBook {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
specifier: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
#[inline] #[inline]
fn create_recipe_key(raw_recipe: &RawComponentRecipe) -> ComponentKey { fn create_recipe_key(raw_recipe: &RawComponentRecipe) -> ComponentKey {
match &raw_recipe.output { match &raw_recipe.output {
@ -903,7 +909,10 @@ pub fn default_component_recipe_book() -> AssetHandle<ComponentRecipeBook> {
} }
impl assets::Compound for ReverseComponentRecipeBook { impl assets::Compound for ReverseComponentRecipeBook {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, assets::BoxedError> { fn load(
cache: assets::AnyCache,
specifier: &assets::SharedString,
) -> Result<Self, assets::BoxedError> {
let forward = cache.load::<ComponentRecipeBook>(specifier)?.cloned(); let forward = cache.load::<ComponentRecipeBook>(specifier)?.cloned();
let mut recipes = HashMap::new(); let mut recipes = HashMap::new();
for (_, recipe) in forward.iter() { for (_, recipe) in forward.iter() {

View File

@ -68,7 +68,7 @@ impl std::ops::Deref for StructuresGroup {
} }
impl assets::Compound for StructuresGroup { impl assets::Compound for StructuresGroup {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, BoxedError> { fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result<Self, BoxedError> {
let specs = cache.load::<StructuresGroupSpec>(specifier)?.read(); let specs = cache.load::<StructuresGroupSpec>(specifier)?.read();
Ok(StructuresGroup( Ok(StructuresGroup(
@ -136,7 +136,7 @@ impl ReadVol for Structure {
} }
impl assets::Compound for BaseStructure { impl assets::Compound for BaseStructure {
fn load(cache: assets::AnyCache, specifier: &str) -> Result<Self, BoxedError> { fn load(cache: assets::AnyCache, specifier: &assets::SharedString) -> Result<Self, BoxedError> {
let dot_vox_data = cache.load::<DotVoxAsset>(specifier)?.read(); let dot_vox_data = cache.load::<DotVoxAsset>(specifier)?.read();
let dot_vox_data = &dot_vox_data.0; let dot_vox_data = &dot_vox_data.0;

View File

@ -96,7 +96,7 @@ server = { package = "veloren-server", path = "../server", optional = true, defa
clap = { version = "3.2.20", features = ["derive"] } clap = { version = "3.2.20", features = ["derive"] }
# Utility # Utility
assets_manager = {version = "0.8", features = ["ab_glyph"]} assets_manager = {version = "0.9", features = ["ab_glyph"]}
backtrace = "0.3.40" backtrace = "0.3.40"
bincode = "1.3.1" bincode = "1.3.1"
chrono = { version = "0.4.22", features = ["serde"] } chrono = { version = "0.4.22", features = ["serde"] }

View File

@ -552,7 +552,7 @@ impl assets::Asset for SoundtrackCollection<RawSoundtrackItem> {
} }
impl assets::Compound for SoundtrackCollection<SoundtrackItem> { impl assets::Compound for SoundtrackCollection<SoundtrackItem> {
fn load(_: assets::AnyCache, id: &str) -> Result<Self, assets::BoxedError> { fn load(_: assets::AnyCache, id: &assets::SharedString) -> Result<Self, assets::BoxedError> {
let manifest: AssetHandle<SoundtrackCollection<RawSoundtrackItem>> = AssetExt::load(id)?; let manifest: AssetHandle<SoundtrackCollection<RawSoundtrackItem>> = AssetExt::load(id)?;
let mut soundtrack = SoundtrackCollection::default(); let mut soundtrack = SoundtrackCollection::default();
for item in manifest.read().tracks.iter().cloned() { for item in manifest.read().tracks.iter().cloned() {

View File

@ -24,7 +24,7 @@ pub struct Shaders {
impl assets::Compound for Shaders { impl assets::Compound for Shaders {
// TODO: Taking the specifier argument as a base for shaders specifiers // TODO: Taking the specifier argument as a base for shaders specifiers
// would allow to use several shaders groups easily // would allow to use several shaders groups easily
fn load(_: assets::AnyCache, _: &str) -> Result<Shaders, assets::BoxedError> { fn load(_: assets::AnyCache, _: &assets::SharedString) -> Result<Shaders, assets::BoxedError> {
let shaders = [ let shaders = [
"include.constants", "include.constants",
"include.globals", "include.globals",

View File

@ -125,7 +125,7 @@ macro_rules! make_vox_spec {
} }
impl assets::Compound for $Spec { impl assets::Compound for $Spec {
fn load(_: assets::AnyCache, _: &str) -> Result<Self, assets::BoxedError> { fn load(_: assets::AnyCache, _: &assets::SharedString) -> Result<Self, assets::BoxedError> {
Ok($Spec { Ok($Spec {
$( $field: AssetExt::load($asset_path)?, )* $( $field: AssetExt::load($asset_path)?, )*
}) })