diff --git a/editor/src/debug/mod.rs b/editor/src/debug/mod.rs new file mode 100644 index 0000000000..6c7d25bb33 --- /dev/null +++ b/editor/src/debug/mod.rs @@ -0,0 +1,52 @@ +use crate::game::{GameState, Mode}; +use ezgui::{EventCtx, EventLoopMode, GfxCtx, Wizard}; +use std::collections::HashMap; + +pub struct DebugMode { + state: State, +} + +enum State { + Exploring, +} + +impl DebugMode { + pub fn new() -> DebugMode { + DebugMode { + state: State::Exploring, + } + } + + pub fn event(state: &mut GameState, ctx: &mut EventCtx) -> EventLoopMode { + match state.mode { + Mode::Debug(ref mut mode) => { + ctx.canvas.handle_event(ctx.input); + state.ui.state.primary.current_selection = + state + .ui + .handle_mouseover(ctx, None, &state.ui.state.primary.sim); + + ctx.input.set_mode("Debug Mode", ctx.canvas); + if ctx.input.modal_action("quit") { + state.mode = Mode::SplashScreen(Wizard::new(), None); + } + + EventLoopMode::InputOnly + } + _ => unreachable!(), + } + } + + pub fn draw(state: &GameState, g: &mut GfxCtx) { + match state.mode { + Mode::Debug(ref mode) => match mode.state { + State::Exploring => { + state + .ui + .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim); + } + }, + _ => unreachable!(), + } + } +} diff --git a/editor/src/game.rs b/editor/src/game.rs index aa095c58bf..3c753556ff 100644 --- a/editor/src/game.rs +++ b/editor/src/game.rs @@ -1,3 +1,4 @@ +use crate::debug::DebugMode; use crate::edit::EditMode; use crate::sandbox::SandboxMode; use crate::state::{Flags, UIState}; @@ -28,6 +29,7 @@ pub enum Mode { Edit(EditMode), Tutorial(TutorialMode), Sandbox(SandboxMode), + Debug(DebugMode), } impl GameState { @@ -35,7 +37,7 @@ impl GameState { let splash = !flags.no_splash; let mut rng = flags.sim_flags.make_rng(); let mut game = GameState { - mode: Mode::Legacy, + mode: Mode::Sandbox(SandboxMode::new()), ui: UI::new(UIState::new(flags, prerender, true), canvas), }; if splash { @@ -87,6 +89,7 @@ impl GUI for GameState { Mode::Edit(_) => EditMode::event(self, ctx), Mode::Tutorial(_) => TutorialMode::event(self, ctx), Mode::Sandbox(_) => SandboxMode::event(self, ctx), + Mode::Debug(_) => DebugMode::event(self, ctx), } } @@ -100,6 +103,7 @@ impl GUI for GameState { Mode::Edit(_) => EditMode::draw(self, g), Mode::Tutorial(_) => TutorialMode::draw(self, g), Mode::Sandbox(_) => SandboxMode::draw(self, g), + Mode::Debug(_) => DebugMode::draw(self, g), } } @@ -172,6 +176,7 @@ fn splash_screen( let load_map = "Load another map"; let edit = "Edit map"; let tutorial = "Tutorial"; + let debug = "Debug mode"; let legacy = "Legacy mode (ignore this)"; let about = "About"; let quit = "Quit"; @@ -181,7 +186,9 @@ fn splash_screen( match wizard .choose_string( "Welcome to A/B Street!", - vec![sandbox, load_map, edit, tutorial, legacy, about, quit], + vec![ + sandbox, load_map, edit, tutorial, debug, legacy, about, quit, + ], )? .as_str() { @@ -214,6 +221,7 @@ fn splash_screen( ctx.canvas.center_to_map_pt(), ))) } + x if x == debug => break Some(Mode::Debug(DebugMode::new())), x if x == legacy => break Some(Mode::Legacy), x if x == about => { if wizard.acknowledge(LogScroller::new( diff --git a/editor/src/main.rs b/editor/src/main.rs index cc1236d032..6fa5c648a0 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -1,4 +1,5 @@ mod colors; +mod debug; mod edit; mod game; mod objects; diff --git a/editor/src/ui.rs b/editor/src/ui.rs index b8a749fd92..0995149cdf 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -174,6 +174,7 @@ impl GUI for UI { (Key::Dot, "forwards"), ], ), + ModalMenu::new("Debug Mode", vec![(Key::Escape, "quit")]), ] }