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 spring_ai_sys::COMMAND_TO_ID_ENGINE;

use crate::ai_interface::callback::{
    command::{
        command_data::{
            drawer::{AddNotificationDrawerCommandData, DrawUnitDrawerCommandData},
            CommandData,
        },
        command_topic::CommandTopic,
    },
    engine::handle_command,
    facing::Facing,
};

pub mod debug;
pub mod figure;
pub mod line;
pub mod path;
pub mod point;

pub struct Drawer {
    pub ai_id: i32,
}

impl Drawer {
    pub fn add_notification(
        &self,
        position: [f32; 3],
        color: [i16; 3],
        alpha: i16,
    ) -> Result<(), String> {
        let mut command_c_data = AddNotificationDrawerCommandData {
            position,
            color,
            alpha,
        }
        .c_data();

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::DrawerAddNotification.into(),
            &mut command_c_data,
        )?;

        Ok(())
    }

    pub fn draw_unit(
        &self,
        draw_unit_def_id: i32,
        position: [f32; 3],
        rotation: f32,
        lifetime: i32,
        team_id: i32,
        transparent: bool,
        draw_border: bool,
        facing: Facing,
    ) -> Result<(), String> {
        let mut command_c_data = DrawUnitDrawerCommandData {
            draw_unit_def_id,
            position,
            rotation,
            lifetime,
            team_id,
            transparent,
            draw_border,
            facing,
        }
        .c_data();

        handle_command(
            self.ai_id,
            COMMAND_TO_ID_ENGINE,
            -1,
            CommandTopic::DrawerDrawUnit.into(),
            &mut command_c_data,
        )?;

        Ok(())
    }
}