diff --git a/docs/map_parking.md b/docs/map_parking.md index 53a51cfda2..f53b1954a0 100644 --- a/docs/map_parking.md +++ b/docs/map_parking.md @@ -13,7 +13,7 @@ regenerate the maps! 5. Select what kind of on-street parking the road has 6. Repeat 7. Click **Generate OsmChange file** -8. Upload the game/diff.osc file by adding a layer in JOSM +8. Upload the diff.osc file by adding a layer in JOSM Like all edits to OSM, to figure out ground-truth, you can survey in-person or use diff --git a/game/src/devtools/mapping.rs b/game/src/devtools/mapping.rs index 1f3ec8e261..03aaa3adf3 100644 --- a/game/src/devtools/mapping.rs +++ b/game/src/devtools/mapping.rs @@ -11,6 +11,7 @@ use geom::Distance; use map_model::{osm, RoadID}; use sim::DontDrawAgents; use std::collections::{BTreeMap, HashSet}; +use std::error::Error; use std::fs::File; use std::io::Write; @@ -281,13 +282,15 @@ impl State for ParkingMapper { vec!["Map some parking first"], )); } - ctx.loading_screen("generate OsmChange file", |_, timer| { + return match ctx.loading_screen("generate OsmChange file", |_, timer| { generate_osmc(&self.data, timer) - }); - return Transition::Push(msg( - "Diff generated", - vec!["diff.osc created. Load it in JOSM, verify, and upload!"], - )); + }) { + Ok(()) => Transition::Push(msg( + "Diff generated", + vec!["diff.osc created. Load it in JOSM, verify, and upload!"], + )), + Err(err) => Transition::Push(msg("Error", vec![format!("{}", err)])), + }; } "change map" => { return Transition::Push(WizardState::new(Box::new(load_map))); @@ -320,10 +323,12 @@ impl State for ParkingMapper { } #[cfg(target_arch = "wasm32")] -fn generate_osmc(data: &BTreeMap, timer: &mut Timer) {} +fn generate_osmc(data: &BTreeMap, timer: &mut Timer) -> Result<(), Box> { + Err("Woops, mapping mode isn't supported on the web yet".to_string()) +} #[cfg(not(target_arch = "wasm32"))] -fn generate_osmc(data: &BTreeMap, timer: &mut Timer) { +fn generate_osmc(data: &BTreeMap, timer: &mut Timer) -> Result<(), Box> { let mut modified_ways = Vec::new(); timer.start_iter("fetch latest OSM data per modified way", data.len()); for (way, value) in data { @@ -334,9 +339,8 @@ fn generate_osmc(data: &BTreeMap, timer: &mut Timer) { let url = format!("https://api.openstreetmap.org/api/0.6/way/{}", way); timer.note(format!("Fetching {}", url)); - let resp = reqwest::blocking::get(&url).unwrap().text().unwrap(); - let mut tree = xmltree::Element::parse(resp.as_bytes()) - .unwrap() + let resp = reqwest::blocking::get(&url)?.text()?; + let mut tree = xmltree::Element::parse(resp.as_bytes())? .take_child("way") .unwrap(); let mut osm_tags = BTreeMap::new(); @@ -388,20 +392,21 @@ fn generate_osmc(data: &BTreeMap, timer: &mut Timer) { tree.attributes.remove("visible"); let mut bytes: Vec = Vec::new(); - tree.write(&mut bytes).unwrap(); - let out = String::from_utf8(bytes).unwrap(); + tree.write(&mut bytes)?; + let out = String::from_utf8(bytes)?; let stripped = out.trim_start_matches(""); modified_ways.push(stripped.to_string()); } - let path = "diff.osc"; - let mut f = File::create(path).unwrap(); - writeln!(f, "").unwrap(); + let path = "../diff.osc"; + let mut f = File::create(path)?; + writeln!(f, "")?; for w in modified_ways { - writeln!(f, " {}", w).unwrap(); + writeln!(f, " {}", w)?; } - writeln!(f, "").unwrap(); + writeln!(f, "")?; timer.note(format!("Wrote {}", path)); + Ok(()) } fn load_map(wiz: &mut Wizard, ctx: &mut EventCtx, app: &mut App) -> Option { diff --git a/game/src/pregame.rs b/game/src/pregame.rs index 5fa680fff0..34a22bcbeb 100644 --- a/game/src/pregame.rs +++ b/game/src/pregame.rs @@ -133,7 +133,7 @@ pub fn main_menu(ctx: &mut EventCtx, app: &App) -> Box { }) .build_def(ctx, hotkey(Key::M)), if app.opts.dev { - Btn::text_bg2("Internal Dev Tools").build_def(ctx, hotkey(Key::M)) + Btn::text_bg2("Internal Dev Tools").build_def(ctx, hotkey(Key::D)) } else { Widget::nothing() },