factorio-prototypes-json 0.1.0

Rust types that parse Factorio's Prototype JSON Format.
Documentation
//! A [`Define`] is an enumerated value that the game uses.
//!
//! Equivalent to the [defines](https://lua-api.factorio.com/latest/defines.html) page.

use serde::{Deserialize, Serialize};
use serde_json::Number;

use super::basic_members::BasicMembers;

/// One of the values of a [`Define`].
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct DefineValue {
    /// The name of the define value.
    pub name: String,

    /// The order of the member as shown in HTML.
    pub order: Number,

    /// The text description of the define value.
    pub description: String,
}

/// Defines can be recursive in nature, meaning one Define can have multiple sub-Defines that have the same structure. These are singled out as `subkeys` instead of `values`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Define {
    /// The basic fields of the type.
    #[serde(flatten)]
    pub basic: BasicMembers,

    /// The recursive full name of the define, ordered from parent to child.
    ///
    /// If the define is a subkey, this will be the full name of the parent define followed by the subkey name.
    /// This value is not present in the JSON format, but is added during the parsing process.
    #[serde(skip)]
    pub parents: Vec<String>,

    /// A member of the define.
    pub values: Option<Vec<DefineValue>>,

    /// A list of sub-defines.
    pub subkeys: Option<Vec<Define>>,
}