303 lines
8.9 KiB
Rust
303 lines
8.9 KiB
Rust
use bon::Builder;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
static VERSION: u64 = calculate_version(2, 0, 19, 173);
|
|
|
|
const fn calculate_version(major: u16, minor: u16, patch: u16, dev: u16) -> u64 {
|
|
((major as u64) << 48) | ((minor as u64) << 32) | ((patch as u64) << 16) | (dev as u64)
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum BlueprintString {
|
|
#[serde(rename = "blueprint_book")]
|
|
BlueprintBook(BlueprintBook),
|
|
#[serde(rename = "blueprint")]
|
|
Blueprint(Blueprint),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
|
|
pub struct BlueprintBook {
|
|
#[builder(skip = "blueprint-book".to_owned())]
|
|
item: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
label: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
label_color: Option<BlueprintColor>,
|
|
blueprints: Vec<BlueprintBookEntry>,
|
|
active_index: i32,
|
|
#[builder(skip = VERSION)]
|
|
version: u64,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintBookEntry {
|
|
#[serde(flatten)]
|
|
entry: BlueprintString,
|
|
index: u32,
|
|
}
|
|
|
|
impl BlueprintBookEntry {
|
|
pub fn new(entry: BlueprintString, index: u32) -> Self {
|
|
Self { entry, index }
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
|
|
pub struct Blueprint {
|
|
#[builder(skip = "blueprint".to_owned())]
|
|
item: String,
|
|
label: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
label_color: Option<BlueprintColor>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
entities: Vec<BlueprintEntity>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
tiles: Vec<BlueprintTile>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
icons: Vec<BlueprintIcon>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
schedules: Vec<serde_json::Value>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
stock_connections: Vec<BlueprintStockConnection>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
description: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
snap_to_grid: Option<BlueprintPosition>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
absolute_snapping: Option<bool>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
position_relative_to_grid: Option<BlueprintPosition>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[builder(default)]
|
|
wires: Vec<[u32; 4]>,
|
|
#[builder(skip = VERSION)]
|
|
version: u64,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
|
|
pub struct BlueprintStockConnection {
|
|
#[builder(start_fn)]
|
|
stock: u32,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
front: Option<u32>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
back: Option<u32>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
|
|
pub struct BlueprintEntity {
|
|
#[builder(start_fn)]
|
|
name: String,
|
|
#[builder(start_fn)]
|
|
pub entity_number: u32,
|
|
#[builder(start_fn)]
|
|
pub position: BlueprintPosition,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
direction: Option<u8>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
orientation: Option<f32>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
connections: Option<BlueprintConnection>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
neighbours: Option<Vec<u64>>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
control_behaviour: Option<()>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
items: Option<Vec<BlueprintItemRequest>>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
recipe: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
bar: Option<u64>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
inventory: Option<BlueprintInventory>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
infinity_settings: Option<()>,
|
|
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
|
underground_type: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
input_priority: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
output_priority: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
filter: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
filters: Option<Vec<BlueprintItemFilter>>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
filter_mode: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
override_stack_size: Option<u8>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
drop_position: Option<BlueprintPosition>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pickup_position: Option<BlueprintPosition>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
request_filters: Option<Vec<BlueprintLogisticFilter>>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
request_from_buffers: Option<bool>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
parameters: Option<BlueprintSpeakerParameter>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
alert_parameters: Option<BlueprintSpeakerAlertParameter>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
auto_launch: Option<bool>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
variation: Option<u8>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
color: Option<BlueprintColor>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
station: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
manuel_trains_limit: Option<u32>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
switch_state: Option<bool>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
tags: Option<serde_json::Value>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
quality: Option<String>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintItemRequest {
|
|
id: BlueprintItemID,
|
|
items: BlueprintItem,
|
|
}
|
|
|
|
impl BlueprintItemRequest {
|
|
pub fn new(id: BlueprintItemID, items: Vec<BlueprintInventoryLocation>) -> Self {
|
|
Self {
|
|
id,
|
|
items: BlueprintItem {
|
|
in_inventory: items,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Builder)]
|
|
pub struct BlueprintItemID {
|
|
#[builder(start_fn)]
|
|
name: String,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintItem {
|
|
in_inventory: Vec<BlueprintInventoryLocation>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintInventoryLocation {
|
|
count: u32,
|
|
inventory: u32,
|
|
stack: u32,
|
|
}
|
|
|
|
impl BlueprintInventoryLocation {
|
|
pub fn new(count: u32, inventory: u32, stack: u32) -> Self {
|
|
Self {
|
|
count,
|
|
inventory,
|
|
stack,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintInventory {
|
|
filters: Vec<BlueprintItemFilter>,
|
|
bar: u16,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintConnection {
|
|
#[serde(rename = "1")]
|
|
first: Option<BlueprintConnectionPoint>,
|
|
#[serde(rename = "2")]
|
|
second: Option<BlueprintConnectionPoint>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintConnectionPoint {
|
|
#[serde(default)]
|
|
red: Vec<BlueprintConnectionData>,
|
|
#[serde(default)]
|
|
green: Vec<BlueprintConnectionData>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
|
pub struct BlueprintConnectionData {
|
|
entity_id: u64,
|
|
circuit_id: Option<u64>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintItemFilter {
|
|
name: String,
|
|
index: u32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintLogisticFilter {
|
|
name: String,
|
|
index: u32,
|
|
count: u32,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintSpeakerParameter {
|
|
playback_volume: f64,
|
|
playback_globally: bool,
|
|
allow_polyphony: bool,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintSpeakerAlertParameter {
|
|
show_alert: bool,
|
|
show_on_map: bool,
|
|
icon_signal_id: BlueprintSignalID,
|
|
alert_message: String,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintSignalID {
|
|
name: String,
|
|
#[serde(rename = "type")]
|
|
signal_type: String,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
|
pub struct BlueprintPosition {
|
|
pub x: f64,
|
|
pub y: f64,
|
|
}
|
|
|
|
impl BlueprintPosition {
|
|
pub fn new(x: f64, y: f64) -> Self {
|
|
BlueprintPosition { x, y }
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintIcon {
|
|
index: u32,
|
|
signal: BlueprintSignalID,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintTile {
|
|
name: String,
|
|
position: BlueprintPosition,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct BlueprintColor {
|
|
r: f32,
|
|
g: f32,
|
|
b: f32,
|
|
a: f32,
|
|
}
|