From 4b7a424b1f3878a8581de3035dfda0f0f122d6d8 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 12 Dec 2018 17:23:27 -0800 Subject: [PATCH] remove duplicate color definitions and don't allow them --- editor/extract_colorscheme.py | 3 ++- editor/src/colors.rs | 4 ++++ editor/src/plugins/edit/draw_neighborhoods.rs | 2 +- editor/src/plugins/edit/scenarios.rs | 8 ++------ editor/src/plugins/sim/diff_all.rs | 8 ++------ editor/src/plugins/view/show_route.rs | 2 +- editor/src/render/intersection.rs | 2 +- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/editor/extract_colorscheme.py b/editor/extract_colorscheme.py index 2ab2353610..7d34f36013 100755 --- a/editor/extract_colorscheme.py +++ b/editor/extract_colorscheme.py @@ -10,7 +10,8 @@ def run(): for f in files: if f.endswith('.rs') and f != 'colors.rs': for k, v in read_file(os.path.join(path, f)): - # TODO Check for double-definitions + if k in mapping: + raise ValueError('Color {} defined twice'.format(k)) mapping[k] = v with open('src/init_colors.rs', 'w') as f: diff --git a/editor/src/colors.rs b/editor/src/colors.rs index 88307c7745..929a56562d 100644 --- a/editor/src/colors.rs +++ b/editor/src/colors.rs @@ -38,6 +38,10 @@ impl ColorScheme { self.map[name] } + pub fn get(&self, name: &str) -> Color { + self.map[name] + } + // Just for the color picker plugin, that's why the funky return value pub fn color_names(&self) -> Vec<(String, ())> { let mut names: Vec<(String, ())> = self.map.keys().map(|n| (n.clone(), ())).collect(); diff --git a/editor/src/plugins/edit/draw_neighborhoods.rs b/editor/src/plugins/edit/draw_neighborhoods.rs index 5756d75608..036d4d7469 100644 --- a/editor/src/plugins/edit/draw_neighborhoods.rs +++ b/editor/src/plugins/edit/draw_neighborhoods.rs @@ -126,7 +126,7 @@ impl Plugin for DrawNeighborhoodState { } for pt in &pts { g.draw_circle( - ctx.cs.get_def("neighborhood point", Color::RED), + ctx.cs.get("neighborhood point"), &Circle::new(*pt, POINT_RADIUS), ); } diff --git a/editor/src/plugins/edit/scenarios.rs b/editor/src/plugins/edit/scenarios.rs index 8ba6d3a6ff..61597fa6e0 100644 --- a/editor/src/plugins/edit/scenarios.rs +++ b/editor/src/plugins/edit/scenarios.rs @@ -3,7 +3,7 @@ use crate::plugins::{ choose_intersection, choose_neighborhood, choose_origin_destination, input_tick, input_weighted_usize, load_scenario, Plugin, PluginCtx, }; -use ezgui::{Color, GfxCtx, LogScroller, Wizard, WrappedWizard}; +use ezgui::{GfxCtx, LogScroller, Wizard, WrappedWizard}; use map_model::Map; use piston::input::Key; use sim::{BorderSpawnOverTime, Neighborhood, Scenario, SeedParkedCars, SpawnOverTime}; @@ -78,11 +78,7 @@ impl Plugin for ScenarioManager { } ScenarioManager::EditScenario(_, wizard) => { if let Some(neighborhood) = wizard.current_menu_choice::() { - g.draw_polygon( - ctx.cs - .get_def("neighborhood polygon", Color::rgba(0, 0, 255, 0.6)), - &neighborhood.polygon, - ); + g.draw_polygon(ctx.cs.get("neighborhood polygon"), &neighborhood.polygon); } wizard.draw(g, ctx.canvas); } diff --git a/editor/src/plugins/sim/diff_all.rs b/editor/src/plugins/sim/diff_all.rs index 4e0286f289..c81fb30b9e 100644 --- a/editor/src/plugins/sim/diff_all.rs +++ b/editor/src/plugins/sim/diff_all.rs @@ -1,6 +1,6 @@ use crate::objects::Ctx; use crate::plugins::{Plugin, PluginCtx}; -use ezgui::{Color, GfxCtx}; +use ezgui::GfxCtx; use geom::Line; use map_model::LANE_THICKNESS; use piston::input::Key; @@ -46,11 +46,7 @@ impl Plugin for DiffAllState { fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) { for line in &self.lines { - g.draw_line( - ctx.cs.get_def("diff agents line", Color::YELLOW), - LANE_THICKNESS, - line, - ); + g.draw_line(ctx.cs.get("diff agents line"), LANE_THICKNESS, line); } } } diff --git a/editor/src/plugins/view/show_route.rs b/editor/src/plugins/view/show_route.rs index 8631c8890d..cfeba60538 100644 --- a/editor/src/plugins/view/show_route.rs +++ b/editor/src/plugins/view/show_route.rs @@ -80,7 +80,7 @@ impl Plugin for ShowRouteState { State::DebugAllRoutes(_, traces) => { for t in traces { g.draw_polygon( - ctx.cs.get_def("route", Color::rgba(255, 0, 0, 0.8)), + ctx.cs.get("route"), &t.make_polygons_blindly(LANE_THICKNESS), ); } diff --git a/editor/src/render/intersection.rs b/editor/src/render/intersection.rs index b7eca634ff..6c26c43d38 100644 --- a/editor/src/render/intersection.rs +++ b/editor/src/render/intersection.rs @@ -183,7 +183,7 @@ pub fn draw_signal_cycle( for crosswalk in &draw_map.get_i(cycle.parent).crosswalks { if !hide_crosswalks.contains(&crosswalk.id1) { - crosswalk.draw(g, cs.get_def("crosswalk", Color::WHITE)); + crosswalk.draw(g, cs.get("crosswalk")); } } for t in &cycle.priority_turns {