diff --git a/.gitattributes b/.gitattributes index b247eed..584647e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,3 +16,4 @@ assets/ filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text *.dll filter=lfs diff=lfs merge=lfs -text *.lib filter=lfs diff=lfs merge=lfs -text +*.gltf filter=lfs diff=lfs merge=lfs -text diff --git a/assets/models/Martian Chess.glb b/assets/models/Martian Chess.glb index be09176..db3b9bc 100644 --- a/assets/models/Martian Chess.glb +++ b/assets/models/Martian Chess.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:de24421e2f949d5fc5de5fb40e9daf78dd00f7a4cf95b0b8392ed5cc7522d161 -size 3559972 +oid sha256:a9a3447fe51d9af0cf74e71ddb0ebeb72d0a48f202cba7580190545124faaef3 +size 18557524 diff --git a/src/display2d.rs b/src/display2d.rs index 14e095c..cb94278 100644 --- a/src/display2d.rs +++ b/src/display2d.rs @@ -197,6 +197,10 @@ fn initialize_board(sprite_sheet: Option>, mut commands: Comman } } +/// TODO: YOU DUMB IDIOT +/// JUST RE-DRAW ANY ENTITY WITH A CHANGED BoardIndex!! +/// INITIALIZE THE STARTING BOARD, THEN JUST UPDATE CHANGED BOARDINDEX!!! +/// GOD YOU ARE SO DUMB. fn draw_board( board: Option>, sprite_sheet: Option>, diff --git a/src/display3d.rs b/src/display3d.rs index 00c5b20..3f88fd1 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{game::BoardIndex, prelude::*}; pub(crate) struct Display3dPlugin; @@ -11,7 +11,16 @@ impl Plugin for Display3dPlugin { Update, menu::exit_to_menu.run_if(in_state(GameState::Display3d)), ) - .add_systems(Update, gizmo_system.run_if(in_state(GameState::Display3d))) + .add_systems( + Update, + gizmo_system + .run_if(in_state(GameState::Display3d)) + .run_if(resource_exists::()), + ) + .add_systems( + Update, + set_piece_position.run_if(in_state(GameState::Display3d)), + ) .add_systems(OnEnter(GameState::Display3d), activate) .add_systems(OnExit(GameState::Display3d), deactivate); } @@ -20,6 +29,9 @@ impl Plugin for Display3dPlugin { #[derive(Debug, Component)] struct Board3d; +#[derive(Debug, Component)] +struct Piece3d; + fn initialize_camera(mut commands: Commands) { commands.spawn(( Camera3dBundle { @@ -28,7 +40,11 @@ fn initialize_camera(mut commands: Commands) { hdr: true, ..default() }, - transform: Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y), + projection: Projection::Orthographic(OrthographicProjection { + scale: 0.02, + ..default() + }), + transform: Transform::from_xyz(0.0, 20.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, UiCameraConfig { show_ui: true }, @@ -64,6 +80,7 @@ fn initialize_board( mut commands: Commands, model_file: Option>, gltfs: Res>, + board: Option>, ) { info!("Initializing board"); if let Some(mf) = model_file { @@ -94,32 +111,57 @@ fn initialize_board( )); info!("Intializeing 3D Board!"); - parent.spawn(( - Board3d, - SceneBundle { - scene: gltf - .named_scenes - .get("Gameboard") - .expect("Game board model") - .clone(), - ..default() - }, - )); + parent + .spawn(( + Board3d, + SceneBundle { + scene: gltf + .named_scenes + .get("Gameboard") + .expect("Game board model") + .clone(), + ..default() + }, + )) + .with_children(|parent| { + board + .unwrap() + .pieces() + .into_iter() + .for_each(|(index, piece)| { + let scene = match piece { + game::Piece::Pawn => gltf.named_scenes.get("Pawn"), + game::Piece::Drone => gltf.named_scenes.get("Drone"), + game::Piece::Queen => gltf.named_scenes.get("Queen"), + } + .expect("Game board model") + .clone(); + + parent.spawn((Piece3d, index, SceneBundle { scene, ..default() })); + }); + }); }); } } +/// Sets a piece location given it's board index +fn set_piece_position( + mut events: Query<(&mut Transform, &BoardIndex), (With, Changed)>, +) { + events.iter_mut().for_each(|(mut t, i)| { + t.translation = board_translation(i); + }); +} + /// Make this the active state fn activate( mut cameras: Query<&mut Camera, With>, mut boards: Query<&mut Visibility, With>, ) { cameras.iter_mut().for_each(|mut camera| { - info!("Activating 3d camera"); camera.is_active = true; }); boards.iter_mut().for_each(|mut visibility| { - info!("Making entities visible"); *visibility = Visibility::Visible; }); } @@ -130,18 +172,39 @@ fn deactivate( mut boards: Query<&mut Visibility, With>, ) { cameras.iter_mut().for_each(|mut camera| { - info!("Deactivating 3d camera"); camera.is_active = false; }); boards.iter_mut().for_each(|mut visibility| { - info!("Making entities visible"); *visibility = Visibility::Hidden; }); } +/// Given a board index returns the Vec3 location in space +fn board_translation(&BoardIndex { x, y }: &BoardIndex) -> Vec3 { + // Scale x down by 4 to account for -4..4 scaling + let x = x as i8 - 4; + // Mirror y axis because our board index is inverted... + let y = -(y as i8) + 1; + + let x = if x < 0 { + x as f32 * 1.3 + 0.325 + } else { + x as f32 * 1.3 + 1.0 + }; + + let y = y as f32 * 1.3 + 0.65; + + Vec3::new(x, 0.0, y) +} + fn gizmo_system(mut gizmos: Gizmos) { - gizmos.cuboid( - Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.)), - Color::WHITE, - ); + for y in 0..4 { + for x in 0..8 { + gizmos.cuboid( + Transform::from_translation(board_translation(&BoardIndex { x, y })) + .with_scale(Vec3::splat(1.25)), + Color::PURPLE, + ) + } + } } diff --git a/src/menu.rs b/src/menu.rs index 484f05c..af55f20 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -65,6 +65,7 @@ fn init_menu_ui(mut commands: Commands) { ..default() }, background_color: Color::NONE.into(), + visibility: Visibility::Hidden, ..default() }, )) @@ -156,7 +157,7 @@ fn handle_menu_start( events .iter() .filter(|&interaction| *interaction == Interaction::Pressed) - .for_each(|_| next_state.set(GameState::Display3d)) + .for_each(|_| next_state.set(GameState::Display2d)) } fn handle_menu_quit(