Convert ScreenshotTest away from app.switch_map

This commit is contained in:
Dustin Carlino 2020-10-09 15:07:35 -07:00
parent 2ad832d01a
commit 03eac377d6

View File

@ -13,6 +13,7 @@ use crate::app::{App, ShowLayers, ShowObject};
use crate::common::{tool_panel, CommonState, ContextualActions}; use crate::common::{tool_panel, CommonState, ContextualActions};
use crate::game::{ChooseSomething, DrawBaselayer, PopupMsg, PromptInput, State, Transition}; use crate::game::{ChooseSomething, DrawBaselayer, PopupMsg, PromptInput, State, Transition};
use crate::helpers::ID; use crate::helpers::ID;
use crate::load::MapLoader;
use crate::options::OptionsPanel; use crate::options::OptionsPanel;
use crate::render::{calculate_corners, DrawOptions}; use crate::render::{calculate_corners, DrawOptions};
use crate::sandbox::GameplayMode; use crate::sandbox::GameplayMode;
@ -220,8 +221,9 @@ impl State for DebugMode {
return Transition::Keep; return Transition::Keep;
} }
"screenshot all of the everything" => { "screenshot all of the everything" => {
return Transition::Push(Box::new(ScreenshotTest { return Transition::Push(ScreenshotTest::new(
todo_maps: vec![ ctx,
vec![
"downtown", "downtown",
"krakow_center", "krakow_center",
"lakeslice", "lakeslice",
@ -229,7 +231,7 @@ impl State for DebugMode {
"southbank", "southbank",
"udistrict", "udistrict",
], ],
})); ));
} }
"find bad traffic signals" => { "find bad traffic signals" => {
find_bad_signals(app); find_bad_signals(app);
@ -729,17 +731,37 @@ fn find_large_intersections(app: &App) {
// separate state is the easiest way to automatically screenshot multiple maps. // separate state is the easiest way to automatically screenshot multiple maps.
struct ScreenshotTest { struct ScreenshotTest {
todo_maps: Vec<&'static str>, todo_maps: Vec<&'static str>,
screenshot_done: bool,
}
impl ScreenshotTest {
fn new(ctx: &mut EventCtx, mut todo_maps: Vec<&'static str>) -> Box<dyn State> {
MapLoader::new(
ctx,
todo_maps.pop().unwrap().to_string(),
Box::new(move |_, _| {
Transition::Replace(Box::new(ScreenshotTest {
todo_maps: todo_maps.clone(),
screenshot_done: false,
}))
}),
)
}
} }
impl State for ScreenshotTest { impl State for ScreenshotTest {
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
if let Some(name) = self.todo_maps.pop() { if self.screenshot_done {
app.switch_map(ctx, abstutil::path_map(name)); if self.todo_maps.is_empty() {
Transition::Pop
} else {
Transition::Replace(ScreenshotTest::new(ctx, self.todo_maps.drain(..).collect()))
}
} else {
self.screenshot_done = true;
screenshot_everything(ctx, app); screenshot_everything(ctx, app);
// TODO Sometimes this still gets stuck and needs a mouse wiggle for input event? // TODO Sometimes this still gets stuck and needs a mouse wiggle for input event?
Transition::Keep Transition::Keep
} else {
Transition::Pop
} }
} }
fn draw(&self, _: &mut GfxCtx, _: &App) {} fn draw(&self, _: &mut GfxCtx, _: &App) {}