Editor, plus better alignment for pieces on side of board

The pieces are still not in the right place...
main
Elijah C. Voigt 2 years ago
parent 050dd1d3d1
commit c9b2a22e68

@ -491,21 +491,12 @@ fn board_translation(&BoardIndex { x, y }: &BoardIndex) -> Vec3 {
fn capture_translation(side: &Side, num: usize) -> Vec3 { fn capture_translation(side: &Side, num: usize) -> Vec3 {
info!("Side: {:?} Num: {:?}", side, num); info!("Side: {:?} Num: {:?}", side, num);
match side { let x = 5.0 - ((num % 4) as f32 * 1.3);
Side::B => {
let x = -((num % 4) as f32 * 1.3) - 5.2; // mod(num, 4)
let z = ((num / 4) as f32 * 1.3) - 5.2; // floor(div(num, 4))
let y = -1.3;
info!("Vec3({}, {}, {})", x, y, z);
Vec3::new(x, y, z)
},
Side::A => {
let x = ((num % 4) as f32 * 1.3) + 5.2; // mod(num, 4)
let z = -((num / 4) as f32 * 1.3) + 5.2; // floor(div(num, 4))
let y = -1.3; let y = -1.3;
info!("Vec3({}, {}, {})", x, y, z); let z = 4.0 + ((num / 4) as f32 * 1.3);
Vec3::new(x, y, z) match side {
} Side::B => Vec3::new(-x, y, z),
Side::A => Vec3::new(x, y, -z),
} }
} }

@ -0,0 +1,97 @@
use bevy::input::keyboard::KeyboardInput;
use crate::prelude::*;
pub struct EditorPlugin;
impl Plugin for EditorPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, init_editor)
.insert_resource(
GizmoConfig {
depth_bias: -0.1,
..default()
},
)
.add_systems(Update, (
toggle_editor.run_if(on_event::<KeyboardInput>()),
aabb_gizmo,
))
// Systems that run in the editor mode
.add_systems(Update, (
selected_gizmo.run_if(any_with_component::<game::Selected>()),
selected_position.run_if(any_with_component::<game::Selected>()),
).run_if(resource_exists::<EditorActive>()));
}
}
#[derive(Debug, Resource)]
struct EditorActive;
fn init_editor(
mut commands: Commands,
) {
info!("Starting editor");
}
fn toggle_editor(
mut events: EventReader<KeyboardInput>,
active: Option<Res<EditorActive>>,
mut commands: Commands,
) {
events
.read()
.filter(|KeyboardInput {
state, key_code, ..
}| *state == ButtonState::Pressed && *key_code == Some(KeyCode::F3))
.for_each(|_| match active {
Some(_) => commands.remove_resource::<EditorActive>(),
None => commands.insert_resource(EditorActive),
});
}
fn aabb_gizmo(
added: Query<Entity, Added<game::Selected>>,
mut removed: RemovedComponents<game::Selected>,
selected: Query<Entity, With<game::Selected>>,
active: Option<Res<EditorActive>>,
mut commands: Commands,
) {
added.iter().for_each(|e| {
commands.entity(e).insert(AabbGizmo { color: Some(Color::RED) });
});
removed.read().for_each(|e| {
commands.entity(e).remove::<AabbGizmo>();
});
match active {
Some(_) => selected.iter().for_each(|e| {
commands.entity(e).insert(AabbGizmo { color: Some(Color::RED) });
}),
None => selected.iter().for_each(|e| {
commands.entity(e).remove::<AabbGizmo>();
}),
}
}
/// Draw a gizmo showing cardinal directions for a selected object
fn selected_gizmo(
selected: Query<(Entity, &Transform, &GlobalTransform), With<game::Selected>>,
mut gizmos: Gizmos,
) {
selected.iter().for_each(|(e, t, g)| {
let s = g.translation();
gizmos.ray(s, Vec3::X, Color::RED);
gizmos.ray(s, Vec3::Y, Color::GREEN);
gizmos.ray(s, Vec3::Z, Color::BLUE);
});
}
fn selected_position(
selected: Query<(Entity, &GlobalTransform), With<game::Selected>>,
mut debug_info: ResMut<debug::DebugInfo>,
) {
let val = selected.iter().map(|(e, gt)| {
format!("\n{:?} {:?}", e, gt.translation())
}).collect::<Vec<String>>().join("");
debug_info.set("Position".into(), val);
}

@ -8,6 +8,7 @@ mod credits;
mod debug; mod debug;
mod display2d; mod display2d;
mod display3d; mod display3d;
mod editor;
mod game; mod game;
mod hit; mod hit;
mod loading; mod loading;
@ -61,6 +62,7 @@ fn main() {
app.add_plugins(debug::DebugPlugin); app.add_plugins(debug::DebugPlugin);
app.add_plugins(display2d::Display2dPlugin); app.add_plugins(display2d::Display2dPlugin);
app.add_plugins(display3d::Display3dPlugin); app.add_plugins(display3d::Display3dPlugin);
app.add_plugins(editor::EditorPlugin);
app.add_plugins(game::GamePlugin); app.add_plugins(game::GamePlugin);
app.add_plugins(loading::LoadingPlugin); app.add_plugins(loading::LoadingPlugin);
app.add_plugins(menu::MenuPlugin); app.add_plugins(menu::MenuPlugin);

Loading…
Cancel
Save