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.
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use super::*;
|
|
|
|
/// A good starting place for creating a game building on top of the base Bevy app
|
|
pub struct BaseGamePlugin {
|
|
pub name: String,
|
|
}
|
|
|
|
impl Default for BaseGamePlugin {
|
|
fn default() -> Self {
|
|
BaseGamePlugin {
|
|
name: "mygame".into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Plugin for BaseGamePlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_plugins(DefaultPlugins.set(WindowPlugin {
|
|
primary_window: Some(Window {
|
|
fit_canvas_to_parent: true,
|
|
canvas: Some(format!("#{}-canvas", self.name)),
|
|
..default()
|
|
}),
|
|
..default()
|
|
}))
|
|
.add_plugins(DebuggingPlugin)
|
|
.add_plugins(MeshPickingPlugin)
|
|
.add_plugins(PhysicsPlugins::default())
|
|
.add_plugins(LoadingPlugin)
|
|
.add_plugins(BaseUiPlugin)
|
|
.add_systems(Startup, setup_camera);
|
|
}
|
|
}
|
|
|
|
/// 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>>,
|
|
) {
|
|
q.iter_mut().for_each(|(e, mut v, s)| {
|
|
if curr.get() == s {
|
|
*v = Visibility::Inherited;
|
|
} else {
|
|
*v = Visibility::Hidden;
|
|
}
|
|
debug!("Changing visibility of {:?} to {:?}", e, *v);
|
|
});
|
|
}
|
|
|
|
// TODO: Rename to "create camera"
|
|
pub fn setup_camera(mut commands: Commands) {
|
|
commands.spawn((Camera3d { ..default() }, Camera { ..default() }, AmbientLight::default()));
|
|
}
|