Skip to content

Commit

Permalink
wip debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 17, 2024
1 parent 8e9afa5 commit b38df96
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -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<KeyboardInput>,
mut local: Local<String>,
mut next: ResMut<NextState<GameState>>,
mut level: ResMut<NextLevel>,
config: Res<GameConfig>,
) {
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),
);
}
}
2 changes: 2 additions & 0 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod command;
mod config;
mod constant;
mod controller;
mod debug;
mod enemy;
mod entity;
mod equipment;
Expand Down

0 comments on commit b38df96

Please sign in to comment.