diff --git a/src/debug.rs b/src/debug.rs new file mode 100644 index 0000000..7d4febe --- /dev/null +++ b/src/debug.rs @@ -0,0 +1,53 @@ +use bevy::{ + input::{ + keyboard::{Key, KeyboardInput}, + ButtonState, + }, + prelude::*, +}; +use bevy_rapier2d::plugin::PhysicsSet; + +use crate::{config::GameConfig, player_state::PlayerState, states::GameState, world::NextLevel}; + +fn process_debug_command( + mut evr_kbd: EventReader, + mut local: Local, + mut next: ResMut>, + mut level: ResMut, + config: Res, +) { + for ev in evr_kbd.read() { + if ev.state == ButtonState::Released { + continue; + } + match ev.logical_key { + Key::Character(ref c) => { + local.push_str(c); + } + _ => {} + } + } + // info!("debug commands: {}", *local); + + if local.ends_with("next") { + local.clear(); + *level = match level.as_ref() { + NextLevel::None => NextLevel::Level(1, PlayerState::from_config(&config)), + NextLevel::Level(n, p) => NextLevel::Level(n + 1, p.clone()), + NextLevel::MultiPlayArena(_) => NextLevel::Level(0, PlayerState::from_config(&config)), + }; + info!("next level: {:?}", level); + next.set(GameState::Warp); + } +} + +pub struct DebugCommandPlugin; + +impl Plugin for DebugCommandPlugin { + fn build(&self, app: &mut App) { + app.add_systems( + FixedUpdate, + process_debug_command.before(PhysicsSet::SyncBackend), + ); + } +} diff --git a/src/game.rs b/src/game.rs index b9d3d1e..de4b4b8 100644 --- a/src/game.rs +++ b/src/game.rs @@ -7,6 +7,7 @@ use crate::constant::*; use crate::controller::enemy::EnemyPlugin; use crate::controller::player::PlayerPlugin; use crate::controller::remote::RemotePlayerPlugin; +use crate::debug::DebugCommandPlugin; use crate::enemy::eyeball::EyeballControlPlugin; use crate::enemy::slime::SlimeControlPlugin; use crate::entity::actor::ActorPlugin; @@ -165,6 +166,7 @@ pub fn run_game() { .add_plugins(CameraPlugin) .add_plugins(ChestPlugin) .add_plugins(CommandButtonPlugin) + .add_plugins(DebugCommandPlugin) .add_plugins(EyeballControlPlugin) .add_plugins(EntityPlugin) .add_plugins(EntityPickerPlugin) diff --git a/src/main.rs b/src/main.rs index 4bfeda0..e127b0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod command; mod config; mod constant; mod controller; +mod debug; mod enemy; mod entity; mod equipment;