Expand the dummy_machines spawner
Spawn a machine entity for each kind of machine. This is where the trait impl becomes important -- now the compiler will make copies of that function for each concrete machine struct so I don't have to.
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -1,9 +1,10 @@
|
||||
use bevy::{color::palettes::css::GREEN, prelude::*, window::WindowResolution};
|
||||
use bevy::{color::palettes::css::*, prelude::*, window::WindowResolution};
|
||||
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
|
||||
|
||||
use crate::{
|
||||
game::machines::{CuttingMachine, RotatingMachine},
|
||||
resources::UiTheme,
|
||||
widgets::SpawnUi,
|
||||
};
|
||||
|
||||
mod assets;
|
||||
@@ -24,7 +25,7 @@ fn main() {
|
||||
.add_plugins(EguiPlugin::default())
|
||||
.add_plugins(WorldInspectorPlugin::new())
|
||||
.add_plugins(widgets::GameUiPlugin)
|
||||
.add_systems(Startup, (setup, assets::load_assets, dummy_machine))
|
||||
.add_systems(Startup, (setup, assets::load_assets, dummy_machines))
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -39,26 +40,35 @@ fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<
|
||||
}
|
||||
}
|
||||
|
||||
fn dummy_machine(
|
||||
mut commands: Commands,
|
||||
// mut meshes: ResMut<Assets<Mesh>>,
|
||||
// mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
/// Dev tool for spawning dummy entities. I'm developing their UIs by hooking
|
||||
/// up to these while the TileMap gets ready.
|
||||
fn dummy_machines(mut commands: Commands) {
|
||||
// Spawn a dummy Cutting Machine
|
||||
commands
|
||||
.spawn((
|
||||
Sprite::from_color(GREEN, Vec2::splat(40.0)),
|
||||
// WARN: Mesh picking is not part of the `DefaultPlugins` plugin collection!
|
||||
// (but sprite picking is!)
|
||||
|
||||
// Mesh2d(meshes.add(Rectangle::new(25., 25.))),
|
||||
// MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))),
|
||||
Sprite::from_color(RED, Vec2::splat(40.0)),
|
||||
Transform::default(),
|
||||
Pickable::default(),
|
||||
))
|
||||
.observe(
|
||||
|event: Trigger<Pointer<Click>>, commands: Commands, theme: Res<UiTheme>| {
|
||||
let entity = event.target;
|
||||
CuttingMachine::spawn_ui(commands, theme);
|
||||
},
|
||||
);
|
||||
.observe(spawn_machine_ui::<CuttingMachine>);
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
Sprite::from_color(GREEN, Vec2::splat(40.0)),
|
||||
Transform::from_translation(Vec3::new(80.0, 0.0, 0.0)),
|
||||
Pickable::default(),
|
||||
))
|
||||
.observe(spawn_machine_ui::<RotatingMachine>);
|
||||
|
||||
// TODO: The other machines, once they have a spawner struct & impl.
|
||||
}
|
||||
|
||||
fn spawn_machine_ui<M: SpawnUi>(
|
||||
event: Trigger<Pointer<Click>>,
|
||||
commands: Commands,
|
||||
theme: Res<UiTheme>,
|
||||
) {
|
||||
let _entity = event.target;
|
||||
// TODO: Hook up the Fuel component (and spawn one so that I can)
|
||||
M::spawn_ui(commands, theme);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user