ltn/pages/design_ltn/
one_ways.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use osm2streets::LaneSpec;
use widgetry::mapspace::{World, WorldOutcome};
use widgetry::{EventCtx, Text};

use super::{road_name, EditOutcome, Obj};
use crate::render::colors;
use crate::{App, Neighbourhood};

pub fn make_world(ctx: &mut EventCtx, app: &App, neighbourhood: &Neighbourhood) -> World<Obj> {
    let map = &app.per_map.map;
    let mut world = World::new();

    for r in &neighbourhood.interior_roads {
        let road = map.get_r(*r);
        world
            .add(Obj::Road(*r))
            .hitbox(road.get_thick_polygon())
            .drawn_in_master_batch()
            .hover_color(colors::HOVER)
            .tooltip(Text::from(format!(
                "Click to flip direction of {}",
                road_name(app, road)
            )))
            .clickable()
            .build(ctx);
    }

    world.initialize_hover(ctx);
    world
}

pub fn handle_world_outcome(
    ctx: &mut EventCtx,
    app: &mut App,
    outcome: WorldOutcome<Obj>,
) -> EditOutcome {
    match outcome {
        WorldOutcome::ClickedObject(Obj::Road(r)) => {
            if app.per_map.map.get_r(r).modal_filter.is_some() {
                return EditOutcome::error(ctx, "A one-way street can't have a filter");
            }
            if app
                .per_map
                .map
                .get_r(r)
                .is_deadend_for_driving(&app.per_map.map)
            {
                return EditOutcome::error(ctx, "A dead-end street can't be one-way");
            }

            let driving_side = app.per_map.map.get_config().driving_side;
            let mut edits = app.per_map.map.get_edits().clone();
            edits.commands.push(app.per_map.map.edit_road_cmd(r, |new| {
                LaneSpec::toggle_road_direction(&mut new.lanes_ltr, driving_side);
            }));
            app.apply_edits(edits);

            EditOutcome::UpdateAll
        }
        _ => EditOutcome::Nothing,
    }
}