Skip to main content

factorio_api/
prototypes.rs

1//! Hand-written data-stage companions and helpers for generated prototypes.
2//!
3//! Generated stubs for every Factorio typename (~260).
4
5include!(concat!(env!("OUT_DIR"), "/prototypes_gen.rs"));
6
7/// RGBA color for fluid / graphics tables (`{r, g, b, a}`).
8#[derive(Debug, Clone, Copy, PartialEq, Default)]
9pub struct Color {
10    pub r: f64,
11    pub g: f64,
12    pub b: f64,
13    pub a: Option<f64>,
14}
15
16/// Axis-aligned box as two corners (`{{left_top}, {right_bottom}}` in Lua).
17#[derive(Debug, Clone, Copy, PartialEq, Default)]
18pub struct BoundingBox {
19    pub left_top_x: f64,
20    pub left_top_y: f64,
21    pub right_bottom_x: f64,
22    pub right_bottom_y: f64,
23}
24
25/// Simplified entity energy source (`type` + optional priority / buffer fields).
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
27pub struct EnergySource {
28    /// Factorio energy source type (e.g. `"electric"`, `"burner"`, `"void"`).
29    pub r#type: &'static str,
30    /// Electric usage priority (e.g. `"secondary-input"`).
31    pub usage_priority: Option<&'static str>,
32}
33
34/// Simplified minable properties for placeable entities.
35#[derive(Debug, Clone, Copy, PartialEq, Default)]
36pub struct MinableProperties {
37    pub mining_time: f64,
38    pub result: Option<&'static str>,
39}
40
41/// Item or fluid ingredient for a [`Recipe`].
42///
43/// Factorio 2.0 requires `{type, name, amount}`. Set [`Self::fluid`] to emit
44/// `type = "fluid"`; otherwise `type = "item"` is injected.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
46pub struct RecipeIngredient {
47    /// Ingredient prototype name.
48    pub name: &'static str,
49    /// Count (items) or amount (fluids).
50    pub amount: i64,
51    /// When true, Lua `type = "fluid"`; otherwise `"item"`.
52    pub fluid: bool,
53}
54
55/// Item product for a [`Recipe`] (`type = "item"` injected).
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57pub struct RecipeProduct {
58    /// Result item prototype name.
59    pub name: &'static str,
60    /// Item count produced.
61    pub amount: i64,
62}
63
64/// Science-pack entry for a [`TechnologyUnit`].
65///
66/// Emitted as a Factorio research ingredient tuple `{ "pack-name", amount }`.
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
68pub struct TechnologyUnitIngredient {
69    /// Tool / science-pack item name (e.g. `"automation-science-pack"`).
70    pub name: &'static str,
71    /// Count consumed per research unit.
72    pub amount: i64,
73}
74
75/// Research cost block for a [`Technology`] (`unit = { count, time, ingredients }`).
76#[derive(Debug, Clone, Copy, PartialEq, Default)]
77pub struct TechnologyUnit {
78    /// How many lab cycles are required.
79    pub count: i64,
80    /// Seconds per cycle.
81    pub time: f64,
82    /// Science packs per cycle.
83    pub ingredients: &'static [TechnologyUnitIngredient],
84}
85
86/// Unlock-recipe modifier (`type = "unlock-recipe"` injected).
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88pub struct UnlockRecipeEffect {
89    /// Recipe prototype name unlocked when the technology is researched.
90    pub recipe: &'static str,
91}