Skip to content

Commit ca1fb9a

Browse files
amyangerdabreegster
authored andcommitted
Add startup flags for layer and info URL parameters
- Add --layer parameter to start with specific layers (steep_streets, elevation, map_edits, no_sidewalks, transit_network) - Add --info parameter to open specific info panels using warp syntax (e.g. b42 for building 42) - Export inner_warp_to_id function for URL parameter handling - Addresses issue #666
1 parent 8dd1b20 commit ca1fb9a

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

apps/game/src/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use widgetry::{
1010

1111
pub use self::route_sketcher::RouteSketcher;
1212
pub use self::select::RoadSelector;
13-
pub use self::warp::{warp_to_id, Warping};
13+
pub use self::warp::{inner_warp_to_id, warp_to_id, Warping};
1414
use crate::app::App;
1515
use crate::app::Transition;
1616
use crate::info::{ContextualActions, InfoPanel, Tab};

apps/game/src/common/warp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn warp_to_id(ctx: &mut EventCtx, app: &mut App, input: &str) -> Transition
163163
}
164164
}
165165

166-
fn inner_warp_to_id(ctx: &mut EventCtx, app: &mut App, line: &str) -> Option<Transition> {
166+
pub fn inner_warp_to_id(ctx: &mut EventCtx, app: &mut App, line: &str) -> Option<Transition> {
167167
if line.is_empty() {
168168
return None;
169169
}

apps/game/src/lib.rs

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use map_model::{Map, MapEdits};
1717
use sim::Sim;
1818
use synthpop::Scenario;
1919
use widgetry::tools::{FutureLoader, PopupMsg, URLManager};
20-
use widgetry::{EventCtx, Settings, State, Transition};
20+
use widgetry::{EventCtx, GfxCtx, Settings, State};
2121

22-
use crate::app::{App, Flags, PerMap};
22+
use crate::app::{App, Flags, PerMap, Transition};
2323
use crate::common::jump_to_time_upon_startup;
2424
use crate::id::ID;
2525
use crate::pregame::TitleScreen;
@@ -111,6 +111,12 @@ struct Args {
111111
/// Start on a particular tutorial stage
112112
#[structopt(long)]
113113
tutorial: Option<usize>,
114+
/// Start with a specific layer enabled. Example: steep_streets
115+
#[structopt(long)]
116+
layer: Option<String>,
117+
/// Start with a specific info panel open. Example: b42 for building 42
118+
#[structopt(long)]
119+
info: Option<String>,
114120
/// Start in ActDev mode for a particular site name.
115121
#[structopt(long)]
116122
actdev: Option<String>,
@@ -131,6 +137,8 @@ struct Setup {
131137
start_time: Option<Duration>,
132138
diff_map: Option<String>,
133139
mode: Mode,
140+
start_with_layer: Option<String>,
141+
start_with_info_panel: Option<String>,
134142
}
135143

136144
// TODO Switch to explicit enum subcommands, each of which includes precisely the set of common
@@ -175,6 +183,8 @@ fn run(mut settings: Settings) {
175183
center_camera: args.cam,
176184
start_time: args.start_time,
177185
diff_map: args.diff_map,
186+
start_with_layer: args.layer,
187+
start_with_info_panel: args.info,
178188
mode: if args.tutorial_intro {
179189
Mode::TutorialIntro
180190
} else if args.challenges {
@@ -513,6 +523,35 @@ fn finish_app_setup(
513523
return vec![TitleScreen::new_state(ctx, app)];
514524
}
515525

526+
// Handle layer parameter before creating the state
527+
if let Some(layer_name) = setup.start_with_layer {
528+
match layer_name.as_str() {
529+
"steep_streets" => {
530+
app.primary.layer = Some(Box::new(layer::elevation::SteepStreets::new(ctx, app)));
531+
}
532+
"elevation" => {
533+
app.primary.layer = Some(Box::new(layer::elevation::ElevationContours::new(ctx, app)));
534+
}
535+
"map_edits" => {
536+
app.primary.layer = Some(Box::new(layer::map::Static::edits(ctx, app)));
537+
}
538+
"no_sidewalks" => {
539+
app.primary.layer = Some(Box::new(layer::map::Static::no_sidewalks(ctx, app)));
540+
}
541+
"parking_occupancy" => {
542+
// Parking occupancy layer - skipping for now as it needs more parameters
543+
warn!("parking_occupancy layer not implemented in URL parameters yet");
544+
}
545+
"transit_network" => {
546+
// Transit network layer - showing all routes, buses, and trains by default
547+
app.primary.layer = Some(Box::new(layer::transit::TransitNetwork::new(ctx, app, true, true, true)));
548+
}
549+
_ => {
550+
warn!("Unknown layer: {}", layer_name);
551+
}
552+
}
553+
}
554+
516555
let state = if let Some(ss) = savestate {
517556
app.primary.sim = ss;
518557
SandboxMode::start_from_savestate(app)
@@ -581,7 +620,33 @@ fn finish_app_setup(
581620
}
582621
}
583622
};
584-
vec![TitleScreen::new_state(ctx, app), state]
623+
624+
let mut states = vec![TitleScreen::new_state(ctx, app), state];
625+
626+
// Handle info panel parameter - needs to be done after the state is created
627+
if let Some(info_id) = setup.start_with_info_panel {
628+
states.push(Box::new(InitialInfoPanel { info_id }));
629+
}
630+
631+
states
632+
}
633+
634+
struct InitialInfoPanel {
635+
info_id: String,
636+
}
637+
638+
impl State<App> for InitialInfoPanel {
639+
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
640+
match crate::common::inner_warp_to_id(ctx, app, &self.info_id) {
641+
Some(t) => t,
642+
None => {
643+
warn!("Invalid info ID: {}", self.info_id);
644+
Transition::Pop
645+
}
646+
}
647+
}
648+
649+
fn draw(&self, _: &mut GfxCtx, _: &App) {}
585650
}
586651

587652
#[cfg(target_arch = "wasm32")]

0 commit comments

Comments
 (0)