show range indicator when placing tower, cleanup tower info stats
This commit is contained in:
parent
e6b04bbdd1
commit
3a25a1bd87
9 changed files with 106 additions and 49 deletions
|
|
@ -8,7 +8,7 @@ use bevy::{
|
|||
platform::collections::HashMap,
|
||||
prelude::*,
|
||||
};
|
||||
use combat::{Health, Range, Team};
|
||||
use combat::{Defense, Health, Range, Team};
|
||||
use input::Selectable;
|
||||
use resources::{Cost, Resources};
|
||||
use state::GameSystemSet;
|
||||
|
|
@ -61,6 +61,9 @@ pub struct BuildingPreview {
|
|||
pub info: Entity,
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
pub struct ActiveBuildingPreview(pub IVec3);
|
||||
|
||||
pub const PREVIEW_ALPHA: f32 = 0.5;
|
||||
|
||||
fn register_building_info(mut world: DeferredWorld, context: HookContext) {
|
||||
|
|
@ -141,7 +144,17 @@ fn place_building(
|
|||
mut reader: EventReader<PlaceBuilding>,
|
||||
mut commands: Commands,
|
||||
mut resources: ResMut<Resources>,
|
||||
info_query: Query<(&BuildingInfo, &Cost, &Name), With<UpgradeTree>>,
|
||||
info_query: Query<
|
||||
(
|
||||
&BuildingInfo,
|
||||
&Cost,
|
||||
&Name,
|
||||
&Health,
|
||||
&Defense,
|
||||
Option<&Range>,
|
||||
),
|
||||
With<UpgradeTree>,
|
||||
>,
|
||||
building_query: Query<&Building>,
|
||||
core_query: Query<(&GlobalTransform, &Range), With<Core>>,
|
||||
spatial_query: SpatialQuery,
|
||||
|
|
@ -151,7 +164,8 @@ fn place_building(
|
|||
location,
|
||||
} in reader.read()
|
||||
{
|
||||
let Ok((info, cost, name)) = info_query.get(*info_entity) else {
|
||||
let Ok((info, cost, name, health, defense, opt_range)) = info_query.get(*info_entity)
|
||||
else {
|
||||
error!("tried to place building without info or required components!");
|
||||
continue;
|
||||
};
|
||||
|
|
@ -175,27 +189,31 @@ fn place_building(
|
|||
continue;
|
||||
}
|
||||
|
||||
let instance = commands
|
||||
.spawn((
|
||||
// adjust model up slightly so base of all towers are aligned
|
||||
Transform::from_translation(position),
|
||||
Building {
|
||||
level: 0,
|
||||
info: *info_entity,
|
||||
},
|
||||
collider,
|
||||
Mesh3d::default(),
|
||||
name.clone(),
|
||||
RigidBody::Static,
|
||||
Team::Core.collision_layers(),
|
||||
Upgradable::new(*info_entity),
|
||||
BarSettings {
|
||||
offset: size_v3.y / 2. + 0.5,
|
||||
width: (size_v3.x.max(size_v3.z) * 8.).ceil() as u32,
|
||||
..default()
|
||||
},
|
||||
))
|
||||
.id();
|
||||
let mut ec = commands.spawn((
|
||||
// adjust model up slightly so base of all towers are aligned
|
||||
Transform::from_translation(position),
|
||||
Building {
|
||||
level: 0,
|
||||
info: *info_entity,
|
||||
},
|
||||
collider,
|
||||
Mesh3d::default(),
|
||||
name.clone(),
|
||||
RigidBody::Static,
|
||||
Team::Core.collision_layers(),
|
||||
Upgradable::new(*info_entity),
|
||||
*health,
|
||||
*defense,
|
||||
BarSettings {
|
||||
offset: size_v3.y / 2. + 0.5,
|
||||
width: (size_v3.x.max(size_v3.z) * 8.).ceil() as u32,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
if let Some(range) = opt_range {
|
||||
ec.insert(*range);
|
||||
}
|
||||
let instance = ec.id();
|
||||
|
||||
commands.trigger_targets(PopulatePlacedBuilding { info: *info_entity }, instance);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue