From b11c1c64bc6840aaf21bb84ac3e05d15106d0aca Mon Sep 17 00:00:00 2001 From: NilsUeter Date: Sun, 7 May 2023 21:02:37 +0200 Subject: [PATCH] Fix sorting order of brackets, show degrading attacks/ different attacks --- src/Roster.jsx | 48 ++++++++++++++++++++++++++------------------ src/Weapons.jsx | 2 +- src/assets/icons.jsx | 2 +- src/roster40k.js | 9 ++++++++- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/Roster.jsx b/src/Roster.jsx index 234a081..5472e53 100644 --- a/src/Roster.jsx +++ b/src/Roster.jsx @@ -142,9 +142,7 @@ const Unit = ({ unit, catalog }) => { const rangedWeapons = weapons .filter((weapon) => weapon.range !== "Melee" && weapon.range !== "-") .sort((a, b) => a.selectionName.localeCompare(b.selectionName)); - if (!modelStats.some((model) => model.name.includes("wounds remaining)"))) { - modelStats = modelStats.sort((a, b) => b.name.length - a.name.length); // Sort by length of name, so that for example "Primaris Intercessor Sergeant" is before "Primaris Intercessor" - } + return (
{ - let { move, toughness, save, wounds, leadership, name, bs, ws } = modelStat; + let { move, toughness, save, wounds, leadership, name, bs, ws, attacks } = + modelStat; if (!wounds) { wounds = "/"; } @@ -360,8 +359,22 @@ const ModelStats = ({ modelListMatches = modelListMatches.map((model) => model.replaceAll(name, "") ); + + const degradingStuff = []; const bsChange = Math.abs(parseInt(modelStats[0].bs, 10) - parseInt(bs, 10)); + if (bsChange > 0) { + degradingStuff.push(`${bsChange} from the balistic skill`); + } const wsChange = Math.abs(parseInt(modelStats[0].ws, 10) - parseInt(ws, 10)); + if (wsChange > 0) { + degradingStuff.push(`${wsChange} from the weapon skill`); + } + const attacksChange = Math.abs( + parseInt(modelStats[0].attacks, 10) - parseInt(attacks, 10) + ); + if (attacksChange > 0) { + degradingStuff.push(`${attacksChange} from the number of attacks`); + } return (
@@ -395,22 +408,19 @@ const ModelStats = ({ ))}
)} - {name.toLowerCase().includes("wounds remaining") && - (bsChange !== 0 || wsChange !== 0) && ( -
- {` Each time this model makes + {degradingStuff.length > 0 && ( +
+ {`Each time this model makes an attack, subtract - ${bsChange ? `${bsChange} from the balistic skill` : ""} - ${bsChange !== 0 && wsChange !== 0 ? " and " : ""} - ${wsChange ? `${wsChange} from the weapon skill` : ""}.`} -
- )} + ${degradingStuff.join(" and ")}.`} +
+ )}
); }; diff --git a/src/Weapons.jsx b/src/Weapons.jsx index c5bb7cb..86b28dc 100644 --- a/src/Weapons.jsx +++ b/src/Weapons.jsx @@ -228,7 +228,7 @@ const Weapon = ({ weapon, modelStats, isMelee, className }) => { }} > {differentProfiles && selectionName + " - "} - {name} + {differentProfiles ? name.replaceAll(selectionName, "") : name} {type && ( + ); diff --git a/src/roster40k.js b/src/roster40k.js index 066d9f2..5552192 100644 --- a/src/roster40k.js +++ b/src/roster40k.js @@ -277,7 +277,14 @@ export class Unit extends BaseNotes { normalize() { // Sort force units by role and name this.models.sort(CompareModel); - this.modelStats.sort(CompareObj); + this.modelStats.sort((a, b) => { + if (!a.wounds) return 1; + var wounds_order = parseInt(a.wounds) - parseInt(b.wounds); + var leadership_order = parseInt(a.leadership) - parseInt(b.leadership); + return ( + -wounds_order || -leadership_order || b.name.length - a.name.length + ); + }); for (let model of this.models) { model.normalize();