CraftedGear and CraftedConsu RequirementData (2/2)
This commit is contained in:
parent
02b5cabcb9
commit
7615c17b60
4 changed files with 85 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::jsonstruct::{CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder, RequirementsDeser, Shinyjson, Shinystruct};
|
use crate::jsonstruct::{ClassDeser, CraftedTypesFr, Durability, FuncParams, Identificationer, ItemTypeDeser, Powder, RequirementsDeser, Shinyjson, Shinystruct, SkillPointDeser};
|
||||||
use idmangler_lib::types::{Element, ItemType, RollType, Stat};
|
use idmangler_lib::types::{ClassType, Element, ItemType, RollType, SkillType, Stat};
|
||||||
use idmangler_lib::{CustomGearTypeData, CustomConsumableTypeData, DataEncoder, EndData, IdentificationData, NameData, PowderData, RerollData, ShinyData, StartData, TypeData, DurabilityData};
|
use idmangler_lib::{CustomGearTypeData, CustomConsumableTypeData, DataEncoder, EndData, IdentificationData, NameData, PowderData, RequirementsData, RerollData, ShinyData, StartData, TypeData, DurabilityData};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::errorfr::Errorfr;
|
use crate::errorfr::Errorfr;
|
||||||
|
|
||||||
|
@ -78,7 +78,18 @@ pub fn encode_duradata(general_params: &mut FuncParams, real_dura: Durability) -
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) {
|
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) {
|
pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) {
|
||||||
// ENCODE: NameData
|
// ENCODE: NameData
|
||||||
|
|
|
@ -61,6 +61,11 @@ pub enum Errorfr {
|
||||||
#[error("Error 4.4: Durability percentage is out of range (Should be between 0 and 100)")]
|
#[error("Error 4.4: Durability percentage is out of range (Should be between 0 and 100)")]
|
||||||
JsonDuraOutOfRange,
|
JsonDuraOutOfRange,
|
||||||
|
|
||||||
|
/// Durability was not found but is necessary
|
||||||
#[error("Error 4.5: \"Durability\" was not found (necessary for Crafted Gear item type)")]
|
#[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
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use idmangler_lib::types::{ItemType, TransformVersion, ConsumableType, GearType}
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use idmangler_lib::types::{ConsumableType::*,GearType::*, ClassType, SkillType};
|
use idmangler_lib::types::{ConsumableType::*,GearType::*, ClassType, SkillType};
|
||||||
|
use idmangler_lib::types::Element::Earth;
|
||||||
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
|
use crate::jsonstruct::CraftedTypesFr::{Consu, Gear};
|
||||||
|
|
||||||
// structs for the json parsing
|
// structs for the json parsing
|
||||||
|
@ -31,9 +32,9 @@ pub struct Jsonconfig {
|
||||||
// This avoids confusing end user.
|
// This avoids confusing end user.
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct RequirementsDeser {
|
pub struct RequirementsDeser {
|
||||||
level: u8,
|
pub level: u8,
|
||||||
class: Option<ClassDeser>,
|
pub class: Option<ClassDeser>,
|
||||||
sp: SkillPointDeser
|
pub sp: SkillPointDeser
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub enum ClassDeser {
|
pub enum ClassDeser {
|
||||||
|
@ -43,13 +44,61 @@ pub enum ClassDeser {
|
||||||
Mage,
|
Mage,
|
||||||
Shaman
|
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)]
|
#[derive(Deserialize)]
|
||||||
pub struct SkillPointDeser {
|
pub struct SkillPointDeser {
|
||||||
Earth: Option<i32>,
|
#[serde(alias = "Str")]
|
||||||
Thunder: Option<i32>,
|
#[serde(alias = "str")]
|
||||||
Water: Option<i32>,
|
#[serde(alias = "strength")]
|
||||||
Fire: Option<i32>,
|
pub strength: Option<i32>,
|
||||||
Air: 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 {
|
pub enum CraftedTypesFr {
|
||||||
Gear(GearType),
|
Gear(GearType),
|
||||||
|
|
|
@ -160,7 +160,7 @@ fn cook(
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ENCODE: DurabilityData (OPTIONAL) (REQUIRED for CraftedGear)
|
// ENCODE: DurabilityData (REQUIRED for CraftedGear)
|
||||||
match json_config.item_type {
|
match json_config.item_type {
|
||||||
ItemTypeDeser::CraftedGear => {
|
ItemTypeDeser::CraftedGear => {
|
||||||
if let Some(real_dura) = json_config.durability {
|
if let Some(real_dura) = json_config.durability {
|
||||||
|
@ -176,7 +176,12 @@ fn cook(
|
||||||
// ENCODE: RequirementsData if ItemType is CraftedGear, CraftedConsu
|
// ENCODE: RequirementsData if ItemType is CraftedGear, CraftedConsu
|
||||||
match json_config.item_type {
|
match json_config.item_type {
|
||||||
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
|
ItemTypeDeser::CraftedGear | ItemTypeDeser::CraftedConsu => {
|
||||||
|
if let Some(real_reqs) = json_config.requirements {
|
||||||
|
encode_reqdata(&mut fr_params, real_reqs)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Err(Errorfr::JsonNotFoundReqs)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue