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
84
85
use std::ffi::CString;

use spring_ai_sys::COMMAND_TO_ID_ENGINE;

use crate::ai_interface::{
    callback::{
        command::{
            command_data::{
                other::{PauseCommandData, SetLastPosMessageCommandData},
                CommandData, EmptyCommandData,
            },
            command_topic::CommandTopic,
        },
        engine::handle_command,
    },
    AIInterface,
};

impl AIInterface {
    pub fn set_last_message_position(&self, position: [f32; 3]) -> Result<(), &'static str> {
        let mut command_data = SetLastPosMessageCommandData { position };

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::SetLastPOSMessage.into(),
            &mut command_data.c_data(),
        )
    }

    pub fn pause<S>(&self, enable: bool, reason: S) -> Result<(), &'static str>
    where
        S: Into<Vec<u8>>,
    {
        let mut command_data = PauseCommandData {
            enable,
            reason: CString::new(reason).unwrap(),
        };

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::Pause.into(),
            &mut command_data.c_data(),
        )
    }

    pub fn null(&self) -> Result<(), &'static str> {
        let mut command_data = EmptyCommandData {};

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::Null.into(),
            &mut command_data.c_data(),
        )
    }

    pub fn unused0(&self) -> Result<(), &'static str> {
        let mut command_data = EmptyCommandData {};

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::Unused0.into(),
            &mut command_data.c_data(),
        )
    }

    pub fn unused1(&self) -> Result<(), &'static str> {
        let mut command_data = EmptyCommandData {};

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::Unused1.into(),
            &mut command_data.c_data(),
        )
    }
}