82 lines
2.1 KiB
Rust
82 lines
2.1 KiB
Rust
//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::<PlaceSoulSpot>()
|
|
.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<Mesh>,
|
|
material: Handle<StandardMaterial>,
|
|
}
|
|
|
|
const SIZE: Vec3 = Vec3::new(1.5, 0.5, 1.5);
|
|
|
|
fn init(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
) {
|
|
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<PlaceSoulSpot>,
|
|
mut commands: Commands,
|
|
res: Res<SoulSpotResources>,
|
|
) {
|
|
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"),
|
|
));
|
|
}
|
|
}
|