Skip to content

Commit

Permalink
check if overload is enough before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Dec 20, 2023
1 parent e837ff4 commit 73b666c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/buildings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::inventory::{self};
use crate::inventory::{Inventory, SpawnInventory};
use crate::overload::Overload;
use crate::random::RandomDeterministic;
use crate::window::WindowSize;
use crate::GameState;
Expand Down Expand Up @@ -48,6 +49,7 @@ pub(crate) struct GetNextBuildingParams<'w, 's> {
&'static mut crate::inventory::Inventory<Building>,
),
>,
q_overload: Query<'w, 's, &'static mut Overload>,
q_buildings: Query<'w, 's, &'static Building>,
}

Expand All @@ -70,9 +72,17 @@ impl BuildingInventory {
let Ok(_item_to_build) = params.q_buildings.get(first_item) else {
return None;
};

// TODO: check if we can build item_to_build (cooldown, space available, currency, ...)
// TODO: send an event if not possible.
// TODO: pay "price" ?

let mut overload = params.q_overload.single_mut();
if overload.0 < 0.1 {
// TODO: send not enough overload event
return None;
}
overload.0 -= 0.1;

inventory.items.pop_front();

let new_building = get_random_building(&mut rng);
Expand Down
4 changes: 1 addition & 3 deletions src/overload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,5 @@ fn react_to_spawned_tower(
let Ok(mut overload) = q_overload.get_single_mut() else {
return;
};
for _e in event.read() {
overload.0 = (overload.0 - 0.1).clamp(0.0, 1.0);
}
// TODO: particles or smth ?
}
7 changes: 5 additions & 2 deletions src/turret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ pub struct SpawnTurret {
impl EntityCommand for SpawnTurret {
fn apply(self, id: Entity, world: &mut World) {
// TODO: attach building to the turret
let _building =
let Some(_building) =
world.resource_scope(|world, mut building_inventory: Mut<BuildingInventory>| {
building_inventory.next(world)
});
})
else {
return;
};

let texture = world.resource_scope(|_, asset_server: Mut<AssetServer>| {
asset_server.load("textures/DifferentTurrets/Turret01.png")
Expand Down

0 comments on commit 73b666c

Please sign in to comment.