-
-
Notifications
You must be signed in to change notification settings - Fork 323
/
road_stroke_canvas.rs
83 lines (74 loc) · 2.61 KB
/
road_stroke_canvas.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use kay::{Actor, Swarm, ID, Recipient, CreateWith, ActorSystem, Individual, Fate};
use descartes::{Into2d, P2};
use core::geometry::AnyShape;
use core::ui::{UserInterface, VirtualKeyCode};
use super::{CurrentPlan};
#[derive(Copy, Clone, Actor, Default)]
pub struct RoadStrokeCanvas {_id: ID, last_click: Option<P2>}
impl RoadStrokeCanvas{
pub fn new() -> Self {Self::default()}
}
use super::AddToUI;
use core::ui::Add;
use core::ui::Focus;
impl Recipient<AddToUI> for RoadStrokeCanvas {
fn receive(&mut self, _msg: &AddToUI) -> Fate {
UserInterface::id() << Add::Interactable3d(self.id(), AnyShape::Everywhere, 0);
UserInterface::id() << Focus(self.id());
Fate::Live
}
}
use super::ClearAll;
use core::ui::Remove;
impl Recipient<ClearAll> for RoadStrokeCanvas {
fn receive(&mut self, _msg: &ClearAll) -> Fate {
UserInterface::id() << Remove::Interactable3d(self.id());
Fate::Die
}
}
use core::ui::Event3d;
use super::PlanControl::{AddRoadStrokeNode, Materialize, CreateGrid};
use super::RecreateInteractables;
use game::lanes_and_cars::{Lane, LaneCar, Obstacle};
use ordered_float::OrderedFloat;
impl Recipient<Event3d> for RoadStrokeCanvas {
fn receive(&mut self, msg: &Event3d) -> Fate {match *msg {
Event3d::DragStarted{at} => {
CurrentPlan::id() << AddRoadStrokeNode(at.into_2d(), true);
Fate::Live
},
Event3d::DragFinished{..} => {
CurrentPlan::id() << RecreateInteractables;
Fate::Live
},
Event3d::KeyDown(VirtualKeyCode::Return) => {
CurrentPlan::id() << Materialize(());
Fate::Live
},
Event3d::KeyDown(VirtualKeyCode::C) => {
for _i in 0..100 {
Swarm::<Lane>::all() << ::game::lanes_and_cars::Add::Car(LaneCar{
trip: ID::invalid(),
as_obstacle: Obstacle{
position: OrderedFloat(0.0),
velocity: 0.0,
max_velocity: 20.0
},
acceleration: 0.0
});
}
Fate::Live
},
Event3d::KeyDown(VirtualKeyCode::G) => {
CurrentPlan::id() << CreateGrid(());
Fate::Live
}
_ => Fate::Live
}}
}
pub fn setup(system: &mut ActorSystem) {
system.add_individual(Swarm::<RoadStrokeCanvas>::new());
system.add_inbox::<ClearAll, Swarm<RoadStrokeCanvas>>();
system.add_inbox::<Event3d, Swarm<RoadStrokeCanvas>>();
system.add_inbox::<CreateWith<RoadStrokeCanvas, AddToUI>, Swarm<RoadStrokeCanvas>>();
}