mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-21 13:21:45 +03:00
starting a debug mode... for me, basically :P
This commit is contained in:
parent
dd88b8724d
commit
a2fb26d5fb
52
editor/src/debug/mod.rs
Normal file
52
editor/src/debug/mod.rs
Normal file
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -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(
|
||||
|
@ -1,4 +1,5 @@
|
||||
mod colors;
|
||||
mod debug;
|
||||
mod edit;
|
||||
mod game;
|
||||
mod objects;
|
||||
|
@ -174,6 +174,7 @@ impl GUI for UI {
|
||||
(Key::Dot, "forwards"),
|
||||
],
|
||||
),
|
||||
ModalMenu::new("Debug Mode", vec![(Key::Escape, "quit")]),
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user