spring_ai_rs/ai_interface/callback/unit_def/
model.rs1use std::error::Error;
2
3use serde::{Deserialize, Serialize};
4
5use crate::get_callback;
6
7#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
8pub struct UnitModel {
9 pub ai_id: i32,
10 pub def_id: i32,
11}
12
13#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
14pub struct UnitModelAll {
15 pub height: f32,
16 pub radius: f32,
17}
18
19impl UnitModel {
20 pub fn height(&self) -> Result<f32, Box<dyn Error>> {
21 let get_model_height = get_callback!(self.ai_id, UnitDef_getHeight)?;
22 Ok(unsafe { get_model_height(self.ai_id, self.def_id) })
23 }
24
25 pub fn radius(&self) -> Result<f32, Box<dyn Error>> {
26 let get_model_radius = get_callback!(self.ai_id, UnitDef_getRadius)?;
27 Ok(unsafe { get_model_radius(self.ai_id, self.def_id) })
28 }
29
30 pub fn all(&self) -> Result<UnitModelAll, Box<dyn Error>> {
31 Ok(UnitModelAll {
32 height: self.height()?,
33 radius: self.radius()?,
34 })
35 }
36}