diff --git a/common/src/assets.rs b/common/src/assets.rs index 871f924dc1..40cad4e8e6 100644 --- a/common/src/assets.rs +++ b/common/src/assets.rs @@ -234,6 +234,7 @@ impl Directory { impl Compound for Directory { fn load(_: &AssetCache, specifier: &str) -> Result { + let specifier = specifier.strip_suffix(".*").unwrap_or(specifier); let root = ASSETS.source().path_of(specifier, ""); let mut files = Vec::new(); diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index de3b26c707..ec232344df 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -206,6 +206,24 @@ impl assets::Asset for RawItemDef { #[derive(Debug)] pub struct OperationFailure; +#[derive(Clone)] +struct ItemList(Vec); +impl assets::Compound for ItemList { + fn load( + cache: &assets::AssetCache, + specifier: &str, + ) -> Result { + let list = cache + .load::(specifier)? + .read() + .iter() + .map(|spec| Item::new_from_asset(spec)) + .collect::>()?; + + Ok(ItemList(list)) + } +} + impl Item { // TODO: consider alternatives such as default abilities that can be added to a // loadout when no weapon is present @@ -229,15 +247,7 @@ impl Item { /// Creates a Vec containing one of each item that matches the provided /// asset glob pattern pub fn new_from_asset_glob(asset_glob: &str) -> Result, Error> { - //let items = ItemDef::load_glob(asset_glob)?; - - let specifiers = assets::Directory::load(asset_glob)?; - - specifiers - .read() - .iter() - .map(|spec| Self::new_from_asset(&spec)) - .collect() + Ok(ItemList::load_cloned(asset_glob)?.0) } /// Creates a new instance of an `Item from the provided asset identifier if