Skip to content

Commit

Permalink
WIP: Support vectors of standard dynamic assets in dynamic asset file…
Browse files Browse the repository at this point in the history
…s (see #78)
  • Loading branch information
NiklasEi committed Aug 8, 2022
1 parent 508a05a commit e9b5831
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bevy_asset_loader/src/standard_dynamic_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ pub enum StandardDynamicAsset {
},
}

#[derive(Debug, Clone, serde::Deserialize)]
#[serde(untagged)]
pub enum ExtendedStandardDynamicAsset {
Collection(Vec<StandardDynamicAsset>),
Single(StandardDynamicAsset),
}

impl DynamicAsset for StandardDynamicAsset {
fn load(&self, asset_server: &AssetServer) -> Vec<HandleUntyped> {
match self {
Expand Down Expand Up @@ -143,13 +150,29 @@ impl DynamicAsset for StandardDynamicAsset {
}
}

impl DynamicAsset for ExtendedStandardDynamicAsset {
fn load(&self, asset_server: &AssetServer) -> Vec<HandleUntyped> {
match self {
ExtendedStandardDynamicAsset::Single(asset) => asset.load(asset_server),
ExtendedStandardDynamicAsset::Collection(_asset_list) => todo!(),
}
}

fn build(&self, world: &mut World) -> Result<DynamicAssetType, anyhow::Error> {
match self {
ExtendedStandardDynamicAsset::Single(asset) => asset.build(world),
ExtendedStandardDynamicAsset::Collection(_asset_list) => todo!(),
}
}
}

/// The asset defining a mapping from asset keys to dynamic assets
///
/// These assets are loaded at the beginning of a loading state
/// and combined in [`DynamicAssets`](DynamicAssets).
#[derive(serde::Deserialize, TypeUuid)]
#[uuid = "2df82c01-9c71-4aa8-adc4-71c5824768f1"]
pub struct StandardDynamicAssetCollection(pub HashMap<String, StandardDynamicAsset>);
pub struct StandardDynamicAssetCollection(pub HashMap<String, ExtendedStandardDynamicAsset>);

impl DynamicAssetCollection for StandardDynamicAssetCollection {
fn register(&self, dynamic_assets: &mut DynamicAssets) {
Expand Down

0 comments on commit e9b5831

Please sign in to comment.