From ea4448f781ecc9b8c8d7830459e0b4a38aa4addd Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 21 Nov 2025 22:58:46 -0800 Subject: [PATCH] Fix a bug where textures did not follow debug state when new entities were spawned (i.e., shapes), leading to textured shapes being added in debug mode. --- src/bin/tetris/main.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/bin/tetris/main.rs b/src/bin/tetris/main.rs index e28251c..b1b8f80 100644 --- a/src/bin/tetris/main.rs +++ b/src/bin/tetris/main.rs @@ -39,10 +39,10 @@ fn main() { ), ) .add_systems( - OnEnter(DebuggingState::On), toggle_visuals + OnEnter(DebuggingState::On), toggle_art ) .add_systems( - OnExit(DebuggingState::On), toggle_visuals + OnExit(DebuggingState::On), toggle_art ) .add_systems( Update, @@ -88,6 +88,7 @@ fn main() { damage_over_time.run_if(on_timer(Duration::from_secs(5))), check_level_goal.run_if(resource_changed::), check_level_fail.run_if(any_component_removed::), + toggle_art.run_if(any_component_added::), ), ) // UI systems @@ -396,37 +397,30 @@ fn init_tetris( }, material_o: materials.add(ColorMaterial { color: YELLOW.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_t: materials.add(ColorMaterial { color: PURPLE.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_l: materials.add(ColorMaterial { color: ORANGE.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_j: materials.add(ColorMaterial { color: BLUE.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_s: materials.add(ColorMaterial { color: LIME.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_z: materials.add(ColorMaterial { color: RED.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), material_i: materials.add(ColorMaterial { color: AQUA.into(), - texture: Some(server.load("tetris/shape_block.png")), ..default() }), }); @@ -438,7 +432,6 @@ fn init_tetris( Mesh2d(mesh.clone()), MeshMaterial2d(materials.add(ColorMaterial { color: BLACK.into(), - texture: Some(server.load("tetris/bg_block.png")), ..default() })), Art { @@ -471,7 +464,6 @@ fn init_battler( { let mat = materials.add(ColorMaterial { color: BLUE.into(), - texture: Some(server.load("tetris/placeholder_protagonist.png")), ..default() }); let mesh = meshes.add(Ellipse::new(SCALE, SCALE * 2.0)); @@ -494,7 +486,6 @@ fn init_battler( { let mat = materials.add(ColorMaterial { color: RED.into(), - texture: Some(server.load("tetris/placeholder_enemy.png")), ..default() }); let art = Art { @@ -1492,8 +1483,9 @@ fn check_level_fail( }); } -fn toggle_visuals( +fn toggle_art( state: Res>, + // TODO: Correctness: Query for added or changed entities query: Query<(&MeshMaterial2d, &Art)>, mut color_materials: ResMut>, ) {