From d0130b50f13707a0ccd0fdf3fc87c1a424225e51 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sat, 28 Jun 2025 23:57:29 +0300 Subject: [PATCH] Added common synth structs and updated the format for KH1 synths --- input/kh1/synthesis.toml | 29 +++++++++++++++ src/common.rs | 1 + src/common/enemy.rs | 1 - src/common/materials.rs | 2 +- src/common/synthesis.rs | 78 ++++++++++++++++++++++++++++++++++++++++ src/kh1.rs | 7 +++- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 src/common/synthesis.rs diff --git a/input/kh1/synthesis.toml b/input/kh1/synthesis.toml index e991ebd..90f4473 100644 --- a/input/kh1/synthesis.toml +++ b/input/kh1/synthesis.toml @@ -1,3 +1,32 @@ +[[sets]] +id = 1 +name = "List I" + +[[sets]] +id = 2 +name = "List II" +requirement = "Create three unique items" + +[[sets]] +id = 3 +name = "List III" +requirement = "Create nine unique items" + +[[sets]] +id = 4 +name = "List IV" +requirement = "Create fifteen unique items" + +[[sets]] +id = 5 +name = "List V" +requirement = "Create all items so far" + +[[sets]] +id = 6 +name = "List VI" +requirement = "Create all items so far" + [[recipes]] result = "Mega-Potion" set = 1 diff --git a/src/common.rs b/src/common.rs index 4ab86cf..1c17718 100644 --- a/src/common.rs +++ b/src/common.rs @@ -3,6 +3,7 @@ use serde::Deserialize; pub mod direction; pub mod enemy; pub mod materials; +pub mod synthesis; #[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Game { diff --git a/src/common/enemy.rs b/src/common/enemy.rs index 8b2a80b..5bde159 100644 --- a/src/common/enemy.rs +++ b/src/common/enemy.rs @@ -50,7 +50,6 @@ pub struct EnemyDrop { pub from: String, pub chance: EnemyDropChance, pub kind: EnemyDropKind, - pub icon: Option, pub info: Option, pub material: Option, } diff --git a/src/common/materials.rs b/src/common/materials.rs index 97cc30c..c5c303f 100644 --- a/src/common/materials.rs +++ b/src/common/materials.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fmt::Display, fs, path}; +use std::{collections::HashMap, fmt::Display, path}; use serde::Deserialize; diff --git a/src/common/synthesis.rs b/src/common/synthesis.rs new file mode 100644 index 0000000..a139dee --- /dev/null +++ b/src/common/synthesis.rs @@ -0,0 +1,78 @@ +use std::collections::{BTreeMap, HashMap}; + +use itertools::Itertools; +use serde::Deserialize; + +#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] +pub struct SynthesisData { + pub sets: Vec, + pub recipes: Vec, +} + +impl SynthesisData { + pub fn new(path: &str) -> SynthesisData { + let str = std::fs::read_to_string(path).unwrap(); + let mut data = toml::from_str::(&str).unwrap(); + + for recipe in &mut data.recipes { + for set in &data.sets { + if set.id == recipe.set_id { + recipe.set = set.clone(); + break; + } + } + } + + data + } + + pub fn total_amounts(&self) -> Vec<(String, u32)> { + let mut map = HashMap::::new(); + self.recipes.iter().for_each(|recipe| { + for item in &recipe.items { + map.entry(item.name.clone()) + .and_modify(|val| *val += item.amount) + .or_insert(0); + } + }); + + let mut v = map.into_iter().collect::>(); + v.sort_by(|a, b| b.1.cmp(&a.1)); + v + } +} + +#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] +pub struct SynthesisSet { + pub id: u32, + pub name: String, + pub requirement: Option, +} + +impl PartialOrd for SynthesisSet { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for SynthesisSet { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq)] +pub struct SynthesisRecipe { + #[serde(rename = "set")] + pub set_id: u32, + #[serde(skip)] + pub set: SynthesisSet, + pub result: String, + pub items: Vec, +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq)] +pub struct SynthesisRecipeItem { + pub name: String, + pub amount: u32, +} diff --git a/src/kh1.rs b/src/kh1.rs index 5dbc39e..f3ad7a4 100644 --- a/src/kh1.rs +++ b/src/kh1.rs @@ -6,11 +6,12 @@ use itertools::Itertools; use crate::{ RuntimeModule, - common::{Game, enemy::Enemy, materials::MaterialDrops}, + common::{Game, enemy::Enemy, materials::MaterialDrops, synthesis::SynthesisData}, create_file, create_hashes, }; const ENEMIES_PATH: &str = "./input/kh1/enemies"; +const SYNTHESIS_PATH: &str = "./input/kh1/synthesis.toml"; static JS_HASH: OnceLock = OnceLock::new(); #[derive(Template)] @@ -35,6 +36,10 @@ impl RuntimeModule for Module { .dedup() .collect(); + tracing::info!("Loading synthesis data from {}", SYNTHESIS_PATH); + let synth = SynthesisData::new(SYNTHESIS_PATH); + dbg!(synth.total_amounts()); + tracing::info!("Generating the KH1 drops template"); let drops_template = DropsTemplate { game: Game::Kh1,