From ba906ec96682070fceedc513e0a01f1ed9563478 Mon Sep 17 00:00:00 2001 From: Wynd Date: Wed, 4 Mar 2026 02:04:24 +0200 Subject: [PATCH] Fixed melding menu not using the common css and its sorting --- public/styles/bbs/melding.css | 2 ++ src/bbs.rs | 7 ++--- src/bbs/command.rs | 58 +++++++++++++++++++++++++++++++++-- src/bbs/melding.rs | 2 +- src/common.rs | 5 +-- src/common/materials.rs | 2 +- src/kh1.rs | 2 +- 7 files changed, 64 insertions(+), 14 deletions(-) diff --git a/public/styles/bbs/melding.css b/public/styles/bbs/melding.css index aff1e39..098a98d 100644 --- a/public/styles/bbs/melding.css +++ b/public/styles/bbs/melding.css @@ -1,3 +1,5 @@ +@import url("./common.css"); + table { thead { position: sticky; diff --git a/src/bbs.rs b/src/bbs.rs index d62f810..34dc755 100644 --- a/src/bbs.rs +++ b/src/bbs.rs @@ -1,12 +1,12 @@ use std::{ collections::HashMap, - fmt::{self, Display}, + fmt::{self}, str::FromStr, string::ParseError, }; use ability::Abilities; -use askama::{FastWritable, Template, filters::HtmlSafe}; +use askama::Template; use command::Command; use finisher::Finisher; use itertools::Itertools; @@ -23,7 +23,7 @@ pub const ABILITIES_PATH: &str = "./input/bbs/abilities.toml"; const FINISHERS_PATH: &str = "./input/bbs/finishers.toml"; pub const COMMANDS_PATH: &str = "./input/bbs/commands"; -#[derive(Debug, Deserialize, PartialEq, Eq)] +#[derive(Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord)] enum Character { #[serde(alias = "A")] Aqua, @@ -100,7 +100,6 @@ impl RuntimeModule for Module { tracing::info!("Loading BBS commands data from {}", ABILITIES_PATH); let mut commands = Command::import(); - commands.sort_by(|a, b| a.order.cmp(&b.order)); // Create a vec with all the crystal variants found in abilities let crystals = abilities diff --git a/src/bbs/command.rs b/src/bbs/command.rs index 3e7bda9..a1ca843 100644 --- a/src/bbs/command.rs +++ b/src/bbs/command.rs @@ -1,14 +1,35 @@ -use std::path::PathBuf; +use core::fmt; +use std::{cmp, path::PathBuf}; use serde::Deserialize; use super::{COMMANDS_PATH, melding::CommandRecipe}; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[serde(rename_all = "lowercase")] +pub enum CommandCategory { + Attack, + Magic, + Action, + Shotlock, +} + +impl fmt::Display for CommandCategory { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CommandCategory::Attack => f.write_str("attack"), + CommandCategory::Magic => f.write_str("magic"), + CommandCategory::Action => f.write_str("action"), + CommandCategory::Shotlock => f.write_str("shotlock"), + } + } +} + +#[derive(Debug, Deserialize, PartialEq, Eq)] pub struct Command { pub name: String, pub order: u32, - pub category: String, + pub category: CommandCategory, pub char: Vec, #[serde(default)] pub info: Option, @@ -16,6 +37,35 @@ pub struct Command { pub recipes: Vec, } +impl PartialOrd for Command { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Command { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + let self_mod = match self.category { + CommandCategory::Attack => 0, + CommandCategory::Magic => 100, + CommandCategory::Action => 200, + CommandCategory::Shotlock => 300, + }; + + let other_mod = match other.category { + CommandCategory::Attack => 0, + CommandCategory::Magic => 100, + CommandCategory::Action => 200, + CommandCategory::Shotlock => 300, + }; + + let o1 = self.order + self_mod; + let o2 = other.order + other_mod; + + Ord::cmp(&o1, &o2) + } +} + impl Command { pub fn import() -> Vec { let mut commands = vec![]; @@ -36,6 +86,8 @@ impl Command { commands.push(cmd); } + commands.sort(); + commands } } diff --git a/src/bbs/melding.rs b/src/bbs/melding.rs index a995888..6aee45f 100644 --- a/src/bbs/melding.rs +++ b/src/bbs/melding.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use super::{Character, ability::Ability}; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct CommandRecipe { pub char: Vec, pub r#type: char, diff --git a/src/common.rs b/src/common.rs index 454aeef..69e902a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -15,10 +15,7 @@ pub struct GameProps { impl GameProps { pub fn final_mix() -> Self { - Self { - is_final_mix: true, - ..Default::default() - } + Self { is_final_mix: true } } } diff --git a/src/common/materials.rs b/src/common/materials.rs index 642ca90..4ffdfe3 100644 --- a/src/common/materials.rs +++ b/src/common/materials.rs @@ -5,7 +5,7 @@ use serde::Deserialize; use crate::ASSETS_FOLDER_PATH; use super::{ - Game, GameProps, + Game, enemy::{Enemy, EnemyDrop}, }; diff --git a/src/kh1.rs b/src/kh1.rs index 34e6af6..c10436b 100644 --- a/src/kh1.rs +++ b/src/kh1.rs @@ -2,7 +2,7 @@ use askama::Template; use crate::{ RuntimeModule, - common::{Game, drops::Drops, enemy::Enemy, synthesis::Synthesis}, + common::{drops::Drops, synthesis::Synthesis}, create_file, };