From 5cdfcfeca2b6521ae3c058f7d9d333568a28096d Mon Sep 17 00:00:00 2001 From: endernon Date: Tue, 24 Dec 2024 18:49:30 +0000 Subject: [PATCH] crafted support (1/?) (unfinished) --- Cargo.lock | 16 +++++++++++++--- Cargo.toml | 1 + config.json | 1 + src/errorfr/mod.rs | 6 +++++- src/main.rs | 8 +++----- src/structures/mod.rs | 25 ++++++++++++++++++++++++- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d264076..76df55e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,7 +227,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -594,6 +594,7 @@ dependencies = [ "serde", "serde_json", "thiserror", + "tribool", ] [[package]] @@ -912,7 +913,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1153,7 +1154,7 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1259,6 +1260,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tribool" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e8660361502033a51e119386b47fbb811e5706722f2e91ccf867aa6b2b09f90" +dependencies = [ + "serde", +] + [[package]] name = "try-lock" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index 2bd4b8c..d521a25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ reqwest = "0.12.9" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0.68" +tribool = { version = "0.3.0", features = ["serde"] } diff --git a/config.json b/config.json index e234b76..5035b44 100644 --- a/config.json +++ b/config.json @@ -4,6 +4,7 @@ "There are also some values you cannot increase beyond a limit." ], "name":"Singularity", + "item_type": "Gear", "shiny": { "key": "playersKilled", "value": 9223372036854775807 diff --git a/src/errorfr/mod.rs b/src/errorfr/mod.rs index d7885f9..c080996 100644 --- a/src/errorfr/mod.rs +++ b/src/errorfr/mod.rs @@ -25,5 +25,9 @@ pub enum Errorfr { /// shiny data json is corrupt #[error("Error 6: shiny_stats.json is corrupt.")] - ShinyJsonCorrupt + ShinyJsonCorrupt, + + /// + #[error("Error 7: Item Type is missing from json (add an \"item_type\" field")] + ItemTypeMissing } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 19494c5..3f1310e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,15 +83,16 @@ fn cook() -> Result<(), Errorfr> { .unwrap(); // ENCODE: TypeData - TypeData(ItemType::Gear) + TypeData(ItemType::from(json_config.item_type)) .encode(ver, &mut out) - .unwrap(); + .map_err(|_| Errorfr::ItemTypeMissing)?; // ENCODE: NameData NameData(String::from(format!("{}", json_config.name.trim()))) .encode(ver, &mut out) .unwrap(); + // json identification data handling let mut idvec = Vec::new(); for eachid in json_config.ids { @@ -162,9 +163,6 @@ fn cook() -> Result<(), Errorfr> { }; - - - } if debug_mode { dbg!(&powdervec); diff --git a/src/structures/mod.rs b/src/structures/mod.rs index 37ee7f0..1ea9eaa 100644 --- a/src/structures/mod.rs +++ b/src/structures/mod.rs @@ -1,3 +1,4 @@ +use idmangler_lib::types::ItemType; use serde::Deserialize; // structs #[derive(Deserialize)] @@ -16,7 +17,7 @@ pub struct Identificationer { pub struct Jsonconfig { pub debug: Option, pub name: String, - pub crafted: bool, + pub item_type: ItemTypeDeser, pub shiny: Option, pub ids: Vec, pub powder_limit: u8, @@ -34,3 +35,25 @@ pub struct Shinyjson { pub key: String, pub value: i64, } + +// I had to clone this and add Deserialize because the original idmangler_lib::types::ItemType does not +#[repr(u8)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug, Deserialize)] +pub enum ItemTypeDeser { + Gear = 0, + Tome = 1, + Charm = 2, + CraftedGear = 3, + CraftedConsu = 4, +} +impl From for ItemType { + fn from(value: ItemTypeDeser) -> ItemType { + match value { + ItemTypeDeser::Gear => ItemType::Gear, + ItemTypeDeser::Tome => ItemType::Tome, + ItemTypeDeser::Charm => ItemType::Charm, + ItemTypeDeser::CraftedConsu => ItemType::CraftedConsu, + ItemTypeDeser::CraftedGear => ItemType::CraftedGear + } + } +} \ No newline at end of file