move stuff to ENCODE functions
This commit is contained in:
parent
321a5b302f
commit
366f5b5a64
1 changed files with 69 additions and 57 deletions
126
src/main.rs
126
src/main.rs
|
@ -58,23 +58,7 @@ fn main() {
|
||||||
|
|
||||||
// download jsons if necessary
|
// download jsons if necessary
|
||||||
if let Some(dlvalue) = &args.download {
|
if let Some(dlvalue) = &args.download {
|
||||||
let jsons = DownloadJsons::from(dlvalue.clone());
|
dl_json_fr(dlvalue, executable_path)
|
||||||
if jsons == DownloadJsons::All || jsons == DownloadJsons::ShinyStats {
|
|
||||||
if let Err(e) = dl_json(
|
|
||||||
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(),
|
|
||||||
format!("{}{}", executable_path, "/shiny_stats.json"),
|
|
||||||
) { // error handling below
|
|
||||||
println!("{} Filename: {}",e,dlvalue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if jsons == DownloadJsons::All || jsons == DownloadJsons::IdKeys {
|
|
||||||
if let Err(e) = dl_json(
|
|
||||||
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(),
|
|
||||||
format!("{}{}", executable_path, "/id_keys.json"),
|
|
||||||
) { // error handling below
|
|
||||||
println!("{} Filename: {}",e,dlvalue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if files load properly and all that
|
// check if files load properly and all that
|
||||||
|
@ -98,14 +82,8 @@ fn main() {
|
||||||
let ver = TransformVersion::Version1;
|
let ver = TransformVersion::Version1;
|
||||||
|
|
||||||
// StartData and TypeData are always present
|
// StartData and TypeData are always present
|
||||||
|
encode_startdata(&mut out, ver);
|
||||||
// ENCODE: StartData
|
encode_typedata(&mut out, ver, loaded_config.item_type);
|
||||||
StartData(ver).encode(ver, &mut out).unwrap();
|
|
||||||
|
|
||||||
// ENCODE: TypeData
|
|
||||||
TypeData(ItemType::from(loaded_config.item_type))
|
|
||||||
.encode(ver, &mut out)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// ENCODE: ALotOfStuff
|
// ENCODE: ALotOfStuff
|
||||||
// Also print any mapped errors
|
// Also print any mapped errors
|
||||||
|
@ -120,8 +98,7 @@ fn main() {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ENCODE: EndData
|
encode_enddata(&mut out, ver);
|
||||||
EndData.encode(ver, &mut out).unwrap();
|
|
||||||
|
|
||||||
// final string print
|
// final string print
|
||||||
println!("{}", encode_string(&out));
|
println!("{}", encode_string(&out));
|
||||||
|
@ -155,35 +132,7 @@ fn cook(
|
||||||
// json identification data handling for type GEAR (0)
|
// json identification data handling for type GEAR (0)
|
||||||
// only occurs if identifications block is present
|
// only occurs if identifications block is present
|
||||||
if let Some(real_ids) = json_config.ids {
|
if let Some(real_ids) = json_config.ids {
|
||||||
let mut idvec = Vec::new();
|
encode_ids(out, real_ids, ver, idsmap)
|
||||||
for eachid in real_ids {
|
|
||||||
let id_id = idsmap.get(eachid.id.trim());
|
|
||||||
let id_base = eachid.base;
|
|
||||||
let id_roll = eachid.roll;
|
|
||||||
|
|
||||||
idvec.push(
|
|
||||||
Stat {
|
|
||||||
kind: match id_id {
|
|
||||||
Some(ide) => *ide,
|
|
||||||
None => panic!("There is a mismatched ID, and this message has replaced where the line is meant to be")
|
|
||||||
},
|
|
||||||
base: Some(id_base),
|
|
||||||
roll: match id_roll{
|
|
||||||
Some(rolle) => RollType::Value(rolle),
|
|
||||||
None => RollType::PreIdentified
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// println!("{:?} {:?} {:?}",id_id,id_base,id_roll)
|
|
||||||
}
|
|
||||||
// ENCODE: IdentificationsData
|
|
||||||
IdentificationData {
|
|
||||||
identifications: idvec,
|
|
||||||
extended_encoding: true,
|
|
||||||
}
|
|
||||||
.encode(ver, out)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +202,35 @@ fn load_shinystats(executable_path: &str) -> Result<Vec<Shinystruct>, Errorfr> {
|
||||||
)
|
)
|
||||||
.map_err(|_| Errorfr::ShinyJsonCorrupt)
|
.map_err(|_| Errorfr::ShinyJsonCorrupt)
|
||||||
}
|
}
|
||||||
|
fn dl_json_fr(dlvalue: &String, executable_path: &str) {
|
||||||
|
let jsons = DownloadJsons::from(dlvalue.clone());
|
||||||
|
if jsons == DownloadJsons::All || jsons == DownloadJsons::ShinyStats {
|
||||||
|
if let Err(e) = dl_json(
|
||||||
|
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json".parse().unwrap(),
|
||||||
|
format!("{}{}", executable_path, "/shiny_stats.json"),
|
||||||
|
) { // error handling below
|
||||||
|
println!("{} Filename: {}",e,dlvalue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if jsons == DownloadJsons::All || jsons == DownloadJsons::IdKeys {
|
||||||
|
if let Err(e) = dl_json(
|
||||||
|
"https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json".parse().unwrap(),
|
||||||
|
format!("{}{}", executable_path, "/id_keys.json"),
|
||||||
|
) { // error handling below
|
||||||
|
println!("{} Filename: {}",e,dlvalue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn encode_startdata(out: &mut Vec<u8>, ver: TransformVersion) {
|
||||||
|
// ENCODE: StartData
|
||||||
|
StartData(ver).encode(ver, out).unwrap();
|
||||||
|
}
|
||||||
|
fn encode_typedata(out: &mut Vec<u8>, ver: TransformVersion, item_type_deser: ItemTypeDeser) {
|
||||||
|
// ENCODE: TypeData
|
||||||
|
TypeData(ItemType::from(item_type_deser))
|
||||||
|
.encode(ver, out)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
fn encode_powder(out: &mut Vec<u8>, debug_mode: &bool, real_powders: Vec<Powder>, ver: TransformVersion) {
|
fn encode_powder(out: &mut Vec<u8>, debug_mode: &bool, real_powders: Vec<Powder>, ver: TransformVersion) {
|
||||||
let mut powdervec = Vec::new();
|
let mut powdervec = Vec::new();
|
||||||
for eachpowder in real_powders {
|
for eachpowder in real_powders {
|
||||||
|
@ -290,4 +267,39 @@ fn encode_powder(out: &mut Vec<u8>, debug_mode: &bool, real_powders: Vec<Powder>
|
||||||
}
|
}
|
||||||
.encode(ver, out)
|
.encode(ver, out)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
}
|
||||||
|
fn encode_ids(out: &mut Vec<u8>, real_ids: Vec<Identificationer>, ver: TransformVersion, idsmap: HashMap<String, u8>) {
|
||||||
|
let mut idvec = Vec::new();
|
||||||
|
for eachid in real_ids {
|
||||||
|
let id_id = idsmap.get(eachid.id.trim());
|
||||||
|
let id_base = eachid.base;
|
||||||
|
let id_roll = eachid.roll;
|
||||||
|
|
||||||
|
idvec.push(
|
||||||
|
Stat {
|
||||||
|
kind: match id_id {
|
||||||
|
Some(ide) => *ide,
|
||||||
|
None => panic!("There is a mismatched ID, and this message has replaced where the line is meant to be")
|
||||||
|
},
|
||||||
|
base: Some(id_base),
|
||||||
|
roll: match id_roll{
|
||||||
|
Some(rolle) => RollType::Value(rolle),
|
||||||
|
None => RollType::PreIdentified
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// println!("{:?} {:?} {:?}",id_id,id_base,id_roll)
|
||||||
|
}
|
||||||
|
// ENCODE: IdentificationsData
|
||||||
|
IdentificationData {
|
||||||
|
identifications: idvec,
|
||||||
|
extended_encoding: true,
|
||||||
|
}
|
||||||
|
.encode(ver, out)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
fn encode_enddata(out: &mut Vec<u8>, ver: TransformVersion) {
|
||||||
|
// ENCODE: EndData
|
||||||
|
EndData.encode(ver, out).unwrap();
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue