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 bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::machines::{CuttingMachine, RotatingMachine},
|
game::machines::{CuttingMachine, RotatingMachine},
|
||||||
resources::UiTheme,
|
resources::UiTheme,
|
||||||
|
widgets::SpawnUi,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod assets;
|
mod assets;
|
||||||
@@ -24,7 +25,7 @@ fn main() {
|
|||||||
.add_plugins(EguiPlugin::default())
|
.add_plugins(EguiPlugin::default())
|
||||||
.add_plugins(WorldInspectorPlugin::new())
|
.add_plugins(WorldInspectorPlugin::new())
|
||||||
.add_plugins(widgets::GameUiPlugin)
|
.add_plugins(widgets::GameUiPlugin)
|
||||||
.add_systems(Startup, (setup, assets::load_assets, dummy_machine))
|
.add_systems(Startup, (setup, assets::load_assets, dummy_machines))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,26 +40,35 @@ fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dummy_machine(
|
/// Dev tool for spawning dummy entities. I'm developing their UIs by hooking
|
||||||
mut commands: Commands,
|
/// up to these while the TileMap gets ready.
|
||||||
// mut meshes: ResMut<Assets<Mesh>>,
|
fn dummy_machines(mut commands: Commands) {
|
||||||
// mut materials: ResMut<Assets<ColorMaterial>>,
|
// Spawn a dummy Cutting Machine
|
||||||
) {
|
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Sprite::from_color(GREEN, Vec2::splat(40.0)),
|
Sprite::from_color(RED, 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))),
|
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
Pickable::default(),
|
Pickable::default(),
|
||||||
))
|
))
|
||||||
.observe(
|
.observe(spawn_machine_ui::<CuttingMachine>);
|
||||||
|event: Trigger<Pointer<Click>>, commands: Commands, theme: Res<UiTheme>| {
|
|
||||||
let entity = event.target;
|
commands
|
||||||
CuttingMachine::spawn_ui(commands, theme);
|
.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