Clean up unused ctx param from SandboxMode::async_new and simple_new

This commit is contained in:
Dustin Carlino 2021-02-10 14:03:06 -08:00
parent a5bfa55c8e
commit a5091a4f18
13 changed files with 26 additions and 45 deletions

View File

@ -271,7 +271,7 @@ impl State<App> for ChallengesPicker {
"Start!" => {
let challenge = self.challenge.take().unwrap();
// Constructing the cutscene doesn't require the map/scenario to be loaded
let sandbox = SandboxMode::simple_new(ctx, app, challenge.gameplay.clone());
let sandbox = SandboxMode::simple_new(app, challenge.gameplay.clone());
if let Some(cutscene) = challenge.cutscene {
Transition::Multi(vec![
Transition::Replace(sandbox),

View File

@ -121,7 +121,6 @@ impl EditMode {
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::async_new(
ctx,
app,
self.mode.clone(),
Box::new(move |ctx, app| {

View File

@ -552,7 +552,6 @@ impl InfoPanel {
(
false,
Some(Transition::Replace(SandboxMode::async_new(
ctx,
app,
ctx_actions.gameplay_mode(),
Box::new(move |_, _| vec![jump_to_time]),

View File

@ -291,15 +291,14 @@ fn finish_app_setup(
vec![Box::new(TitleScreen::new(ctx, app))]
} else if let Some(mode) = maybe_mode {
if let GameplayMode::Blog(_) = mode {
vec![SandboxMode::async_new(ctx, app, mode, start_daytime)]
vec![SandboxMode::async_new(app, mode, start_daytime)]
} else {
vec![SandboxMode::simple_new(ctx, app, mode)]
vec![SandboxMode::simple_new(app, mode)]
}
} else {
// We got here by just passing --dev and a map as flags; we're just looking at an empty
// map. Start in the daytime.
vec![SandboxMode::async_new(
ctx,
app,
GameplayMode::Freeform(app.primary.map.get_name().clone()),
start_daytime,

View File

@ -205,7 +205,6 @@ impl State<App> for MainMenu {
"home_to_work"
};
return Transition::Push(SandboxMode::simple_new(
ctx,
app,
GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),
@ -465,7 +464,6 @@ impl State<App> for Proposals {
app.primary.layer =
Some(Box::new(crate::layer::map::Static::edits(ctx, app)));
Transition::Replace(SandboxMode::simple_new(
ctx,
app,
GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),

View File

@ -187,7 +187,6 @@ impl GameplayState for FixTrafficSignals {
}
"try again" => {
return Some(Transition::Replace(SandboxMode::simple_new(
ctx,
app,
self.mode.clone(),
)));

View File

@ -46,11 +46,10 @@ impl GameplayState for Freeform {
"change map" => Some(Transition::Push(CityPicker::new(
ctx,
app,
Box::new(|ctx, app| {
Box::new(|_, app| {
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::simple_new(
ctx,
app,
GameplayMode::Freeform(app.primary.map.get_name().clone()),
)),
@ -234,7 +233,7 @@ impl ChangeScenario {
}
impl SimpleState<App> for ChangeScenario {
fn on_click(&mut self, ctx: &mut EventCtx, app: &mut App, x: &str, _: &Panel) -> Transition {
fn on_click(&mut self, _: &mut EventCtx, app: &mut App, x: &str, _: &Panel) -> Transition {
if x == "close" {
Transition::Pop
} else if x == "Import your own data" {
@ -246,7 +245,6 @@ impl SimpleState<App> for ChangeScenario {
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::simple_new(
ctx,
app,
if x == "none" {
GameplayMode::Freeform(app.primary.map.get_name().clone())

View File

@ -311,7 +311,7 @@ impl State<App> for FinalScore {
"Try again" => {
return Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::simple_new(ctx, app, self.retry.clone())),
Transition::Replace(SandboxMode::simple_new(app, self.retry.clone())),
]);
}
"Next challenge" => {
@ -353,7 +353,7 @@ impl State<App> for FinalScore {
return Transition::Clear(vec![
MainMenu::new(ctx),
// Constructing the cutscene doesn't require the map/scenario to be loaded.
SandboxMode::simple_new(ctx, app, self.next_mode.clone().unwrap()),
SandboxMode::simple_new(app, self.next_mode.clone().unwrap()),
(Challenge::find(self.next_mode.as_ref().unwrap())
.0
.cutscene

View File

@ -55,7 +55,7 @@ impl GameplayState for PlayScenario {
Some(Transition::Push(CityPicker::new(
ctx,
app,
Box::new(move |ctx, app| {
Box::new(move |_, app| {
// Try to load a scenario with the same name if it exists
let mode = if abstio::file_exists(abstio::path_scenario(
app.primary.map.get_name(),
@ -71,7 +71,7 @@ impl GameplayState for PlayScenario {
};
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::simple_new(ctx, app, mode)),
Transition::Replace(SandboxMode::simple_new(app, mode)),
])
}),
)))
@ -253,7 +253,6 @@ impl State<App> for EditScenarioModifiers {
return Transition::Multi(vec![
Transition::Pop,
Transition::Replace(SandboxMode::simple_new(
ctx,
app,
GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),

View File

@ -57,7 +57,6 @@ impl Tutorial {
Transition::Multi(vec![
// Constructing the intro_story cutscene doesn't require the map/scenario to be loaded.
Transition::Push(SandboxMode::simple_new(
ctx,
app,
GameplayMode::Tutorial(
app.session
@ -124,15 +123,15 @@ impl Tutorial {
}
"previous tutorial" => {
tut.current = TutorialPointer::new(tut.current.stage - 1, 0);
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
"next tutorial" => {
tut.current = TutorialPointer::new(tut.current.stage + 1, 0);
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
"instructions" => {
tut.current = TutorialPointer::new(tut.current.stage, 0);
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
"edit map" => {
// TODO Ideally this would be an inactive button in message states
@ -151,11 +150,11 @@ impl Tutorial {
Outcome::Clicked(x) => match x.as_ref() {
"previous message" => {
tut.prev();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
"next message" | "Try it" => {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
_ => unreachable!(),
},
@ -172,7 +171,7 @@ impl Tutorial {
&& app.per_obj.left_click(ctx, "put out the... fire?")
{
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::InspectObjects {
// TODO Have to wiggle the mouse or something after opening the panel, because of the
@ -209,12 +208,12 @@ impl Tutorial {
&& tut.inspected_border
{
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::TimeControls {
if app.primary.sim.time() >= Time::START_OF_DAY + Duration::hours(17) {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::PauseResume {
let is_paused = controls.speed.as_ref().unwrap().is_paused();
@ -228,7 +227,7 @@ impl Tutorial {
}
if tut.num_pauses == 3 {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::Escort {
let following_car =
@ -252,17 +251,17 @@ impl Tutorial {
if tut.prank_done {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::LowParking {
if tut.parking_found {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::WatchBikes {
if app.primary.sim.time() >= Time::START_OF_DAY + Duration::minutes(3) {
tut.next();
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::FixBikes {
if app.primary.sim.is_done() {
@ -331,7 +330,7 @@ impl Tutorial {
if before - after >= CAR_BIKE_CONTENTION_GOAL {
tut.next();
}
return Some(transition(ctx, app, tut));
return Some(transition(app, tut));
}
} else if tut.interaction() == Task::Done {
// If the player chooses to stay here, at least go back to the message panel.
@ -657,10 +656,10 @@ fn make_bike_lane_scenario(map: &Map) -> ScenarioGenerator {
s
}
fn transition(ctx: &mut EventCtx, app: &mut App, tut: &mut TutorialState) -> Transition {
fn transition(app: &mut App, tut: &mut TutorialState) -> Transition {
tut.reset_state();
let mode = GameplayMode::Tutorial(tut.current);
Transition::Replace(SandboxMode::simple_new(ctx, app, mode))
Transition::Replace(SandboxMode::simple_new(app, mode))
}
impl TutorialState {

View File

@ -60,21 +60,14 @@ pub struct SandboxControls {
impl SandboxMode {
/// If you don't need to chain any transitions after the SandboxMode that rely on its resources
/// being loaded, use this. Otherwise, see `async_new`.
pub fn simple_new(
ctx: &mut EventCtx,
app: &mut App,
mode: GameplayMode,
) -> Box<dyn State<App>> {
SandboxMode::async_new(ctx, app, mode, Box::new(|_, _| Vec::new()))
pub fn simple_new(app: &mut App, mode: GameplayMode) -> Box<dyn State<App>> {
SandboxMode::async_new(app, mode, Box::new(|_, _| Vec::new()))
}
/// This does not immediately initialize anything (like loading the correct map, instantiating
/// the scenario, etc). That means if you're chaining this call with other transitions, you
/// probably need to defer running them using `finalize`.
// TODO Remove the unused ctx param? It affects lots of downstream callers; maybe better to
// leave it here in case this monstrosity is refactored again.
pub fn async_new(
_: &mut EventCtx,
app: &mut App,
mode: GameplayMode,
finalize: Box<dyn FnOnce(&mut EventCtx, &mut App) -> Vec<Transition>>,

View File

@ -186,7 +186,6 @@ impl SpeedControls {
"reset to midnight" => {
if let Some(mode) = maybe_mode {
return Some(Transition::Replace(SandboxMode::simple_new(
ctx,
app,
mode.clone(),
)));

View File

@ -97,7 +97,6 @@ impl State<App> for JumpToTime {
if let Some(mode) = self.maybe_mode.take() {
let target_time = self.target;
return Transition::Replace(SandboxMode::async_new(
ctx,
app,
mode,
Box::new(move |ctx, app| {