Fix debug items

This commit is contained in:
Benoît du Garreau 2020-12-18 18:11:48 +01:00
parent ace47766f9
commit 1ace001fde
2 changed files with 20 additions and 9 deletions

View File

@ -234,6 +234,7 @@ impl Directory {
impl Compound for Directory {
fn load<S: source::Source>(_: &AssetCache<S>, specifier: &str) -> Result<Self, Error> {
let specifier = specifier.strip_suffix(".*").unwrap_or(specifier);
let root = ASSETS.source().path_of(specifier, "");
let mut files = Vec::new();

View File

@ -206,6 +206,24 @@ impl assets::Asset for RawItemDef {
#[derive(Debug)]
pub struct OperationFailure;
#[derive(Clone)]
struct ItemList(Vec<Item>);
impl assets::Compound for ItemList {
fn load<S: assets::source::Source>(
cache: &assets::AssetCache<S>,
specifier: &str,
) -> Result<Self, Error> {
let list = cache
.load::<assets::Directory>(specifier)?
.read()
.iter()
.map(|spec| Item::new_from_asset(spec))
.collect::<Result<_, Error>>()?;
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<Vec<Self>, 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