rustapi/actions/
create_linedef.rs1use crate::prelude::*;
2
3pub struct CreateLinedef {
4 id: TheId,
5 nodeui: TheNodeUI,
6}
7
8impl Action for CreateLinedef {
9 fn new() -> Self
10 where
11 Self: Sized,
12 {
13 let mut nodeui: TheNodeUI = TheNodeUI::default();
14 let item = TheNodeUIItem::Markdown("desc".into(), fl!("action_create_linedef_desc"));
15 nodeui.add_item(item);
16
17 Self {
18 id: TheId::named(&fl!("action_create_linedef")),
19 nodeui,
20 }
21 }
22
23 fn id(&self) -> TheId {
24 self.id.clone()
25 }
26
27 fn info(&self) -> String {
28 fl!("action_create_linedef_desc")
29 }
30
31 fn role(&self) -> ActionRole {
32 ActionRole::Editor
33 }
34
35 fn accel(&self) -> Option<TheAccelerator> {
36 None
37 }
38
39 fn is_applicable(&self, map: &Map, _ctx: &mut TheContext, _server_ctx: &ServerContext) -> bool {
40 map.selected_vertices.len() == 2
41 }
42
43 fn apply(
44 &self,
45 map: &mut Map,
46 _ui: &mut TheUI,
47 _ctx: &mut TheContext,
48 server_ctx: &mut ServerContext,
49 ) -> Option<ProjectUndoAtom> {
50 let changed = true;
51 let prev = map.clone();
52
53 _ = map.create_linedef_manual(map.selected_vertices[0], map.selected_vertices[1]);
55 map.possible_polygon.clear();
56
57 if changed {
58 Some(ProjectUndoAtom::MapEdit(
59 server_ctx.pc,
60 Box::new(prev),
61 Box::new(map.clone()),
62 ))
63 } else {
64 None
65 }
66 }
67
68 fn params(&self) -> TheNodeUI {
69 self.nodeui.clone()
70 }
71
72 fn handle_event(
73 &mut self,
74 event: &TheEvent,
75 _project: &mut Project,
76 _ui: &mut TheUI,
77 _ctx: &mut TheContext,
78 _server_ctx: &mut ServerContext,
79 ) -> bool {
80 self.nodeui.handle_event(event)
81 }
82}