Skip to content

Commit

Permalink
chore: update 'reload' example to use RespawnTiledMap
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-bon committed Sep 8, 2024
1 parent c1c3d7c commit b88e929
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions examples/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
Update,
(
handle_load.run_if(in_state(MapState::Unloaded)),
(handle_unload, handle_reload).run_if(in_state(MapState::Loaded)),
(handle_unload, handle_reload, handle_respawn).run_if(in_state(MapState::Loaded)),
),
)
.add_systems(Update, log_transitions)
Expand All @@ -32,7 +32,7 @@ fn startup(
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(TextBundle::from(
"U = Unload map by removing asset\nI = Unload map by despawning entity\nL = Load finite map\nK = Replace loaded map component without unloading",
"U = Unload map by removing asset\nI = Unload map by despawning entity\nL = Load finite map\nK = Replace loaded map component without unloading\nR = Reload map using the RespawnTiledMap component",
));

let map_handle: Handle<TiledMap> = asset_server.load("finite.tmx");
Expand Down Expand Up @@ -119,6 +119,17 @@ fn handle_unload(
}
}

fn handle_respawn(
mut commands: Commands,
keyboard_input: Res<ButtonInput<KeyCode>>,
maps_query: Query<(Entity, &Handle<TiledMap>)>,
) {
if keyboard_input.just_pressed(KeyCode::KeyR) {
let (entity, _) = maps_query.single();
commands.entity(entity).insert(RespawnTiledMap);
}
}

fn log_transitions(mut transitions: EventReader<StateTransitionEvent<MapState>>) {
for transition in transitions.read() {
info!(
Expand Down

0 comments on commit b88e929

Please sign in to comment.