Lift parsing of --scenario_modifiers to a more common place, so it can be done in run_scenario too. #368

This commit is contained in:
Dustin Carlino 2020-10-21 08:35:38 -07:00
parent ead7960112
commit 8a1525ddfa
3 changed files with 13 additions and 8 deletions

View File

@ -43,6 +43,7 @@ impl App {
ctx.set_style(cs.gui_style.clone());
let primary = ctx.loading_screen("load map", |ctx, mut timer| {
assert!(flags.sim_flags.modifiers.is_empty());
let (map, sim, _) = flags.sim_flags.load(timer);
PerMap::map_loaded(map, sim, splash, flags, &opts, &cs, ctx, &mut timer)
});

View File

@ -3,7 +3,7 @@ extern crate log;
use abstutil::{CmdArgs, Timer};
use geom::Duration;
use sim::{ScenarioModifier, SimFlags};
use sim::SimFlags;
use crate::app::Flags;
@ -104,6 +104,11 @@ pub fn main() {
sandbox::TutorialPointer::new(n - 1, 0),
));
}
// Don't keep the scenario modifiers in the original sim_flags; they shouldn't apply to
// other scenarios loaed in the UI later.
let modifiers = flags.sim_flags.modifiers.drain(..).collect();
if mode.is_none() && flags.sim_flags.load.contains("scenarios/") {
// TODO regex
let parts = flags.sim_flags.load.split("/").collect::<Vec<_>>();
@ -111,12 +116,6 @@ pub fn main() {
let scenario = abstutil::basename(parts[parts.len() - 1]);
flags.sim_flags.load = abstutil::path_map(&map_name);
let modifiers: Vec<ScenarioModifier> = args
.optional_parse("--scenario_modifiers", |s| {
abstutil::from_json(&s.to_string().into_bytes())
})
.unwrap_or_else(Vec::new);
mode = Some(sandbox::GameplayMode::PlayScenario(
map_name, scenario, modifiers,
));

View File

@ -26,11 +26,16 @@ impl SimFlags {
let rng_seed = args
.optional_parse("--rng_seed", |s| s.parse())
.unwrap_or(SimFlags::RNG_SEED);
let modifiers: Vec<ScenarioModifier> = args
.optional_parse("--scenario_modifiers", |s| {
abstutil::from_json(&s.to_string().into_bytes())
})
.unwrap_or_else(Vec::new);
SimFlags {
load: args
.optional_free()
.unwrap_or_else(|| abstutil::path_map("montlake")),
modifiers: Vec::new(),
modifiers,
rng_seed,
opts: SimOptions::from_args(args, rng_seed),
}