crafted support (1/?) (unfinished)

This commit is contained in:
endernon 2024-12-24 18:49:30 +00:00
parent a2b82ccf22
commit 5cdfcfeca2
6 changed files with 47 additions and 10 deletions

16
Cargo.lock generated
View file

@ -227,7 +227,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -594,6 +594,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tribool",
] ]
[[package]] [[package]]
@ -912,7 +913,7 @@ dependencies = [
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1153,7 +1154,7 @@ dependencies = [
"fastrand", "fastrand",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1259,6 +1260,15 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "tribool"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e8660361502033a51e119386b47fbb811e5706722f2e91ccf867aa6b2b09f90"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"

View file

@ -15,3 +15,4 @@ reqwest = "0.12.9"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0.68" thiserror = "1.0.68"
tribool = { version = "0.3.0", features = ["serde"] }

View file

@ -4,6 +4,7 @@
"There are also some values you cannot increase beyond a limit." "There are also some values you cannot increase beyond a limit."
], ],
"name":"Singularity", "name":"Singularity",
"item_type": "Gear",
"shiny": { "shiny": {
"key": "playersKilled", "key": "playersKilled",
"value": 9223372036854775807 "value": 9223372036854775807

View file

@ -25,5 +25,9 @@ pub enum Errorfr {
/// shiny data json is corrupt /// shiny data json is corrupt
#[error("Error 6: shiny_stats.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
} }

View file

@ -83,15 +83,16 @@ fn cook() -> Result<(), Errorfr> {
.unwrap(); .unwrap();
// ENCODE: TypeData // ENCODE: TypeData
TypeData(ItemType::Gear) TypeData(ItemType::from(json_config.item_type))
.encode(ver, &mut out) .encode(ver, &mut out)
.unwrap(); .map_err(|_| Errorfr::ItemTypeMissing)?;
// ENCODE: NameData // ENCODE: NameData
NameData(String::from(format!("{}", json_config.name.trim()))) NameData(String::from(format!("{}", json_config.name.trim())))
.encode(ver, &mut out) .encode(ver, &mut out)
.unwrap(); .unwrap();
// json identification data handling // json identification data handling
let mut idvec = Vec::new(); let mut idvec = Vec::new();
for eachid in json_config.ids { for eachid in json_config.ids {
@ -162,9 +163,6 @@ fn cook() -> Result<(), Errorfr> {
}; };
} }
if debug_mode { if debug_mode {
dbg!(&powdervec); dbg!(&powdervec);

View file

@ -1,3 +1,4 @@
use idmangler_lib::types::ItemType;
use serde::Deserialize; use serde::Deserialize;
// structs // structs
#[derive(Deserialize)] #[derive(Deserialize)]
@ -16,7 +17,7 @@ pub struct Identificationer {
pub struct Jsonconfig { pub struct Jsonconfig {
pub debug: Option<bool>, pub debug: Option<bool>,
pub name: String, pub name: String,
pub crafted: bool, pub item_type: ItemTypeDeser,
pub shiny: Option<Shinyjson>, pub shiny: Option<Shinyjson>,
pub ids: Vec<Identificationer>, pub ids: Vec<Identificationer>,
pub powder_limit: u8, pub powder_limit: u8,
@ -34,3 +35,25 @@ pub struct Shinyjson {
pub key: String, pub key: String,
pub value: i64, 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<ItemTypeDeser> 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
}
}
}