Update to official Blotter v5 format

This commit is contained in:
Adam Gausmann 2021-07-08 12:45:27 -05:00
parent 975a626c12
commit 50dea19207
2 changed files with 28 additions and 11 deletions

View file

@ -2,6 +2,6 @@
A Rust parser for the Blotter file format. A Rust parser for the Blotter file format.
Current version: [Blotter v5 Draft 0][spec] Current version: [Blotter v5][spec]
[spec]: https://gist.github.com/JimmyCushnie/7dae698c92a900f2e530668740c20ca2 [spec]: https://gist.github.com/JimmyCushnie/bebea37a21acbb6e669589967f9512a2

View file

@ -7,6 +7,7 @@ type ComponentId = LittleEndian<u16>;
type ComponentAddress = LittleEndian<u32>; type ComponentAddress = LittleEndian<u32>;
type Int = LittleEndian<i32>; type Int = LittleEndian<i32>;
type Float = LittleEndian<f32>; type Float = LittleEndian<f32>;
type Version = [Int; 4];
#[derive(Debug, Clone, Copy, PartialEq, Encode, Decode)] #[derive(Debug, Clone, Copy, PartialEq, Encode, Decode)]
#[declio(id_type = "u8")] #[declio(id_type = "u8")]
@ -21,10 +22,13 @@ enum SaveType {
pub struct BlotterFile { pub struct BlotterFile {
header: Header, header: Header,
save_version: u8, save_version: u8,
game_version: [Int; 4], game_version: Version,
save_type: SaveType, save_type: SaveType,
components_len: Int, components_len: Int,
wires_len: Int, wires_len: Int,
mods_len: Int,
#[declio(ctx = "Len(mods_len.0.try_into()?)")]
mods: Vec<Mod>,
component_ids_len: Int, component_ids_len: Int,
#[declio(ctx = "Len(component_ids_len.0.try_into()?)")] #[declio(ctx = "Len(component_ids_len.0.try_into()?)")]
component_ids: Vec<ComponentIdMapping>, component_ids: Vec<ComponentIdMapping>,
@ -52,6 +56,12 @@ struct Text {
value: String, value: String,
} }
#[derive(Debug, Encode, Decode)]
struct Mod {
mod_id: Text,
version: Version,
}
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]
struct ComponentIdMapping { struct ComponentIdMapping {
numeric_id: ComponentId, numeric_id: ComponentId,
@ -60,8 +70,6 @@ struct ComponentIdMapping {
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]
struct Input { struct Input {
#[declio(with = "zero_one")]
exclusive: bool,
circuit_state_id: Int, circuit_state_id: Int,
} }
@ -77,23 +85,32 @@ struct Component {
type_id: ComponentId, type_id: ComponentId,
position: [Float; 3], position: [Float; 3],
rotation: [Float; 4], rotation: [Float; 4],
inputs_len: u8, inputs_len: Int,
#[declio(ctx = "Len((*inputs_len).try_into()?)")] #[declio(ctx = "Len(inputs_len.0.try_into()?)")]
inputs: Vec<Input>, inputs: Vec<Input>,
outputs_len: u8, outputs_len: Int,
#[declio(ctx = "Len((*outputs_len).try_into()?)")] #[declio(ctx = "Len(outputs_len.0.try_into()?)")]
outputs: Vec<Output>, outputs: Vec<Output>,
custom_data_len: Int, custom_data_len: Int,
#[declio(ctx = "Len(custom_data_len.0.try_into()?)")] #[declio(ctx = "Len(len_or_neg1(*custom_data_len)?)")]
custom_data: Vec<u8>, custom_data: Vec<u8>,
} }
fn len_or_neg1(len: Int) -> Result<usize, std::num::TryFromIntError> {
// From the spec:
// > If the component has no custom data, -1 may be written instead of 0
match len.0 {
-1 => Ok(0),
other => other.try_into(),
}
}
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]
struct PegAddress { struct PegAddress {
#[declio(with = "zero_one")] #[declio(with = "zero_one")]
is_input: bool, is_input: bool,
component: ComponentAddress, component: ComponentAddress,
index: u8, index: Int,
} }
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]