dcso3/
dcs.rs

1/*
2Copyright 2024 Eric Stokes.
3
4This file is part of dcso3.
5
6dcso3 is free software: you can redistribute it and/or modify it under
7the terms of the MIT License.
8
9dcso3 is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE.
12*/
13
14use super::{as_tbl, coalition::Side, String};
15use crate::{wrapped_table, HooksLua, LuaEnv, Time};
16use anyhow::Result;
17use mlua::{prelude::*, Value};
18use serde_derive::Serialize;
19use std::ops::Deref;
20
21wrapped_table!(Dcs, None);
22
23impl<'lua> Dcs<'lua> {
24    pub fn singleton(lua: HooksLua<'lua>) -> Result<Self> {
25        let globals = lua.inner().globals();
26        Ok(globals.raw_get("DCS")?)
27    }
28
29    pub fn get_mission_name(&self) -> Result<String> {
30        Ok(self.t.call_function("getMissionName", ())?)
31    }
32
33    pub fn get_mission_filename(&self) -> Result<String> {
34        Ok(self.t.call_function("getMissionFilename", ())?)
35    }
36
37    pub fn get_mission_result(&self, side: Side) -> Result<i64> {
38        Ok(self.t.call_function("getMissionResult", side)?)
39    }
40
41    pub fn get_unit_property(&self, name: String) -> Result<Value<'lua>> {
42        Ok(self.t.call_function("getUnitProperty", name)?)
43    }
44
45    pub fn set_pause(&self, pause: bool) -> Result<()> {
46        Ok(self.t.call_function("setPause", pause)?)
47    }
48
49    pub fn get_pause(&self) -> Result<bool> {
50        Ok(self.t.call_function("getPause", ())?)
51    }
52
53    pub fn stop_mission(&self) -> Result<()> {
54        Ok(self.t.call_function("stopMission", ())?)
55    }
56
57    pub fn exit_process(&self) -> Result<()> {
58        Ok(self.t.call_function("exitProcess", ())?)
59    }
60
61    pub fn is_multiplayer(&self) -> Result<bool> {
62        Ok(self.t.call_function("isMultiplayer", ())?)
63    }
64
65    pub fn is_server(&self) -> Result<bool> {
66        Ok(self.t.call_function("isServer", ())?)
67    }
68
69    pub fn get_model_time(&self) -> Result<Time> {
70        Ok(self.t.call_function("getModelTime", ())?)
71    }
72
73    pub fn get_real_time(&self) -> Result<Time> {
74        Ok(self.t.call_function("getRealTime", ())?)
75    }
76
77    pub fn get_mission_options(&self) -> Result<LuaTable<'lua>> {
78        Ok(self.t.call_function("getMissionOptions", ())?)
79    }
80
81    pub fn get_available_coalitions(&self) -> Result<LuaTable<'lua>> {
82        Ok(self.t.call_function("getAvailableCoalitions", ())?)
83    }
84
85    pub fn get_available_slots(&self) -> Result<LuaTable<'lua>> {
86        Ok(self.t.call_function("getAvailableSlots", ())?)
87    }
88
89    pub fn get_current_mission(&self) -> Result<LuaTable<'lua>> {
90        Ok(self.t.call_function("getCurrentMission", ())?)
91    }
92}