convert core to new format, improve tower placement
This commit is contained in:
parent
2808f6dd2c
commit
bc02db7b26
12 changed files with 250 additions and 107 deletions
|
|
@ -9,6 +9,7 @@ avian3d = { workspace = true }
|
|||
|
||||
building = { path = "../building" }
|
||||
physics = { path = "../physics" }
|
||||
input = { path = "../input" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use bevy::prelude::*;
|
|||
use building::{
|
||||
ActiveBuildingPreview, BuildingInfo, BuildingPreview, PlaceBuilding, PlacedBuildings,
|
||||
};
|
||||
use input::Inputs;
|
||||
use physics::Ground;
|
||||
|
||||
pub struct BuildingPlacementPlugin;
|
||||
|
|
@ -30,47 +31,50 @@ fn init(mut commands: Commands, query: Single<Entity, With<Ground>>, mut setup:
|
|||
|
||||
fn move_preview(
|
||||
trigger: Trigger<Pointer<Move>>,
|
||||
preview: Single<(&mut Transform, &BuildingPreview), With<ActiveBuildingPreview>>,
|
||||
preview: Single<(&mut Transform, &mut ActiveBuildingPreview, &BuildingPreview)>,
|
||||
info_query: Query<&BuildingInfo>,
|
||||
placed_buildings: Res<PlacedBuildings>,
|
||||
) {
|
||||
let Some(dest) = trigger.event().hit.position else {
|
||||
return;
|
||||
};
|
||||
let (mut tf, preview) = preview.into_inner();
|
||||
let (mut tf, mut active, preview) = preview.into_inner();
|
||||
let Ok(info) = info_query.get(preview.info) else {
|
||||
error!("building preview has no associated info!");
|
||||
return;
|
||||
};
|
||||
// center mouse on building
|
||||
let loc = dest.round();
|
||||
if !placed_buildings.placement_valid(loc.as_ivec3(), info) {
|
||||
info!("invalid placement!!!!!");
|
||||
return;
|
||||
}
|
||||
tf.translation = dest.round();
|
||||
active.0 = loc.as_ivec3();
|
||||
tf.translation = loc + Vec3::Y * info.size.y as f32 / 2.;
|
||||
}
|
||||
|
||||
fn place_preview(
|
||||
trigger: Trigger<Pointer<Click>>,
|
||||
preview: Single<&BuildingPreview, With<ActiveBuildingPreview>>,
|
||||
_trigger: Trigger<Pointer<Click>>,
|
||||
inputs: Res<Inputs<Update>>,
|
||||
query: Single<(&BuildingPreview, &ActiveBuildingPreview)>,
|
||||
info_query: Query<&BuildingInfo>,
|
||||
placed_buildings: Res<PlacedBuildings>,
|
||||
mut place_writer: EventWriter<PlaceBuilding>,
|
||||
) {
|
||||
let Some(dest) = trigger.event().hit.position else {
|
||||
if !inputs.pressed(input::actions::InputAction::PlaceTower) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
let (preview, active) = query.into_inner();
|
||||
let Ok(info) = info_query.get(preview.info) else {
|
||||
error!("building preview has no associated info!");
|
||||
return;
|
||||
};
|
||||
let loc = dest.round();
|
||||
if !placed_buildings.placement_valid(loc.as_ivec3(), info) {
|
||||
if !placed_buildings.placement_valid(active.0, info) {
|
||||
info!("invalid placement!!!!!");
|
||||
return;
|
||||
}
|
||||
place_writer.write(PlaceBuilding {
|
||||
info: preview.info,
|
||||
location: loc.as_ivec3(),
|
||||
location: active.0,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue