2025-08-24 20:13:22 -04:00
|
|
|
//bevy system signatures often violate these rules
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
#![allow(clippy::too_many_arguments)]
|
|
|
|
|
|
|
|
|
|
use avian3d::prelude::*;
|
|
|
|
|
use bevy::prelude::*;
|
2025-08-30 23:13:23 -04:00
|
|
|
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
2025-08-24 20:13:22 -04:00
|
|
|
use combat::{Defense, Health};
|
|
|
|
|
|
|
|
|
|
pub struct BuildingCorePlugin;
|
|
|
|
|
|
|
|
|
|
impl Plugin for BuildingCorePlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
2025-08-30 23:13:23 -04:00
|
|
|
app.add_systems(Startup, register).add_observer(populate);
|
2025-08-24 20:13:22 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
2025-08-25 08:31:33 -04:00
|
|
|
pub struct Core;
|
2025-08-24 20:13:22 -04:00
|
|
|
|
2025-08-30 23:13:23 -04:00
|
|
|
#[derive(Resource)]
|
|
|
|
|
struct CoreResources {
|
|
|
|
|
mesh: Handle<Mesh>,
|
|
|
|
|
material: Handle<StandardMaterial>,
|
|
|
|
|
info_entity: Entity,
|
2025-08-24 20:13:22 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-30 23:13:23 -04:00
|
|
|
const SIZE: UVec3 = UVec3::new(2, 2, 2);
|
|
|
|
|
|
|
|
|
|
fn register(
|
2025-08-24 20:13:22 -04:00
|
|
|
mut commands: Commands,
|
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
) {
|
2025-08-30 23:13:23 -04:00
|
|
|
let mesh = meshes.add(Cuboid::from_length(2.0));
|
|
|
|
|
let base_material = StandardMaterial {
|
|
|
|
|
base_color: Color::srgb_u8(166, 69, 16),
|
|
|
|
|
metallic: 0.0,
|
|
|
|
|
perceptual_roughness: 0.8,
|
|
|
|
|
..default()
|
|
|
|
|
};
|
|
|
|
|
let material = materials.add(base_material.clone());
|
|
|
|
|
let preview_material = materials.add(StandardMaterial {
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA),
|
|
|
|
|
..base_material
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let info = commands.spawn_empty().id();
|
|
|
|
|
let preview = commands
|
|
|
|
|
.spawn((
|
|
|
|
|
BuildingPreview { info },
|
|
|
|
|
Visibility::Hidden,
|
|
|
|
|
Mesh3d(mesh.clone()),
|
|
|
|
|
MeshMaterial3d(preview_material),
|
|
|
|
|
))
|
|
|
|
|
.id();
|
|
|
|
|
commands.entity(info).insert((
|
|
|
|
|
BuildingInfo {
|
|
|
|
|
preview,
|
|
|
|
|
size: SIZE,
|
|
|
|
|
},
|
|
|
|
|
Name::new("Core"),
|
|
|
|
|
));
|
|
|
|
|
commands.insert_resource(CoreResources {
|
|
|
|
|
mesh: mesh,
|
|
|
|
|
material: material,
|
|
|
|
|
info_entity: info,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn populate(
|
|
|
|
|
trigger: Trigger<PopulatePlacedBuilding>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
res: Res<CoreResources>,
|
|
|
|
|
) {
|
|
|
|
|
if trigger.event().info != res.info_entity {
|
|
|
|
|
return;
|
2025-08-24 20:13:22 -04:00
|
|
|
}
|
2025-08-30 23:13:23 -04:00
|
|
|
commands.entity(trigger.target()).insert((
|
|
|
|
|
RigidBody::Static,
|
|
|
|
|
Core,
|
|
|
|
|
Health::new(100.0),
|
|
|
|
|
Defense::new(5.0),
|
|
|
|
|
Name::from("Core"),
|
|
|
|
|
Mesh3d(res.mesh.clone()),
|
|
|
|
|
MeshMaterial3d(res.material.clone()),
|
|
|
|
|
));
|
2025-08-24 20:13:22 -04:00
|
|
|
}
|