mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-01 17:27:38 +00:00
add loading scenes to tx
This commit is contained in:
parent
f2fc8f41da
commit
4ed1c7d881
5 changed files with 38 additions and 3 deletions
|
@ -4,13 +4,15 @@ use std::{fs, path::PathBuf};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_inspector_egui::bevy_egui::EguiPlugin;
|
use bevy_inspector_egui::bevy_egui::EguiPlugin;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use console::{ConsoleLog, exec_script};
|
use console::exec_script;
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
mod console;
|
mod console;
|
||||||
mod debug_event;
|
mod debug_event;
|
||||||
|
|
||||||
|
pub use console::ConsoleLog;
|
||||||
|
|
||||||
pub use debug_event::DebugEvent;
|
pub use debug_event::DebugEvent;
|
||||||
|
|
||||||
/// Debug system set.
|
/// Debug system set.
|
||||||
|
|
|
@ -53,4 +53,8 @@ pub enum DebugEvent {
|
||||||
/// - Nothing
|
/// - Nothing
|
||||||
#[command(name = "enable-debug", aliases = ["debug-enable"])]
|
#[command(name = "enable-debug", aliases = ["debug-enable"])]
|
||||||
EnableDebugMode,
|
EnableDebugMode,
|
||||||
|
|
||||||
|
/// Load a gltf scene.
|
||||||
|
#[command(name = "load-scene", aliases = ["load-file", "load"])]
|
||||||
|
LoadGltf { asset_path: String },
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod camera;
|
mod camera;
|
||||||
|
mod debug;
|
||||||
mod scene;
|
mod scene;
|
||||||
mod debug {}
|
|
||||||
|
|
||||||
/// Gameplay system set. All functions in this control the gameplay (duh).
|
/// Gameplay system set. All functions in this control the gameplay (duh).
|
||||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -25,6 +25,6 @@ pub fn plugin(app: &mut App) {
|
||||||
OnExit(AppState::Ingame),
|
OnExit(AppState::Ingame),
|
||||||
despawn::<cleanup::Scene>.in_set(GameplaySet),
|
despawn::<cleanup::Scene>.in_set(GameplaySet),
|
||||||
)
|
)
|
||||||
.add_plugins(camera::plugin);
|
.add_plugins((camera::plugin, debug::plugin));
|
||||||
app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame)));
|
app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame)));
|
||||||
}
|
}
|
||||||
|
|
26
src/game/debug.rs
Normal file
26
src/game/debug.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use bevy::{asset::AssetPath, prelude::*};
|
||||||
|
|
||||||
|
use crate::debug::{ConsoleLog, DebugEvent, DebugMode};
|
||||||
|
|
||||||
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.add_systems(
|
||||||
|
Update,
|
||||||
|
handle_load_gltf.run_if(in_state(DebugMode::Enabled)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_load_gltf(
|
||||||
|
mut c: Commands,
|
||||||
|
mut dbg_reader: EventReader<DebugEvent>,
|
||||||
|
mut logger: ResMut<ConsoleLog>,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
for ev in dbg_reader.read() {
|
||||||
|
if let DebugEvent::LoadGltf { asset_path } = ev {
|
||||||
|
let scene_handle = asset_server
|
||||||
|
.load(GltfAssetLabel::Scene(0).from_asset(AssetPath::from(asset_path.clone())));
|
||||||
|
|
||||||
|
c.spawn(SceneRoot(scene_handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,5 @@
|
||||||
log "hello from startup script!!"
|
log "hello from startup script!!"
|
||||||
|
|
||||||
|
enable-debug
|
||||||
start-game
|
start-game
|
||||||
|
load-scene gltf/test.glb
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue