map_editor/
lib.rs

1//! The map_editor renders and lets you edit RawMaps, which are a format in between OSM and the
2//! full Map. It's useful for debugging maps imported from OSM, and for drawing synthetic maps for
3//! testing.
4//!
5//! TODO It's a bit unmaintained / rarely used. Two big problems using it:
6//! - Intersection geometry isn't recalculated constantly as changes are made
7//! - The app will run out of GPU memory up-front on huge maps, because of storing objects for
8//!   every road and intersections
9
10#[macro_use]
11extern crate log;
12
13use structopt::StructOpt;
14
15use widgetry::Settings;
16
17use crate::app::App;
18
19mod app;
20mod camera;
21mod edit;
22mod load;
23mod model;
24
25pub fn main() {
26    let settings = Settings::new("RawMap editor");
27    run(settings);
28}
29
30#[derive(StructOpt)]
31#[structopt(name = "run_scenario", about = "Simulates a scenario")]
32struct Args {
33    /// The path to a RawMap to load. If omitted, start with a blank map.
34    #[structopt()]
35    load: Option<String>,
36    /// Import buildings from the RawMap. Slow.
37    #[structopt(long)]
38    include_buildings: bool,
39    /// The initial camera state
40    #[structopt(long)]
41    cam: Option<String>,
42}
43
44fn run(mut settings: Settings) {
45    abstutil::logger::setup();
46
47    settings = settings
48        .read_svg(Box::new(abstio::slurp_bytes))
49        .window_icon(abstio::path("system/assets/pregame/icon.png"));
50    widgetry::run(settings, |ctx| {
51        let args = Args::from_iter(abstutil::cli_args());
52        let mut app = App {
53            model: model::Model::blank(),
54        };
55        app.model.include_bldgs = args.include_buildings;
56
57        let states = if let Some(path) = args.load {
58            // In case the initial load fails, stick a blank state at the bottom
59            vec![
60                app::MainState::new_state(ctx, &app),
61                load::load_map(ctx, path, args.include_buildings, args.cam),
62            ]
63        } else {
64            vec![app::MainState::new_state(ctx, &app)]
65        };
66        (app, states)
67    });
68}
69
70#[cfg(target_arch = "wasm32")]
71use wasm_bindgen::prelude::*;
72
73#[cfg(target_arch = "wasm32")]
74#[wasm_bindgen(js_name = "run")]
75pub fn run_wasm(root_dom_id: String, assets_base_url: String, assets_are_gzipped: bool) {
76    let settings = Settings::new("RawMap editor")
77        .root_dom_element_id(root_dom_id)
78        .assets_base_url(assets_base_url)
79        .assets_are_gzipped(assets_are_gzipped);
80    run(settings);
81}