mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 17:37:22 +03:00
follow build.rs output rules better... even though spurious recompiles
still happen. :(
This commit is contained in:
parent
e51a8efbc3
commit
999c4e6975
@ -1,11 +1,16 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let output = Path::new(&env::var("OUT_DIR").unwrap()).join("init_colors.rs");
|
||||
|
||||
// TODO Argh, this runs even when nothing in the editor crate has changed! Constant
|
||||
// recompilation. :(
|
||||
assert!(Command::new("/usr/bin/python2")
|
||||
.args(&["extract_colorscheme.py"])
|
||||
.args(&["extract_colorscheme.py", output.to_str().unwrap()])
|
||||
.status()
|
||||
.unwrap()
|
||||
.success());
|
||||
//println!("cargo:rerun-if-changed=build.rs");
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run():
|
||||
mapping = {}
|
||||
@ -14,21 +15,14 @@ def run():
|
||||
raise ValueError('Color {} defined twice'.format(k))
|
||||
mapping[k] = v
|
||||
|
||||
with open('src/init_colors.rs', 'w') as f:
|
||||
f.write('// AUTOGENERATED! Do not modify.\n')
|
||||
f.write('\n')
|
||||
f.write('use ezgui::Color;\n')
|
||||
f.write('use std::collections::HashMap;\n')
|
||||
f.write('\n')
|
||||
f.write('pub fn default_colors() -> HashMap<String, Color> {\n')
|
||||
with open(sys.argv[1], 'w') as f:
|
||||
f.write('fn default_colors() -> HashMap<String, Color> {\n')
|
||||
f.write(' let mut m = HashMap::new();\n')
|
||||
for k in sorted(mapping.iterkeys()):
|
||||
f.write(' m.insert("{}".to_string(), {});\n'.format(k, mapping[k]))
|
||||
f.write(' m\n')
|
||||
f.write('}\n')
|
||||
|
||||
subprocess.call(['rustfmt', 'src/init_colors.rs'])
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
entries = []
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::init_colors;
|
||||
use abstutil;
|
||||
use ezgui::Color;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@ -20,7 +19,7 @@ struct ModifiedColors {
|
||||
impl ColorScheme {
|
||||
pub fn load() -> Result<ColorScheme, Error> {
|
||||
let modified: ModifiedColors = abstutil::read_json("color_scheme")?;
|
||||
let mut map: HashMap<String, Color> = init_colors::default_colors();
|
||||
let mut map: HashMap<String, Color> = default_colors();
|
||||
for (name, c) in &modified.map {
|
||||
map.insert(name.clone(), *c);
|
||||
}
|
||||
@ -33,7 +32,7 @@ impl ColorScheme {
|
||||
}
|
||||
|
||||
// Get, but specify the default inline. The default is extracted before compilation by a script
|
||||
// and used to generate init_colors.rs.
|
||||
// and used to generate default_colors().
|
||||
pub fn get_def(&self, name: &str, _default: Color) -> Color {
|
||||
self.map[name]
|
||||
}
|
||||
@ -65,8 +64,9 @@ impl ColorScheme {
|
||||
} else {
|
||||
self.modified.map.remove(name);
|
||||
// Restore the original default.
|
||||
self.map
|
||||
.insert(name.to_string(), init_colors::default_colors()[name]);
|
||||
self.map.insert(name.to_string(), default_colors()[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/init_colors.rs"));
|
||||
|
@ -1,147 +0,0 @@
|
||||
// AUTOGENERATED! Do not modify.
|
||||
|
||||
use ezgui::Color;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn default_colors() -> HashMap<String, Color> {
|
||||
let mut m = HashMap::new();
|
||||
m.insert("OSM house".to_string(), Color::GREEN);
|
||||
m.insert("OSM motorway".to_string(), Color::rgb(231, 141, 159));
|
||||
m.insert("OSM primary".to_string(), Color::rgb(252, 213, 160));
|
||||
m.insert("OSM residential".to_string(), Color::rgb(254, 254, 254));
|
||||
m.insert("OSM secondary".to_string(), Color::rgb(252, 213, 160));
|
||||
m.insert("OSM trunk".to_string(), Color::rgb(249, 175, 152));
|
||||
m.insert("banned turn".to_string(), Color::BLACK);
|
||||
m.insert("bike lane".to_string(), Color::rgb(15, 125, 75));
|
||||
m.insert(
|
||||
"bike stopping buffer".to_string(),
|
||||
Color::rgba(255, 0, 0, 0.7),
|
||||
);
|
||||
m.insert("blinker on".to_string(), Color::BLACK);
|
||||
m.insert("border intersection".to_string(), Color::rgb(50, 205, 50));
|
||||
m.insert("broken lane".to_string(), Color::rgb_f(1.0, 0.0, 0.565));
|
||||
m.insert("building".to_string(), Color::rgba_f(0.7, 0.7, 0.7, 0.8));
|
||||
m.insert("building boundary".to_string(), Color::rgb(0, 100, 0));
|
||||
m.insert("building path".to_string(), Color::grey(0.6));
|
||||
m.insert("bus lane".to_string(), Color::rgb(190, 74, 76));
|
||||
m.insert(
|
||||
"bus stop marking".to_string(),
|
||||
Color::rgba(220, 160, 220, 0.8),
|
||||
);
|
||||
m.insert(
|
||||
"car stopping buffer".to_string(),
|
||||
Color::rgba(255, 0, 0, 0.7),
|
||||
);
|
||||
m.insert("car window".to_string(), Color::BLACK);
|
||||
m.insert("chokepoint".to_string(), Color::RED);
|
||||
m.insert("crosswalk".to_string(), Color::WHITE);
|
||||
m.insert("crosswalk turn".to_string(), Color::WHITE);
|
||||
m.insert(
|
||||
"current cycle in signal editor panel".to_string(),
|
||||
Color::BLUE.alpha(0.95),
|
||||
);
|
||||
m.insert("current selected turn".to_string(), Color::RED);
|
||||
m.insert("dashed lane line".to_string(), Color::WHITE);
|
||||
m.insert("debug bike".to_string(), Color::rgba(0, 0, 255, 0.8));
|
||||
m.insert("debug car".to_string(), Color::rgba(0, 0, 255, 0.8));
|
||||
m.insert("debug line".to_string(), Color::RED);
|
||||
m.insert(
|
||||
"debug line endpoint".to_string(),
|
||||
Color::rgb_f(0.8, 0.1, 0.1),
|
||||
);
|
||||
m.insert("diff agents line".to_string(), Color::YELLOW);
|
||||
m.insert("driving lane".to_string(), Color::BLACK);
|
||||
m.insert("extra shape".to_string(), Color::CYAN);
|
||||
m.insert("inactive turn icon".to_string(), Color::grey(0.7));
|
||||
m.insert("left turn".to_string(), Color::RED);
|
||||
m.insert("map background".to_string(), Color::rgb(242, 239, 233));
|
||||
m.insert("moving bike".to_string(), Color::GREEN);
|
||||
m.insert("moving car".to_string(), Color::CYAN);
|
||||
m.insert("neighborhood last placed point".to_string(), Color::GREEN);
|
||||
m.insert("neighborhood point".to_string(), Color::RED);
|
||||
m.insert("neighborhood point to move".to_string(), Color::CYAN);
|
||||
m.insert(
|
||||
"neighborhood polygon".to_string(),
|
||||
Color::rgba(0, 0, 255, 0.6),
|
||||
);
|
||||
m.insert("next to visit in floodfill".to_string(), Color::GREEN);
|
||||
m.insert("parcel boundary".to_string(), Color::grey(0.3));
|
||||
m.insert("park area".to_string(), Color::GREEN);
|
||||
m.insert("parked car".to_string(), Color::rgb(180, 233, 76));
|
||||
m.insert("parking lane".to_string(), Color::grey(0.2));
|
||||
m.insert("parking line".to_string(), Color::WHITE);
|
||||
m.insert("pedestrian".to_string(), Color::rgb_f(0.2, 0.7, 0.7));
|
||||
m.insert(
|
||||
"pedestrian preparing bike".to_string(),
|
||||
Color::rgb(255, 0, 144),
|
||||
);
|
||||
m.insert("pedestrian turn arrow".to_string(), Color::CYAN);
|
||||
m.insert(
|
||||
"primary agent route".to_string(),
|
||||
Color::rgba(255, 0, 0, 0.5),
|
||||
);
|
||||
m.insert("priority stop sign turn".to_string(), Color::GREEN);
|
||||
m.insert("priority turn in current cycle".to_string(), Color::GREEN);
|
||||
m.insert("queued in floodfill".to_string(), Color::RED);
|
||||
m.insert("right turn".to_string(), Color::GREEN);
|
||||
m.insert("road center line".to_string(), Color::YELLOW);
|
||||
m.insert("route".to_string(), Color::rgba(255, 0, 0, 0.8));
|
||||
m.insert("search result".to_string(), Color::RED);
|
||||
m.insert(
|
||||
"secondary agent route".to_string(),
|
||||
Color::rgba(0, 0, 255, 0.5),
|
||||
);
|
||||
m.insert("selected".to_string(), Color::BLUE);
|
||||
m.insert("selected turn icon".to_string(), Color::BLUE.alpha(0.5));
|
||||
m.insert("shared sidewalk corner turn".to_string(), Color::BLACK);
|
||||
m.insert("sidewalk".to_string(), Color::grey(0.8));
|
||||
m.insert("sidewalk corner".to_string(), Color::grey(0.7));
|
||||
m.insert("sidewalk lines".to_string(), Color::grey(0.7));
|
||||
m.insert("signal editor panel".to_string(), Color::BLACK.alpha(0.95));
|
||||
m.insert("signal overtime timer".to_string(), Color::PINK);
|
||||
m.insert(
|
||||
"something associated with something else".to_string(),
|
||||
Color::PURPLE,
|
||||
);
|
||||
m.insert("stop line for lane".to_string(), Color::RED);
|
||||
m.insert("stop sign background".to_string(), Color::RED);
|
||||
m.insert("stop sign priority turns".to_string(), Color::GREEN);
|
||||
m.insert("stop sign stop crosswalk".to_string(), Color::RED);
|
||||
m.insert("stop sign stop turns".to_string(), Color::RED.alpha(0.8));
|
||||
m.insert("stop sign yield crosswalk".to_string(), Color::YELLOW);
|
||||
m.insert(
|
||||
"stop sign yield turns".to_string(),
|
||||
Color::YELLOW.alpha(0.8),
|
||||
);
|
||||
m.insert("stop turn".to_string(), Color::RED);
|
||||
m.insert("straight turn".to_string(), Color::BLUE);
|
||||
m.insert("stuck bike".to_string(), Color::RED);
|
||||
m.insert("stuck car".to_string(), Color::RED);
|
||||
m.insert("swamp area".to_string(), Color::rgb_f(0.0, 1.0, 0.6));
|
||||
m.insert("timer background".to_string(), Color::BLACK);
|
||||
m.insert("timer foreground".to_string(), Color::RED);
|
||||
m.insert("traffic signal box".to_string(), Color::BLACK);
|
||||
m.insert("traffic signal green".to_string(), Color::GREEN);
|
||||
m.insert("traffic signal red".to_string(), Color::RED);
|
||||
m.insert("traffic signal yellow".to_string(), Color::YELLOW);
|
||||
m.insert("turn icon circle".to_string(), Color::grey(0.3));
|
||||
m.insert("turn not in current cycle".to_string(), Color::BLACK);
|
||||
m.insert("turn restrictions on lane".to_string(), Color::WHITE);
|
||||
m.insert(
|
||||
"turns allowed with yielding by traffic signal right now".to_string(),
|
||||
Color::rgba(255, 105, 180, 0.8),
|
||||
);
|
||||
m.insert(
|
||||
"turns protected by traffic signal right now".to_string(),
|
||||
Color::GREEN,
|
||||
);
|
||||
m.insert("unchanged intersection".to_string(), Color::grey(0.6));
|
||||
m.insert("visited in floodfill".to_string(), Color::BLUE);
|
||||
m.insert("water area".to_string(), Color::BLUE);
|
||||
m.insert("yield stop sign turn".to_string(), Color::YELLOW);
|
||||
m.insert(
|
||||
"yield turn in current cycle".to_string(),
|
||||
Color::rgb(255, 105, 180),
|
||||
);
|
||||
m
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
mod macros;
|
||||
|
||||
mod colors;
|
||||
mod init_colors;
|
||||
mod objects;
|
||||
mod plugins;
|
||||
mod render;
|
||||
|
Loading…
Reference in New Issue
Block a user