Big overhaul and balancing, fix export

This commit is contained in:
Dandaedre 2026-07-21 06:48:47 +02:00
parent 2235357925
commit 483dc1003f
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
9 changed files with 185 additions and 46 deletions

View File

@ -50,7 +50,7 @@ pub struct WeaponConfig {
pub target: ExportTarget,
/// The path to export to
#[arg(short, long, default_value = "./Craft/")]
#[arg(short, long, default_value = "./Craft")]
pub export: String,
#[arg(long, default_value_t = String::from("safe"))]

View File

@ -81,14 +81,7 @@ fn create_graphs(args: &AnalysisConfig, config: &Config, filter: DynamicFilterTy
}
Err(e) => panic!("{e}"),
}
// if args.html_export{}
refined_list.write_html(&save_path).unwrap();
// if args.csv_export{}
// export_as_csv(&refined_list, &save_path);
// if args.tex_export{}
// export_as_tex(&refined_list, &save_path);
}
#[allow(dead_code)]

View File

@ -0,0 +1,54 @@
// Workspace: weaponry
// File: weaponry/src/export_tex.rs
//! Module regrouping all generic function related to the exporting as tex
//!
use std::fs;
use std::io::Write;
use crate::interfaces::ToTex;
use crate::weaponry_structs::equipement_scenario::ConfigEquipementScenario;
use crate::{interfaces::Scenario, weaponry_structs::RefinedEquipementList};
use cli_parser::Config;
use config::analysis::WeaponConfig;
use crate::{error::WeaponGenerationError, weaponry_structs::CrossRecipeScenario};
/// Export as a tex file in the given directory
///
/// Generic function dispatching any specific demand to different functions
/// TODO: FINISH IMPLEMENTATION
pub fn export_as_tex(refined_list: &RefinedEquipementList, config: &Config, save_path: &str) {
let _ = save_path;
println!("{}", refined_list.to_tex(config).unwrap()); // TexType
// println!(
// "Saved initial data as {}.html: {:?}",
// save_path,
// refined_list.write_csv(Path::new(&format!("{save_path}.csv")))
// );
}
/// Export all weapon database as a tex data
pub fn export_weapons(args: &WeaponConfig, config: &Config) -> Result<(), WeaponGenerationError> {
let scenarios = CrossRecipeScenario::new_with_config(ConfigEquipementScenario {
table_name: "Equipements".into(),
db_path: config.data_generation.database.clone(),
shape: Some(()),
materials: None,
nature: Some(()), //(!args.no_natures).then_some(()),
finishing: None, //args.finishing.then_some(()),
})
.unwrap();
// let filter = Box::new(|_: &RefinedEquipement| true);
let refined_list = scenarios.generate_refined_recipes().unwrap();
// .inner_filter(filter);
let tex = refined_list.to_tex(config).unwrap();
let name = format!("{}gen-forge-table.tex", args.export);
println!("Writing to file {name}");
let mut f = fs::File::create(name).unwrap();
writeln!(f, "{}", tex).unwrap();
Ok(())
}

View File

@ -20,7 +20,8 @@ use crate::{
export::{initial_chart, initial_plot_chart},
interfaces::{RecipeCollection, RefinedList, ToAnalysis},
weaponry_structs::{
Equipement, InitialEquipementList,
Equipement, InitialEquipementList, WeaponBaseShape,
equipement_fields::WeaponBaseSize,
equipement_structs::InnerEquipementStats,
equipement_thin_types::{Dices, Precision},
},
@ -54,6 +55,7 @@ pub struct RefinedEquipementList {
#[derive(Serialize)]
pub struct ExportableEquipement {
pub name: String,
pub category: Option<WeaponBaseShape>,
pub maniement: String,
pub damage_base: i8,
pub damage_per: i8,
@ -64,10 +66,48 @@ pub struct ExportableEquipement {
pub torque_one_handed: Option<i8>,
pub torque_two_handed: Option<i8>,
pub modes: String,
pub esquive: String,
pub parrade: String,
pub vitesse: String,
pub discretion: String,
pub difficulty: String,
pub special: String,
pub needs_break: bool,
}
impl From<&RefinedEquipement> for ExportableEquipement {
fn from(value: &RefinedEquipement) -> Self {
let mut special = Vec::new();
if value.inner.action_cost != 0 && value.inner.action_cost != 1 {
special.push(format!(r"{}A", value.inner.action_cost));
}
if let Some(cost) = value.inner.reload_cost {
special.push(format!(r"{cost}\reload{{}}"));
};
if value.inner.armor_pierce != 0 {
let mut parmure = value.inner.armor_pierce;
match (&value.inner.category_base, &value.inner.category_size) {
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::Heavy)) => parmure += 1,
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::SuperHeavy)) => parmure += 1,
_ => (),
}
special.push(format!(r"\Gls{{parmure}} {parmure}"));
}
if value.inner.range != 0 {
let mut range = value.inner.range;
match (&value.inner.category_base, &value.inner.category_size) {
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::Heavy)) => range += 30,
(&Some(WeaponBaseShape::Ranged), Some(WeaponBaseSize::SuperHeavy)) => range += 60,
_ => (),
}
special.push(format!(r"{range}m"));
}
if value.inner.precision != 0 {
special.push(format!(
r"\glssymbol{{precision}} {:+}",
value.inner.precision
));
}
Self {
name: value.advanced.display_name.clone(),
maniement: value.inner.get_maniement(),
@ -80,6 +120,14 @@ impl From<&RefinedEquipement> for ExportableEquipement {
torque_one_handed: value.inner.torque_one_handed,
torque_two_handed: value.inner.torque_two_handed,
modes: value.inner.get_modes(),
esquive: value.inner.dodge.to_string(),
parrade: value.inner.parry.to_string(),
vitesse: value.inner.speed.to_string(),
discretion: value.inner.stealth.to_string(),
difficulty: value.inner.difficulty.to_string(),
category: value.inner.category_base,
special: special.join(", "),
needs_break: false,
}
}
}
@ -290,7 +338,7 @@ pub struct AdvancedStats {
}
impl From<&InnerEquipementStats> for AdvancedStats {
fn from(value: &InnerEquipementStats) -> Self {
let max_damage_per_attack = (value.damage + value.p_damage * (value.rmax)) as f64;
let max_damage_per_attack = (value.damage + value.p_damage * (value.rmax - 1)) as f64;
let armor_break_per_attack =
(value.armor_break as f64 + value.antimaterial as f64).min(max_damage_per_attack);
let variance = (value.p_damage * value.rmax) as f64;

View File

@ -293,7 +293,8 @@ pub(super) fn binomial_dice_distribution(
+ equipement.p_damage as f64
* (target_dices
.saturating_sub(1)
.clamp(0, equipement.rmax as usize)) as f64)
.clamp(0, (equipement.rmax - 1) as usize))
as f64)
* probability_success
} else {
0.

View File

@ -60,9 +60,9 @@ impl PhysicalDamageType {
/// Get a exportable representation
pub fn export(&self) -> String {
match self {
PhysicalDamageType::Blunt => "\\contondant".to_string(),
PhysicalDamageType::Slash => "\\tranchant".to_string(),
PhysicalDamageType::Pierce => "\\percant".to_string(),
PhysicalDamageType::Blunt => "\\blunt".to_string(),
PhysicalDamageType::Slash => "\\slash".to_string(),
PhysicalDamageType::Pierce => "\\pierce".to_string(),
}
}
}
@ -91,8 +91,8 @@ impl DamageMod {
pub fn export(&self) -> String {
match self {
DamageMod::Primary(phy) => phy.export(),
DamageMod::Secondary(phy) => format!(r"\[{}\]", phy.export()),
DamageMod::Tertiary(phy) => format!(r"\[\[{}\]\]", phy.export()),
DamageMod::Secondary(phy) => format!(r"[{}]", phy.export()),
DamageMod::Tertiary(phy) => format!(r"[[{}]]", phy.export()),
}
}
@ -282,8 +282,9 @@ pub enum EquipementSerializedCategory {
// : This should replace the used MacroCategory
/// The Base Shape of the weapon, used to infer the final category of the weapon
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, strum::EnumString, Default)]
#[cfg_attr(test, derive(PartialEq))]
#[derive(
Copy, Clone, Debug, Display, Deserialize, Serialize, strum::EnumString, Default, PartialEq,
)]
pub enum WeaponBaseShape {
Staves,
Blunt,

View File

@ -10,7 +10,8 @@
use super::equipement_structs::InnerEquipementStats;
use crate::interfaces::{FilterFunction, Reportable};
use crate::weaponry_structs::{DamageMod, SpecialField, WeaponBaseShape};
use crate::weaponry_structs::equipement_fields::WeaponBaseSize;
use crate::weaponry_structs::{SpecialField, WeaponBaseShape};
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
use std::{
fmt::{Debug, Display},
@ -228,6 +229,23 @@ macro_rules! first_correct_option {
};
}
/// Fixing the french grammar in the worst way possible
fn stupid_adjective_fix(name_base: &str, adj: String) -> String {
let plur = || format!("{adj}s");
let masc = || match adj.as_str() {
"moyenne" => "moyen".to_owned(),
"légère" => "léger".to_owned(),
_ => adj[..adj.len() - 1].to_string(),
};
match name_base {
"Griffes" => plur(),
"Hast" => masc(),
"Marteau" => masc(),
"Arc" => masc(),
"Bouclier" => masc(),
_ => adj,
}
}
impl std::ops::Add for &InnerEquipementStats {
type Output = InnerEquipementStats;
@ -237,7 +255,7 @@ impl std::ops::Add for &InnerEquipementStats {
name: add_to_vec!(
self.name,
if let Some(ad) = &rhs.adjective {
vec![ad.clone()]
vec![stupid_adjective_fix(&self.name[0], ad.clone())]
} else {
rhs.name.clone()
}
@ -296,15 +314,26 @@ impl std::ops::Add for SpecialField {
impl InnerEquipementStats {
/// Get the maniement as a printable string
pub fn get_maniement(&self) -> String {
match &self.category_base {
Some(c) => match c {
WeaponBaseShape::Staves => "Hast".to_string(),
WeaponBaseShape::Blunt => "Contondante".to_string(),
WeaponBaseShape::Slash => "Tranchante".to_string(),
WeaponBaseShape::Ranged => "Distance".to_string(),
match &self.category_size {
Some(WeaponBaseSize::SuperHeavy) => match self.name[0].as_str() {
"Griffes" => "Frienzä",
"Marteau" => "Rhödarak",
"Épée" => "Haroth",
"Hache" => "Kahml",
"Hast" => "Paysagiste",
"Arc" => "Distance",
"Arbalète" => "Distance",
_ => "-",
}
.to_string(),
_ => match &self.category_base {
Some(WeaponBaseShape::Staves) => "Hast".to_string(),
Some(WeaponBaseShape::Blunt) => "Contondante".to_string(),
Some(WeaponBaseShape::Slash) => "Tranchante".to_string(),
Some(WeaponBaseShape::Ranged) => "Distance".to_string(),
_ => "-".to_string(),
},
None => "-".to_string(),
}
}
/// Get the modes as a printable string

View File

@ -27,15 +27,21 @@ impl ToTex for RefinedEquipementList {
fn to_tex(&self, config: &Config) -> Result<String, FatalEquipementError> {
let mut template = Handlebars::new();
template.register_template_string("weapons", &config.weapons.template)?;
let r = template.render(
"weapons",
&self
.iter()
.map(|v| v.into())
.collect::<Vec<ExportableEquipement>>(),
)?;
println!("{}", r);
Ok(String::new())
let mut data = self
.iter()
.map(std::convert::Into::<ExportableEquipement>::into)
.collect::<Vec<ExportableEquipement>>();
for i in 0..data.len() - 1 {
if data[i].category != data[i + 1].category
&& data[i + 1].category == Some(super::WeaponBaseShape::Shields)
{
data[i].needs_break = true;
}
}
let r = template.render("weapons", &data)?;
// println!("{}", r);
Ok(r)
}
}

View File

@ -155,7 +155,7 @@ common_part = '''
cell{1}{1}={c=2}{c},
}
{{#if image}}\includegraphics[height=5cm]{ {{{image}}} } & \\ {{/if}}
{{#if image}}\includegraphics[height=5cm]{ {{{~image~}}} } & \\ {{/if}}
& \\
Nom & {{{name}}} \\
{{#if denomination}}Dénomination & {{{denomination}}} \\
@ -229,7 +229,7 @@ master_part = '''
\SetCell{c} Res & \slash & \pierce & \blunt & \symceleste & \symfire & \symearth & \symwood & \symmagma & \symabyss & \symwater & \symwind & \symice & \symthunder \\
\hline
{{#each body_parts.body_parts}}
\SetCell{font=\footnotesize} {{{body_part_name}}} & ${{{slash}}} $ & ${{{pierce}}} $ & ${{{blunt}}} $ & ${{{celestial}}} $ & ${{{fire}}} $ & ${{{earth}}} $ & ${{{wood}}} $ & ${{{magma}}} $ & ${{{celeste}}} $ & ${{{water}}} $ & ${{{wind}}} $ & ${{{ice}}} $ & ${{{thunder}}} $ \\
\SetCell{font=\footnotesize} {{{body_part_name}}} & ${{{slash}}} $ & ${{{pierce}}} $ & ${{{blunt}}} $ & ${{{celestial}}} $ & ${{{fire}}} $ & ${{{earth}}} $ & ${{{wood}}} $ & ${{{magma}}} $ & ${{{celeste}}} $ & ${{{water}}} $ & ${{{wind}}} $ & ${{{ice}}} $ & ${{{thunder}}} $ \\
{{/each}}
\end{tblr}
\end{center}
@ -262,16 +262,16 @@ master_part = '''
hspan=minimal,
colsep=2pt,
row{2}={font=\tiny},
rowshead=2,
rowhead=2,
}
& & & & & \SetCell[c=2]{c} Coûts & & & \SetCell[c=2]{c} Dégâts & & & \SetCell[c=2]{c} Seuils & \\
\cline{6-7} \cline{9-10} \cline{12-13}
{{#each all_attacks.phases as | phase |}}
\SetHline{1}{0pt}
{{#if @first}}
& {\scriptsize\SetCell{white} \textsc{ {{{@key}}} }} & {Type} & {Préquis} & \rb{Ciblage} & \rb{Fatigue} & \rb{Action} & \rb{Élément} & \rb{Fatigue} & \SetCell{c} \rb{Normaux} & {Effets} & \rb{Parade} & \rb{Esquive} \\
& {\scriptsize\SetCell{white} \textsc{ {{{~@key~}}} }} & {Type} & {Préquis} & \rb{Ciblage} & \rb{Fatigue} & \rb{Action} & \rb{Élément} & \rb{Fatigue} & \SetCell{c} \rb{Normaux} & {Effets} & \rb{Parade} & \rb{Esquive} \\
{{else}}
\SetCell[c=13]{white} \textsc{ {{{@key}}} } & & & & & & & & & & \\
\SetCell[c=13]{white} \textsc{ {{{~@key~}}} } & & & & & & & & & & \\
{{/if}}
{{#each phase as | attack_group |}}
\hline
@ -289,7 +289,7 @@ master_part = '''
{{#with data}}
\pagebreak
\begin{tblr}{
colspec={X[7] {{#if intent_graph}}|X[3] {{/if}} },
colspec={X[7] {{#if intent_graph}}|X[3] {{/if~}} },
rowspec={X[c] X[j,h,8cm]},
hline{2},
row{2}={font=\footnotesize},
@ -334,8 +334,8 @@ default_color=''
[weapons]
template='''
\begin{center}
\begin{tblr}[
\begin{landscape}\begin{center}
\begin{longtblr}[
entry = none,
label = none,
]{
@ -345,15 +345,22 @@ template='''
row{even} = {coblueL},
hspan = minimal, vspan=minimal,
colsep = 2mm, abovesep=0px,belowsep=0px, leftsep=3px, rightsep=3px,
rowhead = 1,
}
\hline
{Forme} & {Maniement} & {\damagew} & + & {R.Max} & \arbreakw & \protection & \integrite & $\mathbb{T}$2 & $\mathbb{T}$1 & {Modes} & {Esq.} & {Par.} & {Vit.} & {Disc.} & {Spécial} & {Diff.} \\
\hline
{{#each this}}
{{name}} & {{maniement}} & {{damage_base}} & {{damage_per}} & {{rmax}} & {{arbreak}} & {{protection}} & {{integrity}} &{{torque_two_handed}} & {{torque_one_handed}} & {{modes}}& {{esquive}} & {{parrade}} & {{vitesse}} & {{discretion}} & {{special}} & {{difficulty}} \\
{{name}} & {{maniement}} & {{damage_base}} & {{damage_per}} & {{rmax}} & {{arbreak}} & {{protection}} & {{integrity}} & {{torque_two_handed}} & {{torque_one_handed}} & $\mathbf{ {{{~modes~}}} }$ & {{esquive}} & {{parrade}} & {{vitesse}} & {{discretion}} & {{{special}}} & \ddlvl{ {{~difficulty~}} } \\
{{#if needs_break}}
\hline
\hline
{{/if}}
{{/each}}
\hline
\end{tblr}
\end{longtblr}
\end{center}
\end{landscape}
'''
# Nom & \rotbx{Rareté} & \rotbx{Dégâts} & + & \rotbx{R.Max} & \rotbx{Armr.B} & \rotbx{Protbx} & \rotbx{Int.} & \rotbx{Deux M} & \rotbx{Une M} & \rotbx{Esq.} & \rotbx{Parr.} & \rotbx{Vitesse} & \rotbx{Discr.} & \rotbx{Catégorie} & \rotbx{Modes} & \rotbx{Spécial} \\