in-game cheat/debug menu
This commit is contained in:
parent
7460ddee05
commit
0ef3a51e56
5 changed files with 82 additions and 8 deletions
45
src/gui/cheat_menu.rs
Normal file
45
src/gui/cheat_menu.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
use super::State;
|
||||||
|
use rltk::prelude::*;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
|
pub enum CheatMenuResult {
|
||||||
|
NoResponse,
|
||||||
|
Cancel,
|
||||||
|
Ascend,
|
||||||
|
Descend,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_cheat_menu(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult {
|
||||||
|
let (x_offset, y_offset) = (1, 10);
|
||||||
|
ctx.print_color(
|
||||||
|
1 + x_offset,
|
||||||
|
1 + y_offset,
|
||||||
|
RGB::named(rltk::RED),
|
||||||
|
RGB::named(rltk::BLACK),
|
||||||
|
"DEBUG MENU! [aA-zZ][Esc.]",
|
||||||
|
);
|
||||||
|
let x = 1 + x_offset;
|
||||||
|
let mut y = 3 + y_offset;
|
||||||
|
let count = 2;
|
||||||
|
let width = 18;
|
||||||
|
|
||||||
|
ctx.draw_box(x, y, width, (count + 1) as i32, RGB::named(rltk::RED), RGB::named(rltk::BLACK));
|
||||||
|
y += 1;
|
||||||
|
// Asc
|
||||||
|
ctx.set(x_offset + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), rltk::to_cp437('a'));
|
||||||
|
ctx.print(x_offset + 4, y, "ASCEND A FLOOR");
|
||||||
|
y += 1;
|
||||||
|
// Desc
|
||||||
|
ctx.set(x_offset + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), rltk::to_cp437('d'));
|
||||||
|
ctx.print(x_offset + 4, y, "DESCEND A FLOOR");
|
||||||
|
// Match keys
|
||||||
|
match ctx.key {
|
||||||
|
None => CheatMenuResult::NoResponse,
|
||||||
|
Some(key) => match key {
|
||||||
|
VirtualKeyCode::A => CheatMenuResult::Ascend,
|
||||||
|
VirtualKeyCode::D => CheatMenuResult::Descend,
|
||||||
|
VirtualKeyCode::Escape => CheatMenuResult::Cancel,
|
||||||
|
_ => CheatMenuResult::NoResponse,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,8 +6,10 @@ use super::{
|
||||||
use rltk::{Rltk, VirtualKeyCode, RGB};
|
use rltk::{Rltk, VirtualKeyCode, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
mod cheat_menu;
|
||||||
mod letter_to_option;
|
mod letter_to_option;
|
||||||
mod tooltip;
|
mod tooltip;
|
||||||
|
pub use cheat_menu::*;
|
||||||
|
|
||||||
pub fn draw_lerping_bar(
|
pub fn draw_lerping_bar(
|
||||||
ctx: &mut Rltk,
|
ctx: &mut Rltk,
|
||||||
|
|
|
||||||
39
src/main.rs
39
src/main.rs
|
|
@ -50,9 +50,10 @@ pub const LOG_TICKS: bool = false;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub enum RunState {
|
pub enum RunState {
|
||||||
AwaitingInput,
|
AwaitingInput, // Player's turn
|
||||||
PreRun,
|
PreRun,
|
||||||
Ticking,
|
Ticking, // Tick systems
|
||||||
|
ShowCheatMenu, // Teleport, godmode, etc. - for debugging
|
||||||
ShowInventory,
|
ShowInventory,
|
||||||
ShowDropItem,
|
ShowDropItem,
|
||||||
ShowRemoveItem,
|
ShowRemoveItem,
|
||||||
|
|
@ -64,7 +65,7 @@ pub enum RunState {
|
||||||
NextLevel,
|
NextLevel,
|
||||||
PreviousLevel,
|
PreviousLevel,
|
||||||
HelpScreen,
|
HelpScreen,
|
||||||
MagicMapReveal { row: i32, cursed: bool },
|
MagicMapReveal { row: i32, cursed: bool }, // Animates magic mapping effect
|
||||||
MapGeneration,
|
MapGeneration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,16 +137,23 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_level(&mut self, offset: i32) {
|
fn goto_level(&mut self, offset: i32) {
|
||||||
// Freeze the current level
|
|
||||||
map::dungeon::freeze_entities(&mut self.ecs);
|
|
||||||
|
|
||||||
// Build new map + place player
|
// Build new map + place player
|
||||||
let current_id;
|
let current_id;
|
||||||
{
|
{
|
||||||
let worldmap_resource = self.ecs.fetch::<Map>();
|
let worldmap_resource = self.ecs.fetch::<Map>();
|
||||||
current_id = worldmap_resource.id;
|
current_id = worldmap_resource.id;
|
||||||
}
|
}
|
||||||
gamelog::record_event("descended", 1);
|
// Record the correct type of event
|
||||||
|
if offset > 0 {
|
||||||
|
gamelog::record_event("descended", 1);
|
||||||
|
} else if current_id == 1 {
|
||||||
|
gamelog::Logger::new().append("CHEAT MENU: YOU CAN'T DO THAT.").colour((255, 0, 0)).log();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
gamelog::record_event("ascended", 1);
|
||||||
|
}
|
||||||
|
// Freeze the current level
|
||||||
|
map::dungeon::freeze_entities(&mut self.ecs);
|
||||||
self.generate_world_map(current_id + offset, offset);
|
self.generate_world_map(current_id + offset, offset);
|
||||||
let mapname = self.ecs.fetch::<Map>().name.clone();
|
let mapname = self.ecs.fetch::<Map>().name.clone();
|
||||||
gamelog::Logger::new().append("You head to").npc_name_n(mapname).period().log();
|
gamelog::Logger::new().append("You head to").npc_name_n(mapname).period().log();
|
||||||
|
|
@ -235,6 +243,23 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RunState::ShowCheatMenu => {
|
||||||
|
let result = gui::show_cheat_menu(self, ctx);
|
||||||
|
match result {
|
||||||
|
gui::CheatMenuResult::Cancel => new_runstate = RunState::AwaitingInput,
|
||||||
|
gui::CheatMenuResult::NoResponse => {}
|
||||||
|
gui::CheatMenuResult::Ascend => {
|
||||||
|
self.goto_level(-1);
|
||||||
|
self.mapgen_next_state = Some(RunState::PreRun);
|
||||||
|
new_runstate = RunState::MapGeneration;
|
||||||
|
}
|
||||||
|
gui::CheatMenuResult::Descend => {
|
||||||
|
self.goto_level(1);
|
||||||
|
self.mapgen_next_state = Some(RunState::PreRun);
|
||||||
|
new_runstate = RunState::MapGeneration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
RunState::ShowInventory => {
|
RunState::ShowInventory => {
|
||||||
let result = gui::show_inventory(self, ctx);
|
let result = gui::show_inventory(self, ctx);
|
||||||
match result.0 {
|
match result.0 {
|
||||||
|
|
|
||||||
|
|
@ -361,6 +361,6 @@ pub fn level_builder(
|
||||||
match new_id {
|
match new_id {
|
||||||
1 => town_builder(new_id, rng, width, height, 0, initial_player_level),
|
1 => town_builder(new_id, rng, width, height, 0, initial_player_level),
|
||||||
2 => forest_builder(new_id, rng, width, height, 1, initial_player_level),
|
2 => forest_builder(new_id, rng, width, height, 1, initial_player_level),
|
||||||
_ => random_builder(new_id, rng, 64, 64, difficulty, initial_player_level),
|
_ => random_builder(new_id, rng, width, height, difficulty, initial_player_level),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,8 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState {
|
||||||
VirtualKeyCode::I => return RunState::ShowInventory,
|
VirtualKeyCode::I => return RunState::ShowInventory,
|
||||||
VirtualKeyCode::D => return RunState::ShowDropItem,
|
VirtualKeyCode::D => return RunState::ShowDropItem,
|
||||||
VirtualKeyCode::R => return RunState::ShowRemoveItem,
|
VirtualKeyCode::R => return RunState::ShowRemoveItem,
|
||||||
|
// Other
|
||||||
|
VirtualKeyCode::Minus => return RunState::ShowCheatMenu,
|
||||||
VirtualKeyCode::Escape => return RunState::SaveGame,
|
VirtualKeyCode::Escape => return RunState::SaveGame,
|
||||||
_ => {
|
_ => {
|
||||||
return RunState::AwaitingInput;
|
return RunState::AwaitingInput;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue