upgrade system

This commit is contained in:
Jim 2025-08-31 23:59:50 -04:00
parent 921947c131
commit 83256bfbe5
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
15 changed files with 331 additions and 43 deletions

View file

@ -12,6 +12,7 @@ use combat::{Health, Team};
use input::Selectable;
use resources::{Cost, Resources};
use state::GameSystemSet;
use upgrade::{Upgradable, UpgradeTree};
pub struct BuildingPlugin;
@ -56,7 +57,7 @@ fn on_building_removed(mut world: DeferredWorld, context: HookContext) {
}
#[derive(Component, Clone)]
#[require(Name, Cost)]
#[require(Name, Cost, UpgradeTree)]
#[component(on_add = register_building_info)]
#[component(on_remove = unregister_building_info)]
#[component(immutable)]
@ -198,7 +199,7 @@ fn place_building(
mut building_map: ResMut<PlacedBuildings>,
mut commands: Commands,
mut resources: ResMut<Resources>,
info_query: Query<(&BuildingInfo, &Cost, &Name)>,
info_query: Query<(&BuildingInfo, &Cost, &Name), With<UpgradeTree>>,
) {
for PlaceBuilding {
info: info_entity,
@ -206,7 +207,7 @@ fn place_building(
} in reader.read()
{
let Ok((info, cost, name)) = info_query.get(*info_entity) else {
error!("tried to place building without info!");
error!("tried to place building without info or required components!");
continue;
};
if !building_map.placement_valid(*location, info) {
@ -232,6 +233,7 @@ fn place_building(
name.clone(),
RigidBody::Static,
Team::Core.collision_layers(),
Upgradable::new(*info_entity),
))
.id();
building_map.place_building(*location, info, *info_entity, instance);