Skip to content

Commit

Permalink
Track Parallax Background Load Status
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Jul 28, 2022
1 parent 4cb98e5 commit 30b4a33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
27 changes: 17 additions & 10 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,6 @@ impl AssetLoader for LevelMetaLoader {

let self_path = load_context.path();

// Convert all parallax paths to relative asset paths so that the convention matches the
// rest of the paths used by the asset loaders.
for layer in &mut meta.parallax_background.layers {
layer.path = relative_asset_path(self_path, &layer.path)
.to_str()
.unwrap()
.to_owned();
}

let mut dependencies = Vec::new();

// Load the players
Expand Down Expand Up @@ -207,8 +198,24 @@ impl AssetLoader for LevelMetaLoader {
item.item_handle = item_handle;
}

// Load the music
// Load parallax background layers
for layer in &mut meta.parallax_background.layers {
let (path, handle) = get_relative_asset(load_context, self_path, &layer.path);

// Update the layer path to use an absolute path so that it matches the conventione
// used by the bevy_parallax_background plugin.
layer.path = path
.path()
.as_os_str()
.to_str()
.expect("utf8-filename")
.to_string();

layer.image_handle = handle;
dependencies.push(path);
}

// Load the music
let (music_path, music_handle) =
get_relative_asset(load_context, self_path, &meta.music);
meta.music_handle = music_handle;
Expand Down
2 changes: 1 addition & 1 deletion src/loading/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! impl_default_load_progress {
)*
};
}
impl_default_load_progress!(String, f32, u32, Vec2, Vec3, UVec2, egui::TextureId);
impl_default_load_progress!(String, f32, usize, u32, Vec2, Vec3, UVec2, egui::TextureId);

// Implement `HasLoadProgress` for container types
impl<T: HasLoadProgress> HasLoadProgress for Option<T> {
Expand Down
6 changes: 3 additions & 3 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ pub struct ItemSpawnMeta {

#[derive(HasLoadProgress, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[has_load_progress(none)]
pub struct ParallaxMeta {
pub layers: Vec<ParallaxLayerMeta>,
}
Expand All @@ -159,12 +158,13 @@ impl ParallaxMeta {
}
}

// TODO: This struct is a workaround for the fact that `bevy_parallax::LayerData` isn't Clone.
#[derive(Deserialize, Clone, Debug)]
#[derive(HasLoadProgress, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct ParallaxLayerMeta {
pub speed: f32,
pub path: String,
#[serde(skip)]
pub image_handle: Handle<Image>,
pub tile_size: Vec2,
pub cols: usize,
pub rows: usize,
Expand Down

0 comments on commit 30b4a33

Please sign in to comment.