From bbbe71487943458561be2235aaef87d3dde663d4 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 19 Dec 2023 14:25:23 +0100 Subject: [PATCH] fix back/replay --- src/buildings.rs | 24 +++++++++++++++--------- src/grid/mod.rs | 15 +++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/buildings.rs b/src/buildings.rs index de56d35..bcc8c51 100644 --- a/src/buildings.rs +++ b/src/buildings.rs @@ -76,7 +76,10 @@ impl BuildingInventory { inventory.items.pop_front(); let new_building = get_random_building(&mut rng); - let new_item = params.command.spawn(new_building).id(); + let new_item = params + .command + .spawn((new_building, MarkerGameStatePlaying)) + .id(); inventory.items.push_back(new_item); @@ -158,14 +161,17 @@ const PADDING: f32 = 10f32; pub(crate) fn spawn_layout(mut commands: Commands, window_size: ResMut) { let mut rng = crate::random::RandomDeterministic::new_from_seed(0); - let inventory = vec![ - commands.spawn(get_random_building(&mut rng)).id(), - commands.spawn(get_random_building(&mut rng)).id(), - commands.spawn(get_random_building(&mut rng)).id(), - commands.spawn(get_random_building(&mut rng)).id(), - commands.spawn(get_random_building(&mut rng)).id(), - commands.spawn(get_random_building(&mut rng)).id(), - ]; + let inventory = { + let mut inventory = vec![]; + for _ in 0..6 { + inventory.push( + commands + .spawn((get_random_building(&mut rng), MarkerGameStatePlaying)) + .id(), + ); + } + inventory + }; let anchor_point = Vec3::new( -window_size.size.x / 2f32 + ITEM_VISUAL_SIZE / 2f32 + PADDING, -window_size.size.y / 2f32 + (ITEM_VISUAL_SIZE + PADDING) * 5.5f32 + PADDING, diff --git a/src/grid/mod.rs b/src/grid/mod.rs index 9698c53..6443b2d 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -126,7 +126,6 @@ fn update_distances( grid: Res, mut hexes: Query<(&mut HexCell, &Handle)>, mut materials: ResMut>, - mut colored: Local, ) { let center = Hex::ZERO; let mut queue = vec![center]; @@ -155,21 +154,17 @@ fn update_distances( processed.insert(neighbor); next_queue.push(neighbor); } - // TODO: debug purposes only, find a better way to color the field - if !*colored { - let v = dist as f32 / MAP_RADIUS as f32; - let material = materials.get_mut(hex_material).unwrap(); - material.color.x = v; - material.color.y = v; - material.color.z = v; - } + let v = dist as f32 / (MAP_RADIUS * 2) as f32; + let material = materials.get_mut(hex_material).unwrap(); + material.color.x = v; + material.color.y = v; + material.color.z = v; } } } queue = next_queue; dist += 1; } - *colored = true; } fn update_unconstructible_hexes(