diff --git a/.gitignore b/.gitignore index bc84197..6228053 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk +assets/ diff --git a/Cargo.toml b/Cargo.toml index e081264..2ce0fb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,8 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } itertools = "0.13.0" [features] -default = ["bbs", "ddd", "kh3"] +default = ["bbs", "ddd", "kh3", "kh2"] +kh2 = [] kh3 = [] bbs = [] ddd = [] diff --git a/input/kh2/drops/blazing.toml b/input/kh2/drops/blazing.toml new file mode 100644 index 0000000..18e8547 --- /dev/null +++ b/input/kh2/drops/blazing.toml @@ -0,0 +1,33 @@ +kind = "blazing" + +[[shard]] +from = "Hammer Frame" +chance = 10 + +[[shard]] +from = "Minute Bomb" +chance = 6 + +[[stone]] +from = "Cannon Gun" +chance = 6 + +[[stone]] +from = "Tornado Step" +chance = 8 + +[[gem]] +from = "Fat Bandit" +chance = 12 + +[[gem]] +from = "Fiery Globe" +chance = 4 + +[[crystal]] +from = "Crescendo" +chance = 6 + +[[crystal]] +from = "Crimson Jazz" +chance = 12 diff --git a/input/kh2/drops/bright.toml b/input/kh2/drops/bright.toml new file mode 100644 index 0000000..3748495 --- /dev/null +++ b/input/kh2/drops/bright.toml @@ -0,0 +1,77 @@ +kind = "bright" + +[[shard]] +from = "Creeper Plant" +chance = 4 + +[[shard]] +from = "Hook Bat" +chance = 3 + +[[shard]] +from = "Minute Bomb" +chance = 3 + +[[shard]] +from = "Rabid Dog" +chance = 3 + +[[shard]] +from = "Soldier" +chance = 4 + +[[stone]] +from = "Aeroplane" +chance = 4 + +[[stone]] +from = "Cannon Gun" +chance = 3 + +[[stone]] +from = "Drilelr Mole" +chance = 4 + +[[stone]] +from = "Luna Bandit" +chance = 4 + +[[stone]] +from = "Silver Rock" +chance = 3 + +[[stone]] +from = "Tornado Step" +chance = 4 + +[[stone]] +from = "Wight Knight" +chance = 4 + +[[gem]] +from = "Aerial Knocker" +chance = 4 + +[[gem]] +from = "Magnum Loader" +chance = 4 + +[[gem]] +from = "Surveillance Robot" +chance = 3 + +[[crystal]] +from = "Air Pirate" +chance = 4 + +[[crystal]] +from = "Crescendo" +chance = 3 + +[[crystal]] +from = "Neoshadow" +chance = 4 + +[[crystal]] +from = "Strafer" +chance = 4 diff --git a/input/kh2/drops/dark.toml b/input/kh2/drops/dark.toml new file mode 100644 index 0000000..af0edfe --- /dev/null +++ b/input/kh2/drops/dark.toml @@ -0,0 +1,29 @@ +kind = "dark" + +[[shard]] +from = "Shadow" +chance = 4 + +[[shard]] +from = "Soldier" +chance = 8 + +[[stone]] +from = "Assault Rider" +chance = 12 + +[[stone]] +from = "Nightwalker" +chance = 10 + +[[gem]] +from = "Gargoyle Knight" +chance = 10 + +[[gem]] +from = "Gargoyle Warrior" +chance = 8 + +[[crystal]] +from = "Air Pirate" +chance = 8 diff --git a/input/kh2/drops/dense.toml b/input/kh2/drops/dense.toml new file mode 100644 index 0000000..086b83c --- /dev/null +++ b/input/kh2/drops/dense.toml @@ -0,0 +1,21 @@ +kind = "dense" + +[[shard]] +from = "Creeper" +chance = 8 + +[[shard]] +from = "Dragoon" +chance = 12 + +[[stone]] +from = "Sniper" +chance = 12 + +[[gem]] +from = "Samurai" +chance = 12 + +[[crystal]] +from = "Berserker" +chance = 12 diff --git a/input/kh2/drops/energy.toml b/input/kh2/drops/energy.toml new file mode 100644 index 0000000..7413b6b --- /dev/null +++ b/input/kh2/drops/energy.toml @@ -0,0 +1,45 @@ +kind = "energy" + +[[shard]] +from = "Bolt Tower" +chance = 4 + +[[shard]] +from = "Gargoyle Knight" +chance = 4 + +[[shard]] +from = "Gargoyle Warrior" +chance = 4 + +[[shard]] +from = "Nightwalker" +chance = 4 + +[[stone]] +from = "Hammer Frame" +chance = 4 + +[[stone]] +from = "Lance Soldier" +chance = 4 + +[[stone]] +from = "Trick Ghost" +chance = 4 + +[[gem]] +from = "Emerald Blues" +chance = 4 + +[[gem]] +from = "Fortuneteller" +chance = 4 + +[[crystal]] +from = "Bookmaster" +chance = 4 + +[[crystal]] +from = "Shaman" +chance = 4 diff --git a/input/kh2/drops/frost.toml b/input/kh2/drops/frost.toml new file mode 100644 index 0000000..ce57cb1 --- /dev/null +++ b/input/kh2/drops/frost.toml @@ -0,0 +1,29 @@ +kind = "frost" + +[[shard]] +from = "Hook Bat" +chance = 6 + +[[shard]] +from = "Lance Solider" +chance = 10 + +[[stone]] +from = "Aeroplane" +chance = 8 + +[[stone]] +from = "Hot Rod" +chance = 12 + +[[gem]] +from = "Fortuneteller" +chance = 8 + +[[gem]] +from = "Icy Cube" +chance = 4 + +[[crystal]] +from = "Living Bone" +chance = 12 diff --git a/input/kh2/drops/lightning.toml b/input/kh2/drops/lightning.toml new file mode 100644 index 0000000..d9c6803 --- /dev/null +++ b/input/kh2/drops/lightning.toml @@ -0,0 +1,33 @@ +kind = "lightning" + +[[shard]] +from = "Bolt Tower" +chance = 10 + +[[shard]] +from = "Rapid Thruster" +chance = 4 + +[[stone]] +from = "Driller Mole" +chance = 6 + +[[stone]] +from = "Emerald Blues" +chance = 10 + +[[gem]] +from = "Armored Knight" +chance = 12 + +[[gem]] +from = "Surveillance Robot" +chance = 8 + +[[crystal]] +from = "Devastator" +chance = 4 + +[[crystal]] +from = "Strafer" +chance = 6 diff --git a/input/kh2/drops/lucid.toml b/input/kh2/drops/lucid.toml new file mode 100644 index 0000000..2f96f91 --- /dev/null +++ b/input/kh2/drops/lucid.toml @@ -0,0 +1,33 @@ +kind = "lucid" + +[[shard]] +from = "Rabid Dog" +chance = 6 + +[[shard]] +from = "Trick Ghost" +chance = 10 + +[[stone]] +from = "Graveyard" +chance = 12 + +[[stone]] +from = "Toy Soldier" +chance = 12 + +[[stone]] +from = "Wight Knight" +chance = 8 + +[[gem]] +from = "Bookmaster" +chance = 10 + +[[gem]] +from = "Magnum Loader" +chance = 8 + +[[crystal]] +from = "Neoshadow" +chance = 8 diff --git a/input/kh2/drops/power.toml b/input/kh2/drops/power.toml new file mode 100644 index 0000000..675f7f2 --- /dev/null +++ b/input/kh2/drops/power.toml @@ -0,0 +1,29 @@ +kind = "power" + +[[shard]] +from = "Creeper Plant" +chance = 8 + +[[shard]] +from = "Large Body" +chance = 12 + +[[stone]] +from = "Luna Bandit" +chance = 8 + +[[stone]] +from = "Silver Rock" +chance = 8 + +[[gem]] +from = "Aerial Knocker" +chance = 8 + +[[gem]] +from = "Shaman" +chance = 10 + +[[crystal]] +from = "Morning Star" +chance = 12 diff --git a/input/kh2/drops/remembrance.toml b/input/kh2/drops/remembrance.toml new file mode 100644 index 0000000..2c6c1ed --- /dev/null +++ b/input/kh2/drops/remembrance.toml @@ -0,0 +1,45 @@ +kind = "remembrance" + +[[shard]] +from = "Beffudler" +chance = 6 + +[[shard]] +from = "Iron Hammer" +chance = 10 + +[[shard]] +from = "Camo Cannon" +chance = 6 + +[[stone]] +from = "Aerial Viking" +chance = 6 + +[[stone]] +from = "Magic Phantom" +chance = 10 + +[[stone]] +from = "Lance Warrior" +chance = 10 + +[[stone]] +from = "Necromancer" +chance = 10 + +[[gem]] +from = "Spring Metal" +chance = 10 + +[[gem]] +from = "Runemaster" +chance = 10 + +[[gem]] +from = "Mad Ride" +chance = 12 + +[[crystal]] +from = "Reckless" +chance = 12 diff --git a/input/kh2/drops/serenity.toml b/input/kh2/drops/serenity.toml new file mode 100644 index 0000000..d576d62 --- /dev/null +++ b/input/kh2/drops/serenity.toml @@ -0,0 +1,81 @@ +kind = "serenity" + +[[shard]] +from = "Assault Rider" +chance = 4 + +[[shard]] +from = "Creeper" +chance = 2 + +[[shard]] +from = "Fat Bandit" +chance = 4 + +[[shard]] +from = "Graveyard" +chance = 4 + +[[shard]] +from = "Hot Rod" +chance = 4 + +[[shard]] +from = "Large Body" +chance = 4 + +[[shard]] +from = "Toy Soldier" +chance = 4 + +[[stone]] +from = "Crimson Jazz" +chance = 4 + +[[stone]] +from = "Devastator" +chance = 4 + +[[stone]] +from = "Dusk" +chance = 2 + +[[stone]] +from = "Living Bone" +chance = 4 + +[[stone]] +from = "Morning Star" +chance = 4 + +[[gem]] +from = "Dancer" +chance = 4 + +[[gem]] +from = "Dragoon" +chance = 4 + +[[gem]] +from = "Gambler" +chance = 4 + +[[gem]] +from = "Sniper" +chance = 4 + +[[crystal]] +from = "Assassin" +chance = 4 + +[[crystal]] +from = "Berserker" +chance = 4 + +[[crystal]] +from = "Samurai" +chance = 4 + +[[crystal]] +from = "Sorcerer" +chance = 4 diff --git a/input/kh2/drops/twilight.toml b/input/kh2/drops/twilight.toml new file mode 100644 index 0000000..33a8d7d --- /dev/null +++ b/input/kh2/drops/twilight.toml @@ -0,0 +1,21 @@ +kind = "twilight" + +[[shard]] +from = "Dusk" +chance = 10 + +[[shard]] +from = "Gambler" +chance = 12 + +[[stone]] +from = "Dancer" +chance = 12 + +[[gem]] +from = "Assassin" +chance = 12 + +[[crystal]] +from = "Sorcerer" +chance = 12 diff --git a/src/kh2.rs b/src/kh2.rs new file mode 100644 index 0000000..2803dba --- /dev/null +++ b/src/kh2.rs @@ -0,0 +1,68 @@ +use std::path::PathBuf; + +use rinja::Template; +use serde::Deserialize; + +use crate::create_file; + +#[derive(Debug, Deserialize, PartialEq, Eq)] +pub struct MaterialDrops { + kind: String, + shard: Vec, + stone: Vec, + gem: Vec, + crystal: Vec, +} + +impl MaterialDrops { + fn drops(&self, kind: &str) -> &[EnemyDrop] { + match kind { + x if x == "shard" => &self.shard, + x if x == "stone" => &self.stone, + x if x == "gem" => &self.gem, + x if x == "crystal" => &self.crystal, + _ => &self.shard, + } + } +} + +#[derive(Debug, Deserialize, PartialEq, Eq)] +pub struct EnemyDrop { + from: String, + chance: u8, +} + +#[derive(Template)] +#[template(path = "pages/kh2/drops.html")] +struct DropsTemplate { + pub drops: Vec, +} + +const DROPS_PATH: &str = "./input/kh2/drops"; + +pub fn init() { + tracing::info!("Loading enemy drops data from {}", DROPS_PATH); + let mut drops: Vec = vec![]; + // Loading multiple files into one vector due to the size of each board + let paths = std::fs::read_dir(DROPS_PATH) + .unwrap() + .filter_map(|f| f.ok()) + .map(|f| f.path()) + .filter_map(|p| match p.extension().map_or(false, |e| e == "toml") { + true => Some(p), + false => None, + }) + .collect::>(); + + for path in paths { + let drops_str = std::fs::read_to_string(path).unwrap(); + let enemy_drops = toml::from_str::(&drops_str).unwrap(); + drops.push(enemy_drops); + } + drops.sort_by(|a, b| a.kind.cmp(&b.kind)); + + tracing::info!("Generating the KH2 drops template"); + let drops_template = DropsTemplate { drops }; + + create_file("./out/kh2", "drops", drops_template.render().unwrap()).unwrap(); +} diff --git a/src/main.rs b/src/main.rs index 195e917..f6c30ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,9 @@ mod bbs; #[cfg(feature = "ddd")] mod ddd; +#[cfg(feature = "kh2")] +mod kh2; + #[cfg(feature = "kh3")] mod kh3; @@ -36,6 +39,9 @@ fn main() { #[cfg(feature = "ddd")] ddd::init(); + #[cfg(feature = "kh2")] + kh2::init(); + #[cfg(feature = "kh3")] kh3::init(); } diff --git a/templates/macros/kh2/macros.html b/templates/macros/kh2/macros.html new file mode 100644 index 0000000..a42f875 --- /dev/null +++ b/templates/macros/kh2/macros.html @@ -0,0 +1,24 @@ +{% macro drop(label) %} +
+ +

{{ category.kind|capitalize +}} {{+ label|capitalize }}

+
+
+ {% for drop in category.drops(label) %} +
+ + {{ drop.from +}} + {{+ drop.chance }}% +
+ {% endfor %} +
+{% endmacro %} diff --git a/templates/pages/kh2/drops.html b/templates/pages/kh2/drops.html new file mode 100644 index 0000000..0843c28 --- /dev/null +++ b/templates/pages/kh2/drops.html @@ -0,0 +1,38 @@ +{% extends "layouts/base.html" %} +{% import "macros/kh2/macros.html" as macros %} + +{% block title %}KH2 - Drops{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} + + {% for category in drops %} + {% call macros::drop("shard") %} + {% call macros::drop("stone") %} + {% call macros::drop("gem") %} + {% call macros::drop("crystal") %} + {% endfor %} +{% endblock %}