From e97795044d1da27d0f37568209d83c61bcd675f9 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 8 May 2020 12:01:08 -0700 Subject: [PATCH] edit existing polygons --- abstutil/src/lib.rs | 5 ----- game/src/devtools/mod.rs | 29 +++++++++++++++++++++++++++-- game/src/devtools/polygon.rs | 31 ++++++++++++++++++++++++++++--- updater/src/main.rs | 1 + 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/abstutil/src/lib.rs b/abstutil/src/lib.rs index 70c9a307b6..fd4d3617f6 100644 --- a/abstutil/src/lib.rs +++ b/abstutil/src/lib.rs @@ -153,11 +153,6 @@ pub fn path_pending_screenshots(map_name: &str) -> String { format!("../data/input/screenshots/pending_{}", map_name) } -// TODO Few callers, and importer just manually builds this path anyway -pub fn path_polygon(city: &str, polygon_name: &str) -> String { - format!("../data/input/{}/polygons/{}.poly", city, polygon_name) -} - pub fn path_popdat() -> String { format!("../data/input/seattle/popdat.bin") } diff --git a/game/src/devtools/mod.rs b/game/src/devtools/mod.rs index 0d1beed725..e40927f8ae 100644 --- a/game/src/devtools/mod.rs +++ b/game/src/devtools/mod.rs @@ -12,21 +12,32 @@ pub struct DevToolsMode; impl DevToolsMode { pub fn new(ctx: &mut EventCtx, app: &App) -> Box { - ManagedGUIState::over_map( + ManagedGUIState::fullscreen( WrappedComposite::new(WrappedComposite::quick_menu( ctx, app, "Internal dev tools", vec![], vec![ + (hotkey(Key::E), "edit a polygon"), (hotkey(Key::P), "draw a polygon"), (hotkey(Key::W), "load scenario"), ], )) .cb("X", Box::new(|_, _| Some(Transition::Pop))) + .cb( + "edit a polygon", + Box::new(|_, _| Some(Transition::Push(WizardState::new(Box::new(choose_polygon))))), + ) .cb( "draw a polygon", - Box::new(|ctx, app| Some(Transition::Push(polygon::PolygonEditor::new(ctx, app)))), + Box::new(|ctx, app| { + Some(Transition::Push(polygon::PolygonEditor::new( + ctx, + app, + Vec::new(), + ))) + }), ) .cb( "load scenario", @@ -49,3 +60,17 @@ fn load_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, app: &mut App) -> Option< scenario::ScenarioManager::new(scenario, ctx, app), ))) } + +fn choose_polygon(wiz: &mut Wizard, ctx: &mut EventCtx, app: &mut App) -> Option { + // TODO Sorry, Seattle only right now + let name = wiz.wrap(ctx).choose_string("Edit which polygon?", || { + abstutil::list_all_objects("../data/input/seattle/polygons/".to_string()) + })?; + match polygon::read_from_osmosis(format!("../data/input/seattle/polygons/{}.poly", name)) { + Ok(pts) => Some(Transition::Push(polygon::PolygonEditor::new(ctx, app, pts))), + Err(err) => { + println!("Bad polygon {}: {}", name, err); + Some(Transition::Pop) + } + } +} diff --git a/game/src/devtools/polygon.rs b/game/src/devtools/polygon.rs index 130fa4185a..286dd79eb8 100644 --- a/game/src/devtools/polygon.rs +++ b/game/src/devtools/polygon.rs @@ -5,7 +5,7 @@ use crate::managed::WrappedComposite; use ezgui::{hotkey, Color, Composite, EventCtx, GfxCtx, Key, Line, Outcome, Text}; use geom::{Circle, Distance, LonLat, Polygon, Pt2D}; use std::fs::File; -use std::io::{Error, Write}; +use std::io::{BufRead, BufReader, Error, ErrorKind, Write}; const POINT_RADIUS: Distance = Distance::const_meters(10.0); // Localized and internal, so don't put in ColorScheme. @@ -22,7 +22,7 @@ pub struct PolygonEditor { } impl PolygonEditor { - pub fn new(ctx: &mut EventCtx, app: &App) -> Box { + pub fn new(ctx: &mut EventCtx, app: &App, points: Vec) -> Box { Box::new(PolygonEditor { composite: WrappedComposite::quick_menu( ctx, @@ -31,7 +31,7 @@ impl PolygonEditor { vec![], vec![(hotkey(Key::X), "export as an Osmosis polygon filter")], ), - points: Vec::new(), + points, mouseover_pt: None, moving_pt: false, }) @@ -163,3 +163,28 @@ fn save_as_osmosis(pts: &Vec) -> Result<(), Error> { println!("Exported {}", path); Ok(()) } + +pub fn read_from_osmosis(path: String) -> Result, Error> { + let f = File::open(&path)?; + let mut pts = Vec::new(); + for (idx, line) in BufReader::new(f).lines().enumerate() { + if idx < 2 { + continue; + } + let line = line?; + if line == "END" { + break; + } + let parts = line.trim().split(" ").collect::>(); + pts.push(LonLat::new( + parts[0] + .parse::() + .map_err(|err| Error::new(ErrorKind::Other, err))?, + parts[1] + .parse::() + .map_err(|err| Error::new(ErrorKind::Other, err))?, + )); + } + pts.pop(); + Ok(pts) +} diff --git a/updater/src/main.rs b/updater/src/main.rs index 6906c7a499..38dbfe7adf 100644 --- a/updater/src/main.rs +++ b/updater/src/main.rs @@ -135,6 +135,7 @@ impl Manifest { let path = entry.path().display().to_string(); if path.contains("system/assets/") || path.contains("system/fonts") + || path.contains("system/proposals") || path.contains("system/synthetic_maps") || path.contains("/polygons/") {