Initial commit

This commit is contained in:
hal8174 2023-12-06 21:25:03 +01:00
commit 7d47a10acf
18 changed files with 1545 additions and 0 deletions

36
src/blueprint/mod.rs Normal file
View file

@ -0,0 +1,36 @@
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use std::io::Cursor;
use std::io::Read;
pub mod structs;
pub use structs::*;
pub fn decode(s: &str) -> String {
let raw = s.as_bytes();
assert!(raw[0] == b'0');
let u = STANDARD.decode(&raw[1..]).unwrap();
let mut o = String::new();
flate2::bufread::ZlibDecoder::new(Cursor::new(u))
.read_to_string(&mut o)
.unwrap();
o
}
pub fn encode(s: &str) -> String {
let mut u = Vec::new();
flate2::bufread::ZlibEncoder::new(Cursor::new(s), flate2::Compression::new(9))
.read_to_end(&mut u)
.unwrap();
let mut o = String::from("0");
STANDARD.encode_string(u, &mut o);
o
}

196
src/blueprint/structs.rs Normal file
View file

@ -0,0 +1,196 @@
use std::collections::HashMap;
use serde::Deserialize;
use serde::Serialize;
#[derive(Serialize, Deserialize, Debug)]
pub enum BlueprintString {
#[serde(rename = "blueprint_book")]
BlueprintBook(BlueprintBook),
#[serde(rename = "blueprint")]
Blueprint(Blueprint),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintBook {
item: String,
label: Option<String>,
label_color: Option<BlueprintColor>,
blueprints: Vec<BlueprintBookEntry>,
active_index: i32,
version: u64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintBookEntry {
#[serde(flatten)]
entry: BlueprintString,
index: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Blueprint {
item: String,
label: Option<String>,
label_color: Option<BlueprintColor>,
#[serde(default)]
entities: Vec<BlueprintEntity>,
#[serde(default)]
tiles: Vec<BlueprintTile>,
#[serde(default)]
icons: Vec<BlueprintIcon>,
#[serde(default)]
schedules: Vec<BlueprintSchedule>,
description: Option<String>,
snap_to_grid: Option<BlueprintPosition>,
absolute_snapping: Option<bool>,
position_relative_to_grid: Option<BlueprintPosition>,
version: u64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintEntity {
entity_number: u64,
name: String,
position: BlueprintPosition,
direciton: Option<u8>,
connections: Option<BlueprintConnection>,
neighbours: Option<Vec<u64>>,
control_behaviour: Option<()>,
items: Option<HashMap<String, u32>>,
recipe: Option<String>,
bar: Option<u64>,
inventory: Option<BlueprintInventory>,
infinity_settings: Option<()>,
#[serde(rename = "type")]
underground_type: Option<String>,
input_priority: Option<String>,
output_priority: Option<String>,
filter: Option<String>,
filters: Option<Vec<BlueprintItemFilter>>,
filter_mode: Option<String>,
override_stack_size: Option<u8>,
drop_position: Option<BlueprintPosition>,
pickup_position: Option<BlueprintPosition>,
request_filters: Option<Vec<BlueprintLogisticFilter>>,
request_from_buffers: Option<bool>,
parameters: Option<BlueprintSpeakerParameter>,
alert_parameters: Option<BlueprintSpeakerAlertParameter>,
auto_launch: Option<bool>,
variation: Option<u8>,
color: Option<BlueprintColor>,
station: Option<String>,
manuel_trains_limit: Option<u32>,
switch_state: Option<bool>,
tags: Option<serde_json::Value>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintInventory {
filters: Vec<BlueprintItemFilter>,
bar: u16,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintConnection {
#[serde(rename = "1")]
first: Option<BlueprintConnectionPoint>,
#[serde(rename = "2")]
second: Option<BlueprintConnectionPoint>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintConnectionPoint {
#[serde(default)]
red: Vec<BlueprintConnectionData>,
#[serde(default)]
green: Vec<BlueprintConnectionData>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintConnectionData {
entity_id: u64,
circuit_id: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintItemFilter {
name: String,
index: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintLogisticFilter {
name: String,
index: u32,
count: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintSpeakerParameter {
playback_volume: f64,
playback_globally: bool,
allow_polyphony: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintSpeakerAlertParameter {
show_alert: bool,
show_on_map: bool,
icon_signal_id: BlueprintSignalID,
alert_message: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintSignalID {
name: String,
#[serde(rename = "type")]
signal_type: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintPosition {
x: f64,
y: f64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintIcon {
index: u32,
signal: BlueprintSignalID,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintSchedule {
schedule: Vec<BlueprintScheduleRecord>,
locomotives: Vec<u64>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintScheduleRecord {
station: String,
wait_conditions: Vec<BlueprintWaitCondition>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintWaitCondition {
#[serde(rename = "type")]
condition_type: String,
compare_type: String,
ticks: Option<u64>,
condition: Option<()>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintTile {
name: String,
position: BlueprintPosition,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlueprintColor {
r: f32,
g: f32,
b: f32,
a: f32,
}