add loading scenes to tx

This commit is contained in:
Schrottkatze 2025-06-22 19:36:37 +02:00
parent f2fc8f41da
commit 4ed1c7d881
Signed by: schrottkatze
SSH key fingerprint: SHA256:FPOYVeBy3QP20FEM42uWF1Wa/Qhlk+L3S2+Wuau/Auo
5 changed files with 38 additions and 3 deletions

View file

@ -4,13 +4,15 @@ use std::{fs, path::PathBuf};
use bevy::prelude::*;
use bevy_inspector_egui::bevy_egui::EguiPlugin;
use clap::Subcommand;
use console::{ConsoleLog, exec_script};
use console::exec_script;
use crate::AppState;
mod console;
mod debug_event;
pub use console::ConsoleLog;
pub use debug_event::DebugEvent;
/// Debug system set.

View file

@ -53,4 +53,8 @@ pub enum DebugEvent {
/// - Nothing
#[command(name = "enable-debug", aliases = ["debug-enable"])]
EnableDebugMode,
/// Load a gltf scene.
#[command(name = "load-scene", aliases = ["load-file", "load"])]
LoadGltf { asset_path: String },
}

View file

@ -7,8 +7,8 @@ use crate::{
};
mod camera;
mod debug;
mod scene;
mod debug {}
/// Gameplay system set. All functions in this control the gameplay (duh).
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
@ -25,6 +25,6 @@ pub fn plugin(app: &mut App) {
OnExit(AppState::Ingame),
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)));
}

26
src/game/debug.rs Normal file
View 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));
}
}
}

View file

@ -1,2 +1,5 @@
log "hello from startup script!!"
enable-debug
start-game
load-scene gltf/test.glb