cargo fmt

This commit is contained in:
endernon 2025-01-03 23:24:28 +00:00
parent e90124c4df
commit e11c54cae5
4 changed files with 89 additions and 77 deletions

View file

@ -1,8 +1,15 @@
use crate::jsonstruct::{CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder, RequirementsDeser, Shinyjson, Shinystruct};
use idmangler_lib::types::{ClassType, Element, ItemType, RollType, SkillType, Stat};
use idmangler_lib::{CustomGearTypeData, CustomConsumableTypeData, DataEncoder, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, TypeData, DurabilityData};
use std::collections::HashMap;
use crate::errorfr::Errorfr;
use crate::jsonstruct::{
CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder,
RequirementsDeser, Shinyjson, Shinystruct,
};
use idmangler_lib::types::{ClassType, Element, ItemType, RollType, SkillType, Stat};
use idmangler_lib::{
CustomConsumableTypeData, CustomGearTypeData, DataEncoder, DurabilityData, EndData,
IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData,
TypeData,
};
use std::collections::HashMap;
pub fn encode_startdata(general_params: &mut FuncParams) {
if *general_params.fr_debug_mode {
@ -22,7 +29,10 @@ pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTyp
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap();
}
pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &str) -> Result<(), Errorfr> {
pub fn encode_typedata_custom(
general_params: &mut FuncParams,
crafted_type: &str,
) -> Result<(), Errorfr> {
let frfr_type = CraftedTypesFr::try_from(crafted_type)?;
match frfr_type {
CraftedTypesFr::Gear(a) => {
@ -32,7 +42,7 @@ pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &st
CustomGearTypeData(a)
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap()
},
}
CraftedTypesFr::Consu(a) => {
if *general_params.fr_debug_mode {
println!("Encoding CustomTypeData: Consumable");
@ -44,23 +54,26 @@ pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &st
}
Ok(())
}
pub fn encode_duradata(general_params: &mut FuncParams, real_dura: Durability) -> Result<(), Errorfr> {
pub fn encode_duradata(
general_params: &mut FuncParams,
real_dura: Durability,
) -> Result<(), Errorfr> {
let effect_strength_fr: u8; // but actually it should be 0 to 100, not 0 to 255. But i dunno how to use u7 data type.
if let Some(effstr) = real_dura.effect_strength {
if *general_params.fr_debug_mode {
println!("Encoding DurabilityData: Defined");
}
effect_strength_fr = effstr
}
else {
} else {
let current_percentage = real_dura.dura_cur / real_dura.dura_max; // percentage of max durability
if current_percentage > 100 {
return Err(Errorfr::JsonDuraOutOfRange)
return Err(Errorfr::JsonDuraOutOfRange);
}
if current_percentage >= 50 { // for 100% dura to 50% dura, the effectiveness is 100%
if current_percentage >= 50 {
// for 100% dura to 50% dura, the effectiveness is 100%
effect_strength_fr = 100
}
else if current_percentage >= 10 { // for 50% dura to 10% dura, the effectiveness is 100% to 50%
} else if current_percentage >= 10 {
// for 50% dura to 10% dura, the effectiveness is 100% to 50%
// see this answer from Stackoverflow for transcribing range
// https://stackoverflow.com/a/929107
@ -70,36 +83,41 @@ pub fn encode_duradata(general_params: &mut FuncParams, real_dura: Durability) -
let new_range = 50;
// NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
effect_strength_fr = ((((current_percentage - 10) * new_range) / old_range) + 50) as u8
}
else if current_percentage >= 0 { // for 10% dura to 0% dura, the effectiveness is 50% to 10%
} else if current_percentage >= 0 {
// for 10% dura to 0% dura, the effectiveness is 50% to 10%
// old range is 10-0 = 10
let old_range = 10;
// new range is 50-10 = 40
let new_range = 40;
// NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
effect_strength_fr = ((((current_percentage) * new_range) / old_range) + 10) as u8
}
else {
return Err(Errorfr::JsonDuraOutOfRange)
} else {
return Err(Errorfr::JsonDuraOutOfRange);
}
}
if *general_params.fr_debug_mode {
println!("Encoding DurabilityData.effect_strenght: {}", effect_strength_fr);
println!(
"Encoding DurabilityData.effect_strenght: {}",
effect_strength_fr
);
println!("Encoding DurabilityData.current: {}", real_dura.dura_cur);
println!("Encoding DurabilityData.current: {}", real_dura.dura_max);
}
DurabilityData {
effect_strenght: effect_strength_fr,
current: real_dura.dura_cur,
max: real_dura.dura_max
max: real_dura.dura_max,
}
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap();
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap();
Ok(())
}
pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) {
if *general_params.fr_debug_mode {
println!("Encoding RequirementData.Level: {:?}", real_reqdata.level.clone())
println!(
"Encoding RequirementData.Level: {:?}",
real_reqdata.level.clone()
)
}
let mut fr_class: Option<ClassType> = None;
if let Some(actualclass) = real_reqdata.class {
@ -107,8 +125,7 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
if *general_params.fr_debug_mode {
println!("Encoding RequirementData.Class: {:?}", actualclass.clone())
}
}
else if *general_params.fr_debug_mode {
} else if *general_params.fr_debug_mode {
println!("Encoding RequirementData.Class: Undefined");
}
let spvec: Vec<(SkillType, i32)> = Vec::<(SkillType, i32)>::from(real_reqdata.sp);
@ -118,10 +135,10 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement
RequirementsData {
level: real_reqdata.level,
class: fr_class,
skills: spvec
skills: spvec,
}
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap()
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap()
}
pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) {
// ENCODE: NameData
@ -132,7 +149,11 @@ pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) {
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap();
}
pub fn encode_iddata(general_params: &mut FuncParams, real_ids: Vec<Identificationer>, idsmap: HashMap<String, u8>) {
pub fn encode_iddata(
general_params: &mut FuncParams,
real_ids: Vec<Identificationer>,
idsmap: HashMap<String, u8>,
) {
let mut idvec = Vec::new();
for eachid in real_ids {
let id_id = idsmap.get(eachid.id.trim());
@ -213,7 +234,11 @@ pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) {
}
}
}
pub fn encode_shinydata(general_params: &mut FuncParams, shiny: Shinyjson, json_shiny: Vec<Shinystruct>) {
pub fn encode_shinydata(
general_params: &mut FuncParams,
shiny: Shinyjson,
json_shiny: Vec<Shinystruct>,
) {
let mut realshinykey: u8;
let _shinykey = &shiny.key;
let shinyvalue = shiny.value;

View file

@ -64,8 +64,10 @@ pub enum Errorfr {
/// Durability was not found but is necessary
#[error("Error 4.5: \"Durability\" was not found (necessary for Crafted Gear item type)")]
JsonNotFoundDura,
/// Durability Bad
#[error("Error 4.6: \"Requirements\" was not found (necessary for Crafted Gear / Consumable items)")]
JsonNotFoundReqs
#[error(
"Error 4.6: \"Requirements\" was not found (necessary for Crafted Gear / Consumable items)"
)]
JsonNotFoundReqs,
}

View file

@ -1,13 +1,12 @@
use crate::errorfr::Errorfr;
use idmangler_lib::types::{ItemType, TransformVersion, ConsumableType, GearType};
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
use idmangler_lib::types::{ClassType, ConsumableType::*, GearType::*, SkillType};
use idmangler_lib::types::{ConsumableType, GearType, ItemType, TransformVersion};
use serde::Deserialize;
use std::fs;
use idmangler_lib::types::{ConsumableType::*,GearType::*, ClassType, SkillType};
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
// structs for the json parsing
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Jsonconfig {
pub debug: Option<bool>, // not a thing to be encoded, this just toggles debug prints. Also settable using --debug
// Item Types (Gear, Tome, Charm, Crafted Gear, Crafted Consum)
@ -27,26 +26,22 @@ pub struct Jsonconfig {
pub powders: Option<Vec<Powder>>,
pub rerolls: Option<u8>,
}
// reimplementing this because it doesnt have Deserialize.
// reimplementing this because it doesnt have Deserialize.
// Also, changing the SkillPoint stuff into NOT a vec.
// This avoids confusing end user.
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct RequirementsDeser {
pub level: u8,
pub class: Option<ClassDeser>,
pub sp: SkillPointDeser
pub sp: SkillPointDeser,
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub enum ClassDeser {
Archer,
Warrior,
Assassin,
Mage,
Shaman
Shaman,
}
impl From<ClassDeser> for ClassType {
fn from(value: ClassDeser) -> Self {
@ -55,13 +50,11 @@ impl From<ClassDeser> for ClassType {
ClassDeser::Warrior => ClassType::Warrior,
ClassDeser::Assassin => ClassType::Assasin,
ClassDeser::Mage => ClassType::Mage,
ClassDeser::Shaman => ClassType::Shaman
ClassDeser::Shaman => ClassType::Shaman,
}
}
}
#[derive(Deserialize, Copy)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone)]
#[derive(Deserialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
pub struct SkillPointDeser {
#[serde(alias = "Str")]
#[serde(alias = "str")]
@ -82,7 +75,7 @@ pub struct SkillPointDeser {
#[serde(alias = "Agi")]
#[serde(alias = "agi")]
#[serde(alias = "agility")]
pub agility: Option<i32>
pub agility: Option<i32>,
}
impl From<SkillPointDeser> for Vec<(SkillType, i32)> {
@ -109,7 +102,7 @@ impl From<SkillPointDeser> for Vec<(SkillType, i32)> {
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum CraftedTypesFr {
Gear(GearType),
Consu(ConsumableType)
Consu(ConsumableType),
}
impl TryFrom<&str> for CraftedTypesFr {
type Error = Errorfr;
@ -139,39 +132,34 @@ impl TryFrom<&str> for CraftedTypesFr {
"weapon" => Ok(Gear(Weapon)),
"accessory" => Ok(Gear(Accessory)),
// fallback error return
_ => Err(Errorfr::JsonInvalidCraftedType)
_ => Err(Errorfr::JsonInvalidCraftedType),
}
}
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Durability {
pub effect_strength: Option<u8>,
pub dura_cur: i32,
pub dura_max: i32
pub dura_max: i32,
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Shinystruct {
pub id: u8,
pub key: String,
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Identificationer {
pub id: String,
pub base: i32,
pub roll: Option<u8>,
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Powder {
pub r#type: char,
pub amount: Option<u8>,
}
#[derive(Deserialize)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Shinyjson {
pub key: String,
pub value: i64,

View file

@ -13,9 +13,9 @@ use crate::errorfr::Errorfr;
use crate::jsondl::*;
use crate::jsonstruct::*;
use crate::errorfr::Errorfr::JsonNotFoundCraftedType;
use clap::Parser;
use reqwest::Url;
use crate::errorfr::Errorfr::JsonNotFoundCraftedType;
#[derive(Parser, Debug, Clone)]
#[command(version, about, long_about = None, arg_required_else_help(true))]
@ -130,9 +130,8 @@ fn cook(
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
if let Some(real_crafted_type) = json_config.crafted_type {
encode_typedata_custom(&mut fr_params, &real_crafted_type)?;
}
else {
return Err(JsonNotFoundCraftedType)
} else {
return Err(JsonNotFoundCraftedType);
}
}
_ => {}
@ -165,11 +164,10 @@ fn cook(
ItemTypeDeser::CraftedGear => {
if let Some(real_dura) = json_config.durability {
encode_duradata(&mut fr_params, real_dura)?;
} else {
return Err(Errorfr::JsonNotFoundDura);
}
else {
return Err(Errorfr::JsonNotFoundDura)
}
},
}
_ => {}
}
@ -178,11 +176,10 @@ fn cook(
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
if let Some(real_reqs) = json_config.requirements {
encode_reqdata(&mut fr_params, real_reqs)
} else {
return Err(Errorfr::JsonNotFoundReqs);
}
else {
return Err(Errorfr::JsonNotFoundReqs)
}
},
}
_ => {}
}