Add v5->v6 migration/conversion
This commit is contained in:
parent
2705447574
commit
070276a2f5
4 changed files with 45 additions and 48 deletions
1
src/convert/mod.rs
Normal file
1
src/convert/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mod v5v6;
|
||||
39
src/convert/v5v6.rs
Normal file
39
src/convert/v5v6.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use crate::{v5, v6};
|
||||
|
||||
impl From<v5::BlotterFile> 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<v5::Component> 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,
|
||||
]
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
mod convert;
|
||||
pub mod error;
|
||||
pub(crate) mod io;
|
||||
pub mod v5;
|
||||
|
|
|
|||
52
src/v6.rs
52
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<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[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<u8> },
|
||||
SubassemblyFormat { on_states: Vec<i32> },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BlotterFile {
|
||||
pub game_version: [i32; 4],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue