spring_ai_rs/ai_interface/callback/game_mod/
info.rs1use std::{error::Error, ffi::CStr};
2
3use crate::get_callback;
4
5#[derive(Debug, Copy, Clone)]
6pub struct GameModInfo {
7 pub ai_id: i32,
8}
9
10#[derive(Debug, Clone)]
11pub struct GameModInfoAll {
12 file_name: String,
13 hash: i32,
14 human_name: String,
15 short_name: String,
16 version: String,
17 mutator: String,
18 description: String,
19}
20
21impl GameModInfo {
22 pub fn file_name(&self) -> Result<String, Box<dyn Error>> {
23 let get_file_name = get_callback!(self.ai_id, Mod_getFileName)?;
24
25 Ok(String::from(
26 unsafe { CStr::from_ptr(get_file_name(self.ai_id)) }.to_str()?,
27 ))
28 }
29
30 pub fn hash(&self) -> Result<i32, Box<dyn Error>> {
31 let get_hash = get_callback!(self.ai_id, Mod_getHash)?;
32
33 Ok(unsafe { get_hash(self.ai_id) })
34 }
35
36 pub fn human_name(&self) -> Result<String, Box<dyn Error>> {
37 let get_human_name = get_callback!(self.ai_id, Mod_getHumanName)?;
38
39 Ok(String::from(
40 unsafe { CStr::from_ptr(get_human_name(self.ai_id)) }.to_str()?,
41 ))
42 }
43
44 pub fn short_name(&self) -> Result<String, Box<dyn Error>> {
45 let get_short_name = get_callback!(self.ai_id, Mod_getShortName)?;
46
47 Ok(String::from(
48 unsafe { CStr::from_ptr(get_short_name(self.ai_id)) }.to_str()?,
49 ))
50 }
51
52 pub fn version(&self) -> Result<String, Box<dyn Error>> {
53 let get_version = get_callback!(self.ai_id, Mod_getVersion)?;
54
55 Ok(String::from(
56 unsafe { CStr::from_ptr(get_version(self.ai_id)) }.to_str()?,
57 ))
58 }
59
60 pub fn mutator(&self) -> Result<String, Box<dyn Error>> {
61 let get_mutator = get_callback!(self.ai_id, Mod_getMutator)?;
62
63 Ok(String::from(
64 unsafe { CStr::from_ptr(get_mutator(self.ai_id)) }.to_str()?,
65 ))
66 }
67
68 pub fn description(&self) -> Result<String, Box<dyn Error>> {
69 let get_description = get_callback!(self.ai_id, Mod_getDescription)?;
70
71 Ok(String::from(
72 unsafe { CStr::from_ptr(get_description(self.ai_id)) }.to_str()?,
73 ))
74 }
75
76 pub fn all(&self) -> Result<GameModInfoAll, Box<dyn Error>> {
77 Ok(GameModInfoAll {
78 file_name: self.file_name()?,
79 hash: self.hash()?,
80 human_name: self.human_name()?,
81 short_name: self.short_name()?,
82 version: self.version()?,
83 mutator: self.mutator()?,
84 description: self.description()?,
85 })
86 }
87}