Implement shiny data to json, refactor some other stuff

This commit is contained in:
endernon 2024-09-10 21:36:44 +01:00
parent eea177bb3b
commit e1298accb4
2 changed files with 63 additions and 32 deletions

View file

@ -1,10 +1,10 @@
use idmangler_lib::{ use idmangler_lib::{
data_transformer::{ data_transformer::{
decode, enddata::EndData, identdata::IdentificationData, namedata::NameData, enddata::EndData, identdata::IdentificationData, namedata::NameData,
powderdata::PowderData, rerolldata::RerollData, shinydata::ShinyData, startdata::StartData, powderdata::PowderData, rerolldata::RerollData, shinydata::ShinyData, startdata::StartData,
typedata::TypeData, DataEncoder, typedata::TypeData, DataEncoder,
}, },
encoding::{decode_string, encode_string}, encoding::{encode_string},
types::{ types::{
itemtype::ItemType, itemtype::ItemType,
powder::Powders, powder::Powders,
@ -19,7 +19,6 @@ use std::panic;
use std::env; use std::env;
use serde_json; use serde_json;
use serde::Deserialize; use serde::Deserialize;
use base64::engine::{general_purpose, Engine};
// structs // structs
#[derive(Deserialize)] #[derive(Deserialize)]
@ -37,22 +36,39 @@ struct Identificationer {
#[derive(Deserialize)] #[derive(Deserialize)]
struct jsonconfig { struct jsonconfig {
name: String, name: String,
shiny: Option<shinyjson>,
ids: Vec<Identificationer>, ids: Vec<Identificationer>,
powder_limit: u8, powder_limit: u8,
powders: Vec<Powder>, powders: Vec<Powder>,
rerolls:Option<u8> rerolls:Option<u8>
} }
#[derive(Deserialize)]
struct shinystruct{
id: u8,
key:String
}
#[derive(Deserialize)]
struct shinyjson {
key: String,
value: u8
}
fn main() { fn main() {
// enable fancypanic when building for release // enable fancypanic when building for release
fancypanic(); // fancypanic();
// newest json reading code // newest json reading code
let json_config: jsonconfig = serde_json::from_reader( let json_config: jsonconfig = serde_json::from_reader(
fs::File::open("values.json").expect(ERROR[1])) fs::File::open("values.json").expect(ERROR[1]))
.expect(ERROR[2]); .expect(ERROR[2]);
let idsmap: HashMap<String, u8> = serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])) let idsmap: HashMap<String, u8> = serde_json::from_reader(
fs::File::open("id_keys.json").expect(ERROR[3]))
.expect(ERROR[4]); .expect(ERROR[4]);
let json_shiny: Vec<shinystruct> = serde_json::from_reader(
fs::File::open("shiny_stats.json").expect(ERROR[5]))
.expect(ERROR[6]);
// println!("{:?}",idsmap.get("airDamage")); // println!("{:?}",idsmap.get("airDamage"));
@ -77,7 +93,6 @@ fn main() {
let id_roll = eachid.roll; let id_roll = eachid.roll;
idvec.push( idvec.push(
(
Stat { Stat {
kind: match id_id { kind: match id_id {
Some(ide) => *ide, Some(ide) => *ide,
@ -89,7 +104,6 @@ fn main() {
None => RollType::PreIdentified None => RollType::PreIdentified
} }
} }
)
); );
// println!("{:?} {:?} {:?}",id_id,id_base,id_roll) // println!("{:?} {:?} {:?}",id_id,id_base,id_roll)
@ -122,32 +136,32 @@ fn main() {
// no need to return to variable or i'll need to rematch AGAIN // no need to return to variable or i'll need to rematch AGAIN
match eachpowder.r#type { match eachpowder.r#type {
'E' | 'e' => { 'E' | 'e' => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::EARTH,powdertier)) powdervec.push((Powders::EARTH,powdertier))
} }
}, },
'T' | 't' => { 'T' | 't' => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::THUNDER,powdertier)) powdervec.push((Powders::THUNDER,powdertier))
} }
}, },
'W' | 'w' => { 'W' | 'w' => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::WATER,powdertier)) powdervec.push((Powders::WATER,powdertier))
} }
}, },
'F' | 'f' => { 'F' | 'f' => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::FIRE,powdertier)) powdervec.push((Powders::FIRE,powdertier))
} }
}, },
'A' | 'a' => { 'A' | 'a' => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::AIR,powdertier)) powdervec.push((Powders::AIR,powdertier))
} }
}, },
_ => { _ => {
for i in 0..powderamount { for _i in 0..powderamount {
powdervec.push((Powders::THUNDER,powdertier)) powdervec.push((Powders::THUNDER,powdertier))
} }
} }
@ -158,9 +172,6 @@ fn main() {
} }
// println!("{:?}",powdervec); // println!("{:?}",powdervec);
// old powder data encode kinda, takes data from new encode // old powder data encode kinda, takes data from new encode
PowderData { PowderData {
powder_slots: json_config.powder_limit, powder_slots: json_config.powder_limit,
@ -179,15 +190,31 @@ fn main() {
None => pass() None => pass()
} }
let mut realshinykey:u8;
if let Some(shiny) = json_config.shiny {
ShinyData { if let ref shinykey = shiny.key {
id: 2, if let shinyvalue = shiny.value{
val: i64::MAX as i64, //- 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000, realshinykey = 1;
// u16::MAX is the max value of unsigned 16bit value for i in json_shiny {
if i.key == shiny.key {
realshinykey = i.id;
println!("shiny key {}",shiny.key);
}
}
println!("realshinykey: {}",realshinykey);
println!("shinyvalue: {}",shinyvalue);
ShinyData {
id: realshinykey,
val: shinyvalue as i64, //- 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000,
// u16::MAX is the max value of unsigned 16bit value
}
.encode(ver, &mut out)
.unwrap();
}
}
} }
.encode(ver, &mut out)
.unwrap();
// prints (Water,6) 255 times // prints (Water,6) 255 times
@ -208,11 +235,10 @@ fn main() {
// println!(); // println!();
// decode test // decode test
let input = "󰀀󰄀󰉁󶹴󶡲󶅣󶥴󶔠󴉡󶱬󶥳󷑡󰀃󰠁󰀞󾠇󵠑󳱩󳢠󱽴󴠧󷄡󱹵󳫠󰢂󱌨󵴅󲠞􏿮"; //let input = "󰀀󰄀󰉁󶹴󶡲󶅣󶥴󶔠󴉡󶱬󶥳󷑡󰀃󰠁󰀞󾠇󵠑󳱩󳢠󱽴󴠧󷄡󱹵󳫠󰢂󱌨󵴅󲠞􏿮";
let bytes = decode_string(&input); //let bytes = decode_string(&input);
let mut bytes_iter = bytes.into_iter(); //let mut bytes_iter = bytes.into_iter();
//let out = decode(&mut bytes_iter).unwrap();
let out = decode(&mut bytes_iter).unwrap();
// println!("{:#?}", out); // println!("{:#?}", out);
} }
@ -229,12 +255,14 @@ fn pass() {
} }
const ERROR: [&'static str; 5] = [ const ERROR: [&'static str; 7] = [
"Error 0: what did you even do to get this? ", "Error 0: what did you even do to get this? ",
"Error 1: json config file is missing, reobtain it from the values.json I have sent you. ", "Error 1: json config file is missing, reobtain it from the values.json I have sent you. ",
"Error 2: json config is broken. Reread the example data or reobtain it from the values.json I have sent you. ", "Error 2: json config is broken. Reread the example data or reobtain it from the values.json I have sent you. ",
"Error 3: Identifications hashmap not found. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory.", "Error 3: Identifications hashmap not found. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory.",
"Error 4: Identifications hashhmap is corrupt. Reobtain it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory." "Error 4: Identifications hashhmap is corrupt. Reobtain it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory.",
"Error 5: Shiny data json is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/a8469fad2f3bd0fc0fe2678eeb812d7877c9e61b/Data-Storage/shiny_stats.json",
"Error 6: Shiny data json is corrupt. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/a8469fad2f3bd0fc0fe2678eeb812d7877c9e61b/Data-Storage/shiny_stats.json"
]; ];
const _BOIL: [&'static str; 3] = [ const _BOIL: [&'static str; 3] = [
"0", "0",

View file

@ -4,7 +4,10 @@
"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",
"shiny": {
"key": "mobsKilled",
"value": 69
},
"ids": [ "ids": [
{"id": "mainAttackDamage","base": 320,"roll": 69}, {"id": "mainAttackDamage","base": 320,"roll": 69},
{"id": "healthRegenRaw", "base":250 , "roll":130 }, {"id": "healthRegenRaw", "base":250 , "roll":130 },