factorio-api 0.1.1

Generated Factorio runtime API bindings for factorio-rs
Documentation
//! Generated Factorio runtime API bindings.
//!
//! These types exist for Rust type-checking and IDE support. Mod code is
//! transpiled to Lua and never executes these stub implementations.

#![allow(
    dead_code,
    unused_imports,
    unused_variables,
    non_upper_case_globals,
    clippy::all,
    clippy::pedantic,
    clippy::nursery
)]

/// Marker trait for autogenerated Factorio API types.
/// Do not implement this trait manually.
pub trait LuaObject {}

/// Opaque placeholder for complex Factorio Lua API values.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct LuaAny;

// Primitive types usable as LuaAny positions via `.into()`.
impl<'a> From<&'a str> for LuaAny {
    fn from(_: &'a str) -> Self {
        LuaAny
    }
}
impl From<String> for LuaAny {
    fn from(_: String) -> Self {
        LuaAny
    }
}
impl From<bool> for LuaAny {
    fn from(_: bool) -> Self {
        LuaAny
    }
}
impl From<u8> for LuaAny {
    fn from(_: u8) -> Self {
        LuaAny
    }
}
impl From<u16> for LuaAny {
    fn from(_: u16) -> Self {
        LuaAny
    }
}
impl From<u32> for LuaAny {
    fn from(_: u32) -> Self {
        LuaAny
    }
}
impl From<u64> for LuaAny {
    fn from(_: u64) -> Self {
        LuaAny
    }
}
impl From<i8> for LuaAny {
    fn from(_: i8) -> Self {
        LuaAny
    }
}
impl From<i16> for LuaAny {
    fn from(_: i16) -> Self {
        LuaAny
    }
}
impl From<i32> for LuaAny {
    fn from(_: i32) -> Self {
        LuaAny
    }
}
impl From<i64> for LuaAny {
    fn from(_: i64) -> Self {
        LuaAny
    }
}
impl From<f32> for LuaAny {
    fn from(_: f32) -> Self {
        LuaAny
    }
}
impl From<f64> for LuaAny {
    fn from(_: f64) -> Self {
        LuaAny
    }
}
impl From<usize> for LuaAny {
    fn from(_: usize) -> Self {
        LuaAny
    }
}

// Concept types usable as LuaAny positions.
impl From<crate::concepts::MapPosition> for LuaAny {
    fn from(_: crate::concepts::MapPosition) -> Self {
        LuaAny
    }
}
impl From<crate::concepts::BoundingBox> for LuaAny {
    fn from(_: crate::concepts::BoundingBox) -> Self {
        LuaAny
    }
}
impl From<crate::concepts::Color> for LuaAny {
    fn from(_: crate::concepts::Color) -> Self {
        LuaAny
    }
}

impl std::ops::Index<&str> for LuaAny {
    type Output = crate::settings::ModSettingValue;
    fn index(&self, _key: &str) -> &Self::Output {
        &crate::settings::UNIT_MOD_SETTING
    }
}

/// Common "virtual fields" on `LuaAny` values.
impl LuaAny {
    pub fn x(self) -> f64 {
        0.0
    }
    pub fn y(self) -> f64 {
        0.0
    }
    pub fn left_top(self) -> LuaAny {
        LuaAny
    }
    pub fn right_bottom(self) -> LuaAny {
        LuaAny
    }
    pub fn value(self) -> LuaAny {
        LuaAny
    }
}

/// Marker trait for types that can be used as Factorio mod setting values.
pub trait SettingValue: Copy + 'static {
    const STUB: Self;
}

impl SettingValue for bool {
    const STUB: Self = false;
}
impl SettingValue for u8 {
    const STUB: Self = 0;
}
impl SettingValue for u16 {
    const STUB: Self = 0;
}
impl SettingValue for u32 {
    const STUB: Self = 0;
}
impl SettingValue for u64 {
    const STUB: Self = 0;
}
impl SettingValue for usize {
    const STUB: Self = 0;
}
impl SettingValue for i8 {
    const STUB: Self = 0;
}
impl SettingValue for i16 {
    const STUB: Self = 0;
}
impl SettingValue for i32 {
    const STUB: Self = 0;
}
impl SettingValue for i64 {
    const STUB: Self = 0;
}
impl SettingValue for f32 {
    const STUB: Self = 0.0;
}
impl SettingValue for f64 {
    const STUB: Self = 0.0;
}
impl SettingValue for &'static str {
    const STUB: Self = "";
}

impl LuaAny {
    /// Read a typed mod setting value by name.
    ///
    /// # Example
    /// ```ignore
    /// const CASUAL_MODE: bool = settings.startup.get::<bool>("ms-casual-mode");
    /// const SPAWN_RADIUS: i64 = settings.startup.get::<i64>("ms-spawn-radius");
    /// ```
    pub const fn get<T: SettingValue>(&self, _key: &str) -> T {
        T::STUB
    }
}

include!(concat!(env!("OUT_DIR"), "/mod.rs"));

pub mod settings;

pub use event_filters::{EventFilterEntry, FilterMethodSpec, filter_method_spec};
pub use map::{event_filter_type, event_type_to_name};
pub use unions::literal_enum_variant_str;

pub mod prelude {
    pub use crate::SettingValue;
    pub use crate::concepts::*;
    pub use crate::event_data::*;
    pub use crate::event_filters::*;
    pub use crate::event_type_to_name;
    pub use crate::events::*;
    pub use crate::globals::*;
    pub use crate::settings::{
        BoolSetting, DoubleSetting, IntSetting, ModSettingValue, StringSetting, data, settings,
    };
    pub use crate::unions::*;
}