|
|
@ -1,4 +1,6 @@
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
|
|
|
|
collections::HashMap,
|
|
|
|
fs::{self, File},
|
|
|
|
fs::{self, File},
|
|
|
|
io::{self, Write},
|
|
|
|
io::{self, Write},
|
|
|
|
path::Path,
|
|
|
|
path::Path,
|
|
|
@ -8,13 +10,23 @@ use crate::lw::{BinarySerializable, ComponentIdMap, ModVersion, Version};
|
|
|
|
|
|
|
|
|
|
|
|
pub mod lw;
|
|
|
|
pub mod lw;
|
|
|
|
|
|
|
|
|
|
|
|
// Convert component text id into numeric id
|
|
|
|
lazy_static! {
|
|
|
|
pub fn component_id(text_id: &str) -> i16 {
|
|
|
|
pub static ref COMPONENT_MAP: HashMap<&'static str, u16> = HashMap::from([
|
|
|
|
match text_id {
|
|
|
|
("MHG.CircuitBoard", 1),
|
|
|
|
"MHG.CircuitBoard" => 1,
|
|
|
|
("MHG.Peg", 2),
|
|
|
|
"MHG.AndGate" => 2,
|
|
|
|
("MHG.Inverter", 3),
|
|
|
|
_ => -1,
|
|
|
|
("MHG.AndGate", 4),
|
|
|
|
}
|
|
|
|
("MHG.XorGate", 5),
|
|
|
|
|
|
|
|
("MHG.DLatch", 6),
|
|
|
|
|
|
|
|
("MHG.Relay", 7),
|
|
|
|
|
|
|
|
("MHG.Buffer", 8),
|
|
|
|
|
|
|
|
("MHG.Buffer_WithOutput", 9),
|
|
|
|
|
|
|
|
("MHG.Delayer", 10),
|
|
|
|
|
|
|
|
("MHG.Socket", 11),
|
|
|
|
|
|
|
|
("MHG.ChubbySocket", 12),
|
|
|
|
|
|
|
|
("MHG.Mount", 13),
|
|
|
|
|
|
|
|
("MHG.PanelLabel", 14),
|
|
|
|
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum SaveType {
|
|
|
|
enum SaveType {
|
|
|
@ -67,16 +79,10 @@ fn write_subassembly_file(
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
mods.write_to(file)?;
|
|
|
|
mods.write_to(file)?;
|
|
|
|
|
|
|
|
|
|
|
|
let component_id_map = vec![
|
|
|
|
let component_id_map: Vec<ComponentIdMap> = COMPONENT_MAP.iter().map(|pair| ComponentIdMap {
|
|
|
|
ComponentIdMap {
|
|
|
|
text_id: pair.0.to_string(),
|
|
|
|
numeric_id: 1,
|
|
|
|
numeric_id: *pair.1,
|
|
|
|
text_id: "MHG.CircuitBoard".to_owned(),
|
|
|
|
}).collect();
|
|
|
|
},
|
|
|
|
|
|
|
|
ComponentIdMap {
|
|
|
|
|
|
|
|
numeric_id: 2,
|
|
|
|
|
|
|
|
text_id: "MHG.AndGate".to_owned(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
component_id_map.write_to(file)?;
|
|
|
|
component_id_map.write_to(file)?;
|
|
|
|
|
|
|
|
|
|
|
|
for component in components {
|
|
|
|
for component in components {
|
|
|
|