mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Add a --15min flag to jump right into the tool for #393
This commit is contained in:
parent
fb07e35200
commit
5c6eacf781
@ -4,6 +4,8 @@
|
||||
//!
|
||||
//! See https://github.com/dabreegster/abstreet/issues/393 for more context.
|
||||
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
use map_model::BuildingID;
|
||||
use widgetry::{
|
||||
Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, Panel,
|
||||
@ -24,6 +26,13 @@ pub struct Viewer {
|
||||
}
|
||||
|
||||
impl Viewer {
|
||||
/// Start with a random building
|
||||
pub fn random_start(ctx: &mut EventCtx, app: &App) -> Box<dyn State<App>> {
|
||||
let mut rng = app.primary.current_flags.sim_flags.make_rng();
|
||||
let start = app.primary.map.all_buildings().choose(&mut rng).unwrap().id;
|
||||
Viewer::new(ctx, app, start)
|
||||
}
|
||||
|
||||
pub fn new(ctx: &mut EventCtx, app: &App, start: BuildingID) -> Box<dyn State<App>> {
|
||||
let start = app.primary.map.get_b(start);
|
||||
|
||||
|
@ -114,11 +114,20 @@ pub fn main(mut args: CmdArgs) {
|
||||
}
|
||||
let start_with_edits = args.optional("--edits");
|
||||
let osm_viewer = args.enabled("--osm");
|
||||
let fifteen_min = args.enabled("--15min");
|
||||
|
||||
args.done();
|
||||
|
||||
widgetry::run(settings, |ctx| {
|
||||
setup_app(ctx, flags, opts, start_with_edits, mode, osm_viewer)
|
||||
setup_app(
|
||||
ctx,
|
||||
flags,
|
||||
opts,
|
||||
start_with_edits,
|
||||
mode,
|
||||
osm_viewer,
|
||||
fifteen_min,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
@ -129,11 +138,13 @@ fn setup_app(
|
||||
start_with_edits: Option<String>,
|
||||
maybe_mode: Option<GameplayMode>,
|
||||
osm_viewer: bool,
|
||||
fifteen_min: bool,
|
||||
) -> (App, Vec<Box<dyn State<App>>>) {
|
||||
let title = !opts.dev
|
||||
&& !flags.sim_flags.load.contains("player/save")
|
||||
&& !flags.sim_flags.load.contains("/scenarios/")
|
||||
&& !osm_viewer
|
||||
&& !fifteen_min
|
||||
&& maybe_mode.is_none();
|
||||
let mut app = App::new(flags, opts, ctx, title);
|
||||
|
||||
@ -173,6 +184,10 @@ fn setup_app(
|
||||
vec![Box::new(TitleScreen::new(ctx, &mut app))]
|
||||
} else if osm_viewer {
|
||||
vec![crate::devtools::osm_viewer::Viewer::new(ctx, &mut app)]
|
||||
} else if fifteen_min {
|
||||
vec![crate::devtools::fifteen_min::Viewer::random_start(
|
||||
ctx, &app,
|
||||
)]
|
||||
} else {
|
||||
let mode = maybe_mode
|
||||
.unwrap_or_else(|| GameplayMode::Freeform(app.primary.map.get_name().clone()));
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use instant::Instant;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::Rng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
@ -224,11 +223,8 @@ impl State<App> for MainMenu {
|
||||
return Transition::Push(crate::devtools::osm_viewer::Viewer::new(ctx, app));
|
||||
}
|
||||
"15-minute neighborhoods" => {
|
||||
// Start with a random building
|
||||
let mut rng = app.primary.current_flags.sim_flags.make_rng();
|
||||
let start = app.primary.map.all_buildings().choose(&mut rng).unwrap().id;
|
||||
return Transition::Push(crate::devtools::fifteen_min::Viewer::new(
|
||||
ctx, app, start,
|
||||
return Transition::Push(crate::devtools::fifteen_min::Viewer::random_start(
|
||||
ctx, app,
|
||||
));
|
||||
}
|
||||
"Contribute parking data to OpenStreetMap" => {
|
||||
|
Loading…
Reference in New Issue
Block a user