diff --git a/src/convert/mod.rs b/src/convert/mod.rs new file mode 100644 index 0000000..795cd03 --- /dev/null +++ b/src/convert/mod.rs @@ -0,0 +1 @@ +mod v5v6; diff --git a/src/convert/v5v6.rs b/src/convert/v5v6.rs new file mode 100644 index 0000000..9b5c964 --- /dev/null +++ b/src/convert/v5v6.rs @@ -0,0 +1,39 @@ +use crate::{v5, v6}; + +impl From for v6::BlotterFile { + fn from(file: v5::BlotterFile) -> Self { + Self { + game_version: file.game_version, + save_type: file.save_type, + mods: file.mods, + component_types: file.component_types, + components: file.components.into_iter().map(Into::into).collect(), + wires: file.wires, + circuit_states: file.circuit_states, + } + } +} + +impl From for v6::Component { + fn from(component: v5::Component) -> Self { + Self { + address: component.address, + parent: component.parent, + type_id: component.type_id, + position: floating_to_fixed_position(component.position), + rotation: component.rotation, + inputs: component.inputs, + outputs: component.outputs, + custom_data: component.custom_data, + } + } +} + +fn floating_to_fixed_position([x, y, z]: [f32; 3]) -> [i32; 3] { + const CONVERSION_FACTOR: f32 = 1000.0; + [ + (x * CONVERSION_FACTOR) as i32, + (y * CONVERSION_FACTOR) as i32, + (z * CONVERSION_FACTOR) as i32, + ] +} diff --git a/src/lib.rs b/src/lib.rs index b1e0fd6..27f63a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +mod convert; pub mod error; pub(crate) mod io; pub mod v5; diff --git a/src/v6.rs b/src/v6.rs index 3643691..b332793 100644 --- a/src/v6.rs +++ b/src/v6.rs @@ -4,33 +4,10 @@ use std::io::{Read, Write}; pub const SAVE_VERSION: u8 = 6; -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum SaveType { - World, - Subassembly, -} - -#[derive(Debug)] -pub struct ModInfo { - pub mod_id: String, - pub mod_version: [i32; 4], -} - -#[derive(Debug)] -pub struct ComponentType { - pub numeric_id: u16, - pub text_id: String, -} - -#[derive(Debug)] -pub struct Input { - pub circuit_state_id: i32, -} - -#[derive(Debug)] -pub struct Output { - pub circuit_state_id: i32, -} +// Unchanged from previous version: +pub use crate::v5::{ + CircuitStates, ComponentType, Input, ModInfo, Output, PegAddress, SaveType, Wire, +}; #[derive(Debug)] pub struct Component { @@ -44,27 +21,6 @@ pub struct Component { pub custom_data: Option>, } -#[derive(Debug)] -pub struct PegAddress { - pub is_input: bool, - pub component_address: u32, - pub peg_index: i32, -} - -#[derive(Debug)] -pub struct Wire { - pub start_peg: PegAddress, - pub end_peg: PegAddress, - pub circuit_state_id: i32, - pub rotation: f32, -} - -#[derive(Debug)] -pub enum CircuitStates { - WorldFormat { circuit_states: Vec }, - SubassemblyFormat { on_states: Vec }, -} - #[derive(Debug)] pub struct BlotterFile { pub game_version: [i32; 4],