Skip to main content

factorio_api/
lib.rs

1//! Generated Factorio runtime API bindings.
2//!
3//! These types exist for Rust type-checking and IDE support. Mod code is
4//! transpiled to Lua and never executes these stub implementations.
5
6#![allow(
7    dead_code,
8    unused_imports,
9    unused_variables,
10    non_upper_case_globals,
11    clippy::all,
12    clippy::pedantic,
13    clippy::nursery
14)]
15
16/// Marker trait for autogenerated Factorio API types.
17/// Do not implement this trait manually.
18pub trait LuaObject {}
19
20/// Opaque placeholder for complex Factorio Lua API values.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
22pub struct LuaAny;
23
24// Primitive types usable as LuaAny positions via `.into()`.
25impl<'a> From<&'a str> for LuaAny {
26    fn from(_: &'a str) -> Self {
27        LuaAny
28    }
29}
30impl From<String> for LuaAny {
31    fn from(_: String) -> Self {
32        LuaAny
33    }
34}
35impl From<bool> for LuaAny {
36    fn from(_: bool) -> Self {
37        LuaAny
38    }
39}
40impl From<u8> for LuaAny {
41    fn from(_: u8) -> Self {
42        LuaAny
43    }
44}
45impl From<u16> for LuaAny {
46    fn from(_: u16) -> Self {
47        LuaAny
48    }
49}
50impl From<u32> for LuaAny {
51    fn from(_: u32) -> Self {
52        LuaAny
53    }
54}
55impl From<u64> for LuaAny {
56    fn from(_: u64) -> Self {
57        LuaAny
58    }
59}
60impl From<i8> for LuaAny {
61    fn from(_: i8) -> Self {
62        LuaAny
63    }
64}
65impl From<i16> for LuaAny {
66    fn from(_: i16) -> Self {
67        LuaAny
68    }
69}
70impl From<i32> for LuaAny {
71    fn from(_: i32) -> Self {
72        LuaAny
73    }
74}
75impl From<i64> for LuaAny {
76    fn from(_: i64) -> Self {
77        LuaAny
78    }
79}
80impl From<f32> for LuaAny {
81    fn from(_: f32) -> Self {
82        LuaAny
83    }
84}
85impl From<f64> for LuaAny {
86    fn from(_: f64) -> Self {
87        LuaAny
88    }
89}
90impl From<usize> for LuaAny {
91    fn from(_: usize) -> Self {
92        LuaAny
93    }
94}
95
96// Concept types usable as LuaAny positions.
97impl From<crate::concepts::MapPosition> for LuaAny {
98    fn from(_: crate::concepts::MapPosition) -> Self {
99        LuaAny
100    }
101}
102impl From<crate::concepts::BoundingBox> for LuaAny {
103    fn from(_: crate::concepts::BoundingBox) -> Self {
104        LuaAny
105    }
106}
107impl From<crate::concepts::Color> for LuaAny {
108    fn from(_: crate::concepts::Color) -> Self {
109        LuaAny
110    }
111}
112
113impl std::ops::Index<&str> for LuaAny {
114    type Output = crate::settings::ModSettingValue;
115    fn index(&self, _key: &str) -> &Self::Output {
116        &crate::settings::UNIT_MOD_SETTING
117    }
118}
119
120/// Common "virtual fields" on `LuaAny` values.
121impl LuaAny {
122    pub fn x(self) -> f64 {
123        0.0
124    }
125    pub fn y(self) -> f64 {
126        0.0
127    }
128    pub fn left_top(self) -> LuaAny {
129        LuaAny
130    }
131    pub fn right_bottom(self) -> LuaAny {
132        LuaAny
133    }
134    pub fn value(self) -> LuaAny {
135        LuaAny
136    }
137}
138
139/// Marker trait for types that can be used as Factorio mod setting values.
140pub trait SettingValue: Copy + 'static {
141    const STUB: Self;
142}
143
144impl SettingValue for bool {
145    const STUB: Self = false;
146}
147impl SettingValue for u8 {
148    const STUB: Self = 0;
149}
150impl SettingValue for u16 {
151    const STUB: Self = 0;
152}
153impl SettingValue for u32 {
154    const STUB: Self = 0;
155}
156impl SettingValue for u64 {
157    const STUB: Self = 0;
158}
159impl SettingValue for usize {
160    const STUB: Self = 0;
161}
162impl SettingValue for i8 {
163    const STUB: Self = 0;
164}
165impl SettingValue for i16 {
166    const STUB: Self = 0;
167}
168impl SettingValue for i32 {
169    const STUB: Self = 0;
170}
171impl SettingValue for i64 {
172    const STUB: Self = 0;
173}
174impl SettingValue for f32 {
175    const STUB: Self = 0.0;
176}
177impl SettingValue for f64 {
178    const STUB: Self = 0.0;
179}
180impl SettingValue for &'static str {
181    const STUB: Self = "";
182}
183
184impl LuaAny {
185    /// Read a typed mod setting value by name.
186    ///
187    /// # Example
188    /// ```ignore
189    /// const CASUAL_MODE: bool = settings.startup.get::<bool>("ms-casual-mode");
190    /// const SPAWN_RADIUS: i64 = settings.startup.get::<i64>("ms-spawn-radius");
191    /// ```
192    pub const fn get<T: SettingValue>(&self, _key: &str) -> T {
193        T::STUB
194    }
195}
196
197include!(concat!(env!("OUT_DIR"), "/mod.rs"));
198
199pub mod settings;
200
201pub use event_filters::{EventFilterEntry, FilterMethodSpec, filter_method_spec};
202pub use map::{event_filter_type, event_type_to_name};
203pub use unions::literal_enum_variant_str;
204
205pub mod prelude {
206    pub use crate::SettingValue;
207    pub use crate::concepts::*;
208    pub use crate::event_data::*;
209    pub use crate::event_filters::*;
210    pub use crate::event_type_to_name;
211    pub use crate::events::*;
212    pub use crate::globals::*;
213    pub use crate::settings::{
214        BoolSetting, DoubleSetting, IntSetting, ModSettingValue, StringSetting, data, settings,
215    };
216    pub use crate::unions::*;
217}