Added common synth structs and updated the format for KH1 synths
parent
2e746d29cd
commit
d0130b50f1
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -50,7 +50,6 @@ pub struct EnemyDrop {
|
|||
pub from: String,
|
||||
pub chance: EnemyDropChance,
|
||||
pub kind: EnemyDropKind,
|
||||
pub icon: Option<String>,
|
||||
pub info: Option<String>,
|
||||
pub material: Option<MaterialDetails>,
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, fmt::Display, fs, path};
|
||||
use std::{collections::HashMap, fmt::Display, path};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
|
|
|
@ -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<SynthesisSet>,
|
||||
pub recipes: Vec<SynthesisRecipe>,
|
||||
}
|
||||
|
||||
impl SynthesisData {
|
||||
pub fn new(path: &str) -> SynthesisData {
|
||||
let str = std::fs::read_to_string(path).unwrap();
|
||||
let mut data = toml::from_str::<SynthesisData>(&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::<String, u32>::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::<Vec<_>>();
|
||||
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<String>,
|
||||
}
|
||||
|
||||
impl PartialOrd for SynthesisSet {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
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<SynthesisRecipeItem>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct SynthesisRecipeItem {
|
||||
pub name: String,
|
||||
pub amount: u32,
|
||||
}
|
|
@ -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<Hash> = 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,
|
||||
|
|
Loading…
Reference in New Issue