mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-04 11:07:40 +00:00
Compare commits
3 commits
d43b5b64e1
...
f2fc8f41da
Author | SHA1 | Date | |
---|---|---|---|
f2fc8f41da | |||
fcc4ebeba8 | |||
da4c6172d4 |
4 changed files with 100 additions and 43 deletions
66
src/debug.rs
66
src/debug.rs
|
@ -9,6 +9,9 @@ use console::{ConsoleLog, exec_script};
|
|||
use crate::AppState;
|
||||
|
||||
mod console;
|
||||
mod debug_event;
|
||||
|
||||
pub use debug_event::DebugEvent;
|
||||
|
||||
/// Debug system set.
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -19,49 +22,21 @@ pub fn plugin(app: &mut App) {
|
|||
enable_multipass_for_primary_context: true,
|
||||
})
|
||||
.add_event::<DebugEvent>()
|
||||
.init_state::<DebugMode>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(handle_debug_logs, start_game, run_file.pipe(exec_script)).in_set(DebugSet),
|
||||
(
|
||||
handle_debug_logs,
|
||||
handle_enable_debug_mode.run_if(not(in_state(DebugMode::Enabled))),
|
||||
start_game,
|
||||
run_file.pipe(exec_script),
|
||||
)
|
||||
.in_set(DebugSet),
|
||||
)
|
||||
.add_systems(Startup, startup_file.pipe(exec_script))
|
||||
.add_plugins(console::plugin);
|
||||
}
|
||||
|
||||
#[derive(Event, Debug, Subcommand, PartialEq, Eq)]
|
||||
enum DebugEvent {
|
||||
/// Close the debug console.
|
||||
#[command(name = "close", aliases = ["close-console"])]
|
||||
CloseDebugConsole,
|
||||
|
||||
/// Output a string to the console.
|
||||
///
|
||||
/// Needed for logging in startup scripts, since the console isn't initialized yet.
|
||||
#[command(name = "echo", aliases = ["print", "print-to-console"])]
|
||||
PrintToConsole {
|
||||
/// Print as error.
|
||||
#[arg(short, long)]
|
||||
error: bool,
|
||||
/// The text to be printed in the console.
|
||||
text: String,
|
||||
},
|
||||
|
||||
/// Log as INFO or ERROR to stdout.
|
||||
Log {
|
||||
/// Log as error.
|
||||
#[arg(short, long)]
|
||||
error: bool,
|
||||
/// The text to be logged.
|
||||
text: String,
|
||||
},
|
||||
|
||||
/// Start the game
|
||||
StartGame,
|
||||
|
||||
/// Run a tx file (the games debug scripting lang :3)
|
||||
#[command(name = "run")]
|
||||
RunFile { file: PathBuf },
|
||||
}
|
||||
|
||||
fn start_game(
|
||||
mut dbg_reader: EventReader<DebugEvent>,
|
||||
mut log: ResMut<ConsoleLog>,
|
||||
|
@ -80,6 +55,25 @@ fn start_game(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(States, Default, Debug, Clone, PartialEq, Eq, Hash, Reflect)]
|
||||
pub enum DebugMode {
|
||||
#[default]
|
||||
Disabled,
|
||||
Enabled,
|
||||
}
|
||||
|
||||
fn handle_enable_debug_mode(
|
||||
mut dbg_reader: EventReader<DebugEvent>,
|
||||
mut debug_state: ResMut<NextState<DebugMode>>,
|
||||
) {
|
||||
for ev in dbg_reader.read() {
|
||||
if matches!(ev, DebugEvent::EnableDebugMode) {
|
||||
info!("Enabling debug mode. There be demons (hopefully the cute ones :3)!");
|
||||
debug_state.set(DebugMode::Enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_debug_logs(mut dbg_reader: EventReader<DebugEvent>) {
|
||||
for ev in dbg_reader.read() {
|
||||
if let DebugEvent::Log { error, text } = ev {
|
||||
|
|
|
@ -122,7 +122,7 @@ pub fn exec_script(
|
|||
};
|
||||
|
||||
for (line_nr, line) in file.lines().enumerate() {
|
||||
if !line.trim().is_empty() && !line.trim().starts_with("//") {
|
||||
if !line.trim().is_empty() && !line.trim().starts_with("#") {
|
||||
match respond(line) {
|
||||
Ok(ev) => {
|
||||
dbg_writer.write(ev);
|
||||
|
|
56
src/debug/debug_event.rs
Normal file
56
src/debug/debug_event.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use clap::Subcommand;
|
||||
|
||||
#[derive(Event, Debug, Subcommand, PartialEq, Eq)]
|
||||
pub enum DebugEvent {
|
||||
/// Close the debug console.
|
||||
#[command(name = "close", aliases = ["close-console"])]
|
||||
CloseDebugConsole,
|
||||
|
||||
/// Output a string to the console.
|
||||
///
|
||||
/// Needed for logging in startup scripts, since the console isn't initialized yet.
|
||||
#[command(name = "echo", aliases = ["print", "print-to-console"])]
|
||||
PrintToConsole {
|
||||
/// Print as error.
|
||||
#[arg(short, long)]
|
||||
error: bool,
|
||||
/// The text to be printed in the console.
|
||||
text: String,
|
||||
},
|
||||
|
||||
/// Log as INFO or ERROR to stdout.
|
||||
Log {
|
||||
/// Log as error.
|
||||
#[arg(short, long)]
|
||||
error: bool,
|
||||
/// The text to be logged.
|
||||
text: String,
|
||||
},
|
||||
|
||||
/// Start the game
|
||||
StartGame,
|
||||
|
||||
/// Run a tx file (the games debug scripting lang :3)
|
||||
#[command(name = "run")]
|
||||
RunFile { file: PathBuf },
|
||||
|
||||
/// Enable debug mode.
|
||||
/// Will cause the game to behave differently (mostly, not do things by default it otherwise would.)
|
||||
///
|
||||
/// Do note while all of this is part of the debug tooling, debug mode just gives the debug tools more controls of the game.
|
||||
///
|
||||
/// Read: In debug mode, a lot of features of the normal game aren't enabled, and might have to be turned on explicitly.
|
||||
/// This is to allow for easier testing. The console etc. will still stay available regardless, just might complain that debug mode isn't enabled on some commands.
|
||||
///
|
||||
/// For best results, enable debug mode before starting the game.
|
||||
///
|
||||
/// Debug mode cannot be disabled. Just restart the game lmao.
|
||||
///
|
||||
/// Current debug mode behaviour:
|
||||
/// - Nothing
|
||||
#[command(name = "enable-debug", aliases = ["debug-enable"])]
|
||||
EnableDebugMode,
|
||||
}
|
19
src/game.rs
19
src/game.rs
|
@ -3,21 +3,28 @@ use bevy::prelude::*;
|
|||
use crate::{
|
||||
AppState,
|
||||
cleanup::{self, despawn},
|
||||
debug::DebugMode,
|
||||
};
|
||||
|
||||
mod camera;
|
||||
mod scene;
|
||||
mod debug {}
|
||||
|
||||
/// Gameplay system set. All functions in this control the gameplay (duh).
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
struct GameplaySet;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(AppState::Ingame), scene::setup.in_set(GameplaySet))
|
||||
.add_systems(
|
||||
OnExit(AppState::Ingame),
|
||||
despawn::<cleanup::Scene>.in_set(GameplaySet),
|
||||
)
|
||||
.add_plugins(camera::plugin);
|
||||
app.add_systems(
|
||||
OnEnter(AppState::Ingame),
|
||||
scene::setup
|
||||
.in_set(GameplaySet)
|
||||
.run_if(in_state(DebugMode::Disabled)),
|
||||
)
|
||||
.add_systems(
|
||||
OnExit(AppState::Ingame),
|
||||
despawn::<cleanup::Scene>.in_set(GameplaySet),
|
||||
)
|
||||
.add_plugins(camera::plugin);
|
||||
app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue