|
|
|
@ -2,31 +2,35 @@ use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
/// A good starting place for creating a game building on top of the base Bevy app
|
|
|
|
/// A good starting place for creating a game building on top of the base Bevy app
|
|
|
|
pub struct BaseGamePlugin {
|
|
|
|
pub struct BaseGamePlugin {
|
|
|
|
pub camera: CameraType
|
|
|
|
pub camera: CameraType,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Plugin for BaseGamePlugin {
|
|
|
|
impl Plugin for BaseGamePlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_plugins(DefaultPlugins)
|
|
|
|
app.add_plugins(DefaultPlugins).add_plugins(DebuggingPlugin);
|
|
|
|
.add_plugins(DebuggingPlugin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add a camera setup system and startup
|
|
|
|
// Add a camera setup system and startup
|
|
|
|
app.add_systems(Startup, match self.camera {
|
|
|
|
app.add_systems(
|
|
|
|
|
|
|
|
Startup,
|
|
|
|
|
|
|
|
match self.camera {
|
|
|
|
CameraType::Camera2d => setup_camera_2d,
|
|
|
|
CameraType::Camera2d => setup_camera_2d,
|
|
|
|
CameraType::Camera3d => setup_camera_3d,
|
|
|
|
CameraType::Camera3d => setup_camera_3d,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// For selecting the type of camera this game requires
|
|
|
|
/// For selecting the type of camera this game requires
|
|
|
|
pub enum CameraType {
|
|
|
|
pub enum CameraType {
|
|
|
|
Camera2d,
|
|
|
|
Camera2d,
|
|
|
|
Camera3d
|
|
|
|
Camera3d,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// System to toggle the visibility of entities based on their state
|
|
|
|
/// System to toggle the visibility of entities based on their state
|
|
|
|
pub fn toggle_state_visibility<S: States + Component>(mut q: Query<(Entity, &mut Visibility, &S)>, curr: Res<State<S>>) {
|
|
|
|
pub fn toggle_state_visibility<S: States + Component>(
|
|
|
|
|
|
|
|
mut q: Query<(Entity, &mut Visibility, &S)>,
|
|
|
|
|
|
|
|
curr: Res<State<S>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
q.iter_mut().for_each(|(e, mut v, s)| {
|
|
|
|
q.iter_mut().for_each(|(e, mut v, s)| {
|
|
|
|
if curr.get() == s {
|
|
|
|
if curr.get() == s {
|
|
|
|
*v = Visibility::Inherited;
|
|
|
|
*v = Visibility::Inherited;
|
|
|
|
@ -37,14 +41,10 @@ pub fn toggle_state_visibility<S: States + Component>(mut q: Query<(Entity, &mut
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn setup_camera_2d(
|
|
|
|
fn setup_camera_2d(mut commands: Commands) {
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
commands.spawn((Camera { ..default() }, Camera2d));
|
|
|
|
commands.spawn((Camera { ..default() }, Camera2d));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn setup_camera_3d(
|
|
|
|
fn setup_camera_3d(mut commands: Commands) {
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
commands.spawn((Camera { ..default() }, Camera3d { ..default() }));
|
|
|
|
commands.spawn((Camera { ..default() }, Camera3d { ..default() }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|