//bevy system signatures often violate these rules #![allow(clippy::type_complexity)] #![allow(clippy::too_many_arguments)] use std::time::Duration; use avian3d::prelude::{Collider, PhysicsPickable, RigidBody, Sensor}; use bevy::prelude::*; use input::Selectable; use resources::{Quantity, ResourceDeposit}; use state::GameSystemSet; pub struct ResourceSoulSpotPlugin; impl Plugin for ResourceSoulSpotPlugin { fn build(&self, app: &mut App) { app.add_event::() .add_systems(Startup, init) .add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick)); } } #[derive(Component)] pub struct SoulSpot; #[derive(Event)] pub struct PlaceSoulSpot(pub Vec3); #[derive(Resource)] struct SoulSpotResources { mesh: Handle, material: Handle, } const SIZE: Vec3 = Vec3::new(1.5, 0.5, 1.5); fn init( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { let mesh = meshes.add(Cuboid::from_size(SIZE)); let base_material = StandardMaterial { base_color: Color::srgb_u8(210, 188, 166), metallic: 0.8, perceptual_roughness: 0.2, ..default() }; let material = materials.add(base_material); commands.insert_resource(SoulSpotResources { mesh: mesh, material: material, }); } fn spawn( mut reader: EventReader, mut commands: Commands, res: Res, ) { for PlaceSoulSpot(dest) in reader.read() { commands.spawn(( SoulSpot, Transform::from_translation(*dest), ResourceDeposit { bounty: Quantity { souls: 2, bones: 1 }, level: 1, harvest_time: Duration::from_secs(2), max_workers: 1, }, Mesh3d(res.mesh.clone()), MeshMaterial3d(res.material.clone()), Sensor, RigidBody::Static, Collider::cuboid(SIZE.x, SIZE.y, SIZE.z), PhysicsPickable, Selectable, Name::new("Soul Spot"), )); } }