spring_ai_rs/ai_interface/callback/drawer/
path.rs

1use spring_ai_sys::COMMAND_TO_ID_ENGINE;
2
3use crate::ai_interface::callback::{
4    command::{
5        command_data::{
6            drawer::{
7                BreakPathDrawerCommandData, DrawIconAtLastPosPathDrawerCommandData,
8                DrawLineAndIconPathDrawerCommandData, DrawLinePathDrawerCommandData,
9                FinishPathDrawerCommandData, RestartPathDrawerCommandData,
10                StartPathDrawerCommandData,
11            },
12            CommandData,
13        },
14        command_topic::CommandTopic,
15    },
16    engine::handle_command,
17};
18
19pub struct Path {
20    pub ai_id: i32,
21}
22
23impl Path {
24    pub fn path_break(
25        &self,
26        end_position: [f32; 3],
27        color: [i16; 3],
28        alpha: i16,
29    ) -> Result<(), String> {
30        let mut command_c_data = BreakPathDrawerCommandData {
31            end_position,
32            color,
33            alpha,
34        }
35        .c_data();
36
37        handle_command(
38            self.ai_id,
39            COMMAND_TO_ID_ENGINE,
40            -1,
41            CommandTopic::DrawerPathBreak.into(),
42            &mut command_c_data,
43        )?;
44
45        Ok(())
46    }
47    pub fn draw_icon_at_last_position(&self, command_id: i32) -> Result<(), String> {
48        let mut command_c_data = DrawIconAtLastPosPathDrawerCommandData { command_id }.c_data();
49
50        handle_command(
51            self.ai_id,
52            COMMAND_TO_ID_ENGINE,
53            -1,
54            CommandTopic::DrawerPathDrawIconAtLastPOS.into(),
55            &mut command_c_data,
56        )?;
57
58        Ok(())
59    }
60    pub fn draw_line(
61        &self,
62        end_position: [f32; 3],
63        color: [i16; 3],
64        alpha: i16,
65    ) -> Result<(), String> {
66        let mut command_c_data = DrawLinePathDrawerCommandData {
67            end_position,
68            color,
69            alpha,
70        }
71        .c_data();
72
73        handle_command(
74            self.ai_id,
75            COMMAND_TO_ID_ENGINE,
76            -1,
77            CommandTopic::DrawerPathDrawLine.into(),
78            &mut command_c_data,
79        )?;
80
81        Ok(())
82    }
83    pub fn draw_line_and_icon(
84        &self,
85        command_id: i32,
86        position: [f32; 3],
87        color: [i16; 3],
88        alpha: i16,
89    ) -> Result<(), String> {
90        let mut command_c_data = DrawLineAndIconPathDrawerCommandData {
91            command_id,
92            position,
93            color,
94            alpha,
95        }
96        .c_data();
97
98        handle_command(
99            self.ai_id,
100            COMMAND_TO_ID_ENGINE,
101            -1,
102            CommandTopic::DrawerPathDrawLineAndIcon.into(),
103            &mut command_c_data,
104        )?;
105
106        Ok(())
107    }
108    pub fn finish(&self) -> Result<(), String> {
109        let mut command_c_data = FinishPathDrawerCommandData {
110            i_am_useless: false,
111        }
112        .c_data();
113
114        handle_command(
115            self.ai_id,
116            COMMAND_TO_ID_ENGINE,
117            -1,
118            CommandTopic::DrawerPathFinish.into(),
119            &mut command_c_data,
120        )?;
121
122        Ok(())
123    }
124    pub fn restart(&self, same_color: bool) -> Result<(), String> {
125        let mut command_c_data = RestartPathDrawerCommandData { same_color }.c_data();
126
127        handle_command(
128            self.ai_id,
129            COMMAND_TO_ID_ENGINE,
130            -1,
131            CommandTopic::DrawerPathRestart.into(),
132            &mut command_c_data,
133        )?;
134
135        Ok(())
136    }
137    pub fn start(&self, position: [f32; 3], color: [i16; 3], alpha: i16) -> Result<(), String> {
138        let mut command_c_data = StartPathDrawerCommandData {
139            position,
140            color,
141            alpha,
142        }
143        .c_data();
144
145        handle_command(
146            self.ai_id,
147            COMMAND_TO_ID_ENGINE,
148            -1,
149            CommandTopic::DrawerPathStart.into(),
150            &mut command_c_data,
151        )?;
152
153        Ok(())
154    }
155}