Add component map

master
D4VID 1 month ago
parent d19d7cd94c
commit 3ff75d8d16

@ -11,11 +11,18 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "logicworld-subassembly" name = "logicworld-subassembly"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"binary-serialize-derive", "binary-serialize-derive",
"lazy_static",
"quaternion", "quaternion",
"vecmath", "vecmath",
] ]

@ -5,5 +5,6 @@ edition = "2021"
[dependencies] [dependencies]
binary-serialize-derive = { path = "../binary-serialize-derive" } binary-serialize-derive = { path = "../binary-serialize-derive" }
lazy_static = "1.5.0"
quaternion = "2.0.0" quaternion = "2.0.0"
vecmath = "1.0.0" vecmath = "1.0.0"

@ -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 {

@ -64,7 +64,7 @@ impl Output {
#[derive(BinarySerializable)] #[derive(BinarySerializable)]
pub struct ComponentIdMap { pub struct ComponentIdMap {
pub numeric_id: i16, pub numeric_id: u16,
pub text_id: String, pub text_id: String,
} }

Loading…
Cancel
Save