Replace u8 with bool/zero_one and add SaveType enum
This commit is contained in:
parent
67beb6d062
commit
43a6170eb8
1 changed files with 18 additions and 10 deletions
28
src/lib.rs
28
src/lib.rs
|
|
@ -1,22 +1,28 @@
|
||||||
use declio::ctx::Len;
|
use declio::ctx::Len;
|
||||||
use declio::util::{magic_bytes, LittleEndian};
|
use declio::util::{magic_bytes, zero_one, LittleEndian};
|
||||||
use declio::{Decode, Encode};
|
use declio::{Decode, Encode};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
const WORLD_SAVE_TYPE: u8 = 1;
|
|
||||||
const SUBASSEMBLY_SAVE_TYPE: u8 = 2;
|
|
||||||
|
|
||||||
type ComponentId = LittleEndian<u16>;
|
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>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
|
#[declio(id_type = "u8")]
|
||||||
|
enum SaveType {
|
||||||
|
#[declio(id = "1")]
|
||||||
|
World,
|
||||||
|
#[declio(id = "2")]
|
||||||
|
Subassembly,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
#[derive(Debug, Encode, Decode)]
|
||||||
pub struct BlotterFile {
|
pub struct BlotterFile {
|
||||||
header: Header,
|
header: Header,
|
||||||
save_version: u8,
|
save_version: u8,
|
||||||
game_version: [Int; 4],
|
game_version: [Int; 4],
|
||||||
save_type: u8,
|
save_type: SaveType,
|
||||||
components_len: Int,
|
components_len: Int,
|
||||||
wires_len: Int,
|
wires_len: Int,
|
||||||
component_ids_len: Int,
|
component_ids_len: Int,
|
||||||
|
|
@ -54,7 +60,8 @@ struct ComponentIdMapping {
|
||||||
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
#[derive(Debug, Encode, Decode)]
|
||||||
struct Input {
|
struct Input {
|
||||||
exclusive: u8,
|
#[declio(with = "zero_one")]
|
||||||
|
exclusive: bool,
|
||||||
circuit_state_id: Int,
|
circuit_state_id: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +90,8 @@ struct Component {
|
||||||
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
#[derive(Debug, Encode, Decode)]
|
||||||
struct PegAddress {
|
struct PegAddress {
|
||||||
is_input: u8,
|
#[declio(with = "zero_one")]
|
||||||
|
is_input: bool,
|
||||||
component: ComponentAddress,
|
component: ComponentAddress,
|
||||||
index: u8,
|
index: u8,
|
||||||
}
|
}
|
||||||
|
|
@ -97,15 +105,15 @@ struct Wire {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
#[derive(Debug, Encode, Decode)]
|
||||||
#[declio(ctx = "save_type: u8", id_expr = "save_type")]
|
#[declio(ctx = "save_type: SaveType", id_expr = "save_type")]
|
||||||
enum CircuitStates {
|
enum CircuitStates {
|
||||||
#[declio(id = "WORLD_SAVE_TYPE")]
|
#[declio(id = "SaveType::World")]
|
||||||
WorldFormat {
|
WorldFormat {
|
||||||
len: Int,
|
len: Int,
|
||||||
#[declio(ctx = "Len(len.0.try_into()?)")]
|
#[declio(ctx = "Len(len.0.try_into()?)")]
|
||||||
circuit_states: Vec<u8>,
|
circuit_states: Vec<u8>,
|
||||||
},
|
},
|
||||||
#[declio(id = "SUBASSEMBLY_SAVE_TYPE")]
|
#[declio(id = "SaveType::Subassembly")]
|
||||||
SubassemblyFormat {
|
SubassemblyFormat {
|
||||||
len: Int,
|
len: Int,
|
||||||
#[declio(ctx = "Len(len.0.try_into()?)")]
|
#[declio(ctx = "Len(len.0.try_into()?)")]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue