You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
Rust
72 lines
1.7 KiB
Rust
use crate::prelude::*;
|
|
|
|
pub(crate) struct Display3dPlugin;
|
|
|
|
impl Plugin for Display3dPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(
|
|
Startup,
|
|
(initialize_camera, load_models).run_if(in_state(GameState::Loading)),
|
|
)
|
|
.add_systems(
|
|
Update,
|
|
(
|
|
initialize_board.run_if(resource_added::<ModelMap>()),
|
|
menu::exit_to_menu.run_if(in_state(GameState::Display3d)),
|
|
),
|
|
)
|
|
.add_systems(OnEnter(GameState::Display3d), activate);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Component)]
|
|
struct Board3d;
|
|
|
|
#[derive(Debug, Resource)]
|
|
struct ModelMap;
|
|
|
|
fn initialize_camera(mut commands: Commands) {
|
|
commands.spawn((
|
|
Camera3dBundle {
|
|
camera: Camera {
|
|
is_active: false,
|
|
..default()
|
|
},
|
|
..default()
|
|
},
|
|
UiCameraConfig { show_ui: true },
|
|
));
|
|
}
|
|
|
|
fn load_models(server: Res<AssetServer>, mut commands: Commands) {
|
|
warn!("TODO: Load models");
|
|
|
|
commands.insert_resource(ModelMap);
|
|
}
|
|
|
|
fn initialize_board(mut commands: Commands, model_map: Option<Res<ModelMap>>) {
|
|
if let Some(models) = model_map {
|
|
warn!("TODO: Intialize 3D Board!");
|
|
|
|
commands.spawn((
|
|
SpatialBundle {
|
|
visibility: Visibility::Hidden,
|
|
..default()
|
|
},
|
|
Board3d,
|
|
));
|
|
}
|
|
}
|
|
|
|
fn activate(
|
|
mut cameras: Query<&mut Camera, With<Camera3d>>,
|
|
mut boards: Query<&mut Visibility, With<Board3d>>,
|
|
) {
|
|
cameras.iter_mut().for_each(|mut camera| {
|
|
camera.is_active = true;
|
|
});
|
|
boards.iter_mut().for_each(|mut visibility| {
|
|
*visibility = Visibility::Visible;
|
|
});
|
|
}
|