|
|
|
|
@ -27,6 +27,7 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
hydrate_camera.run_if(any_component_added::<Camera3d>),
|
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece>),
|
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>),
|
|
|
|
|
set_board_model.run_if(any_component_added::<TilesComponent>),
|
|
|
|
|
set_tile_hitbox.run_if(any_component_added::<game::Tile>),
|
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>),
|
|
|
|
|
set_piece_texture.run_if(any_component_changed::<Side>),
|
|
|
|
|
@ -81,6 +82,9 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub(crate) struct Display3d;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
struct TilesComponent;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource)]
|
|
|
|
|
struct AssetsMap {
|
|
|
|
|
models: Handle<Gltf>,
|
|
|
|
|
@ -130,6 +134,9 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
|
|
|
|
|
parent
|
|
|
|
|
.spawn((Display3d, game::BoardComponent, SceneBundle { ..default() }))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
// TEMP: Tiles
|
|
|
|
|
parent.spawn((Display3d, TilesComponent, SceneBundle { ..default() }));
|
|
|
|
|
|
|
|
|
|
// Hitboxes
|
|
|
|
|
game::tiles().for_each(|(index, tile)| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
@ -256,18 +263,27 @@ fn set_piece_model(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_board_model(
|
|
|
|
|
mut events: Query<&mut Handle<Scene>, (With<game::BoardComponent>, With<Display3d>)>,
|
|
|
|
|
mut boards: Query<&mut Handle<Scene>, (With<game::BoardComponent>, Without<TilesComponent>, With<Display3d>)>,
|
|
|
|
|
mut tiles: Query<&mut Handle<Scene>, (With<TilesComponent>, Without<game::BoardComponent>, With<Display3d>)>,
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter_mut().for_each(|mut handle| {
|
|
|
|
|
boards.iter_mut().for_each(|mut handle| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
*handle = gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get("Gameboard")
|
|
|
|
|
.expect("Game board model")
|
|
|
|
|
.clone();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
tiles.iter_mut().for_each(|mut handle| {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
*handle = gltf
|
|
|
|
|
.named_scenes
|
|
|
|
|
.get("Tiles")
|
|
|
|
|
.expect("Game tiles model")
|
|
|
|
|
.clone();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets a piece location given it's board index
|
|
|
|
|
|