CraftedGear and CraftedConsu RequirementData (2/2)

This commit is contained in:
endernon 2025-01-03 20:14:12 +00:00
parent 02b5cabcb9
commit 7615c17b60
4 changed files with 85 additions and 15 deletions

View file

@ -1,6 +1,6 @@
use crate::jsonstruct::{CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder, RequirementsDeser, Shinyjson, Shinystruct};
use idmangler_lib::types::{Element, ItemType, RollType, Stat};
use idmangler_lib::{CustomGearTypeData, CustomConsumableTypeData, DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData, StartData, TypeData, DurabilityData};
use crate::jsonstruct::{ClassDeser, CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder, RequirementsDeser, Shinyjson, Shinystruct, SkillPointDeser};
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;
@ -78,7 +78,18 @@ pub fn encode_duradata(general_params: &mut FuncParams, real_dura: Durability) -
Ok(())
}
pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) {
let mut fr_class: Option<ClassType> = None;
if let Some(actualclass) = real_reqdata.class {
fr_class = Some(ClassType::from(actualclass))
}
let spvec: Vec<(SkillType, i32)> = Vec::<(SkillType, i32)>::from(real_reqdata.sp);
RequirementsData {
level: real_reqdata.level,
class: fr_class,
skills: spvec
}
.encode(general_params.fr_ver, general_params.fr_out)
.unwrap()
}
pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) {
// ENCODE: NameData

View file

@ -61,6 +61,11 @@ pub enum Errorfr {
#[error("Error 4.4: Durability percentage is out of range (Should be between 0 and 100)")]
JsonDuraOutOfRange,
/// Durability was not found but is necessary
#[error("Error 4.5: \"Durability\" was not found (necessary for Crafted Gear item type)")]
JsonNotFoundDura
JsonNotFoundDura,
/// Durability Bad
#[error("Error 4.6: \"Requirements\" was not found (necessary for Crafted Gear / Consumable items)")]
JsonNotFoundReqs
}

View file

@ -3,6 +3,7 @@ use idmangler_lib::types::{ItemType, TransformVersion, ConsumableType, GearType}
use serde::Deserialize;
use std::fs;
use idmangler_lib::types::{ConsumableType::*,GearType::*, ClassType, SkillType};
use idmangler_lib::types::Element::Earth;
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
// structs for the json parsing
@ -31,9 +32,9 @@ pub struct Jsonconfig {
// This avoids confusing end user.
#[derive(Deserialize)]
pub struct RequirementsDeser {
level: u8,
class: Option<ClassDeser>,
sp: SkillPointDeser
pub level: u8,
pub class: Option<ClassDeser>,
pub sp: SkillPointDeser
}
#[derive(Deserialize)]
pub enum ClassDeser {
@ -43,13 +44,61 @@ pub enum ClassDeser {
Mage,
Shaman
}
impl From<ClassDeser> for ClassType {
fn from(value: ClassDeser) -> Self {
match value {
ClassDeser::Archer => ClassType::Archer,
ClassDeser::Warrior => ClassType::Warrior,
ClassDeser::Assassin => ClassType::Assasin,
ClassDeser::Mage => ClassType::Mage,
ClassDeser::Shaman => ClassType::Shaman
}
}
}
#[derive(Deserialize)]
pub struct SkillPointDeser {
Earth: Option<i32>,
Thunder: Option<i32>,
Water: Option<i32>,
Fire: Option<i32>,
Air: Option<i32>
#[serde(alias = "Str")]
#[serde(alias = "str")]
#[serde(alias = "strength")]
pub strength: Option<i32>,
#[serde(alias = "Dex")]
#[serde(alias = "dex")]
#[serde(alias = "dexterity")]
pub dexterity: Option<i32>,
#[serde(alias = "Def")]
#[serde(alias = "def")]
#[serde(alias = "defense")]
pub defense: Option<i32>,
#[serde(alias = "Int")]
#[serde(alias = "int")]
#[serde(alias = "intelligence")]
pub intelligence: Option<i32>,
#[serde(alias = "Agi")]
#[serde(alias = "agi")]
#[serde(alias = "agility")]
pub agility: Option<i32>
}
impl From<SkillPointDeser> for Vec<(SkillType, i32)> {
fn from(value: SkillPointDeser) -> Self {
let mut returnedvec: Vec<(SkillType, i32)> = Vec::new();
if let Some(fr_str) = value.strength {
returnedvec.push((SkillType::Strength, fr_str))
}
if let Some(fr_dex) = value.dexterity {
returnedvec.push((SkillType::Dexterity, fr_dex))
}
if let Some(fr_int) = value.intelligence {
returnedvec.push((SkillType::Intelligence, fr_int))
}
if let Some(fr_def) = value.defense {
returnedvec.push((SkillType::Defence, fr_def))
}
if let Some(fr_agi) = value.agility {
returnedvec.push((SkillType::Agility, fr_agi))
}
returnedvec
}
}
pub enum CraftedTypesFr {
Gear(GearType),

View file

@ -160,7 +160,7 @@ fn cook(
_ => {}
}
// ENCODE: DurabilityData (OPTIONAL) (REQUIRED for CraftedGear)
// ENCODE: DurabilityData (REQUIRED for CraftedGear)
match json_config.item_type {
ItemTypeDeser::CraftedGear => {
if let Some(real_dura) = json_config.durability {
@ -176,7 +176,12 @@ fn cook(
// ENCODE: RequirementsData if ItemType is CraftedGear, CraftedConsu
match json_config.item_type {
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
if let Some(real_reqs) = json_config.requirements {
encode_reqdata(&mut fr_params, real_reqs)
}
else {
return Err(Errorfr::JsonNotFoundReqs)
}
},
_ => {}
}