Skip to content

Commit

Permalink
Merge #484
Browse files Browse the repository at this point in the history
484: Re-implement Seaweed and Anemones Decorations r=zicklag a=zicklag

bors r+

Co-authored-by: Zicklag <zicklag@katharostech.com>
  • Loading branch information
bors[bot] and zicklag committed Nov 23, 2022
2 parents 091da95 + 5a7bd77 commit 8e3f837
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 19 deletions.
9 changes: 5 additions & 4 deletions assets/map/elements/decoration/anemones/anemones.element.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Anemones
category: Decorations
scripts:
- ./anemones.ts
editor_size: [48, 51]
preload_assets:
- ./anemones.atlas.yaml
builtin: !AnimatedDecoration
start_frame: 0
end_frame: 4
fps: 6
atlas: ./anemones.atlas.yaml
9 changes: 5 additions & 4 deletions assets/map/elements/decoration/seaweed/seaweed.element.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Seaweed
category: Decorations
scripts:
- ./seaweed.ts
editor_size: [48, 51]
preload_assets:
- ./seaweed.atlas.yaml
builtin: !AnimatedDecoration
start_frame: 0
end_frame: 4
fps: 6
atlas: ./seaweed.atlas.yaml
21 changes: 11 additions & 10 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use normalize_path::NormalizePath;

use crate::{
metadata::{
BorderImageMeta, GameMeta, MapElementMeta, MapLayerKind, MapMeta, PlayerMeta,
TextureAtlasMeta,
BorderImageMeta, BuiltinElementKind, GameMeta, MapElementMeta, MapLayerKind, MapMeta,
PlayerMeta, TextureAtlasMeta,
},
prelude::*,
};
Expand Down Expand Up @@ -353,17 +353,18 @@ impl AssetLoader for MapElementMetaLoader {

// Load assets for built-in types
match &mut meta.builtin {
crate::metadata::BuiltinElementKind::None => (),
crate::metadata::BuiltinElementKind::PlayerSpawner => (),
crate::metadata::BuiltinElementKind::Sproinger {
BuiltinElementKind::None => (),
BuiltinElementKind::PlayerSpawner => (),
BuiltinElementKind::Sproinger {
atlas,
atlas_handle,
} => {
let (path, handle) = get_relative_asset(load_context, self_path, atlas);
*atlas_handle = AssetHandle::new(path.clone(), handle.typed());
dependencies.push(path);
}
crate::metadata::BuiltinElementKind::Sword {
| BuiltinElementKind::AnimatedDecoration {
atlas,
atlas_handle,
..
}
| BuiltinElementKind::Sword {
atlas,
atlas_handle,
} => {
Expand Down
4 changes: 3 additions & 1 deletion src/map/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
prelude::*,
};

pub mod decoration;
pub mod player_spawner;
pub mod sproinger;
pub mod sword;
Expand All @@ -15,7 +16,8 @@ pub struct MapElementsPlugin;

impl Plugin for MapElementsPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(player_spawner::PlayerSpawnerPlugin)
app.add_plugin(decoration::DecorationPlugin)
.add_plugin(player_spawner::PlayerSpawnerPlugin)
.add_plugin(sproinger::SproingerPlugin)
.add_plugin(sword::SwordPlugin);
}
Expand Down
46 changes: 46 additions & 0 deletions src/map/elements/decoration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use super::*;

pub struct DecorationPlugin;

impl Plugin for DecorationPlugin {
fn build(&self, app: &mut App) {
app.extend_rollback_schedule(|schedule| {
schedule.add_system_to_stage(RollbackStage::PreUpdate, hydrate_decorations);
});
}
}

fn hydrate_decorations(
mut commands: Commands,
non_hydrated_map_elements: Query<(Entity, &MapElementMeta), Without<MapElementHydrated>>,
) {
// Hydrate any newly-spawned decorations
for (entity, map_element) in &non_hydrated_map_elements {
if let BuiltinElementKind::AnimatedDecoration {
atlas_handle,
start_frame,
end_frame,
fps,
..
} = &map_element.builtin
{
commands
.entity(entity)
.insert(MapElementHydrated)
.insert(AnimatedSprite {
start: *start_frame,
end: *end_frame,
atlas: atlas_handle.inner.clone(),
repeat: true,
fps: *fps,
..default()
})
.insert(KinematicBody {
size: Vec2::new(32.0, 8.0),
offset: Vec2::new(0.0, -6.0),
has_mass: false,
..default()
});
}
}
}
9 changes: 9 additions & 0 deletions src/metadata/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ pub enum BuiltinElementKind {
None,
/// Player spawner
PlayerSpawner,
/// An animated decoration such as seaweed or anemones
AnimatedDecoration {
start_frame: usize,
end_frame: usize,
fps: f32,
atlas: String,
#[serde(skip)]
atlas_handle: AssetHandle<TextureAtlas>,
},
/// This is a sproinger
Sproinger {
atlas: String,
Expand Down

0 comments on commit 8e3f837

Please sign in to comment.