From f6b45bcaac0be256eac0834139a00919ffdb7984 Mon Sep 17 00:00:00 2001 From: NilsUeter Date: Fri, 13 Oct 2023 12:20:20 +0200 Subject: [PATCH] always show modelStats to see weapon loadouts --- index.html | 6 +++++- src/10th/Roster.jsx | 46 ++++++++++++++++++++++--------------------- src/roster40k-10th.js | 5 +++-- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 58b5a0f..3cddc17 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,11 @@ /> diff --git a/src/10th/Roster.jsx b/src/10th/Roster.jsx index bd9e472..6a09f07 100644 --- a/src/10th/Roster.jsx +++ b/src/10th/Roster.jsx @@ -120,6 +120,25 @@ const Unit = ({ unit, index, catalog, onePerPage, forceRules }) => { } }, []); + const areAllModelsTheSame = (modelStats) => { + if (modelStats.length === 1) return true; + const firstModel = modelStats[0]; + return modelStats.every( + (model) => + model.move === firstModel.move && + model.toughness === firstModel.toughness && + model.save === firstModel.save && + model.wounds === firstModel.wounds && + model.leadership === firstModel.leadership && + model.oc === firstModel.oc && + model.bs === firstModel.bs && + model.ws === firstModel.ws && + model.attacks === firstModel.attacks + ); + }; + if (areAllModelsTheSame(modelStats)) { + modelStats = [modelStats[0]]; + } return (
{ modelList={modelList} index={index} showName={modelStats.length > 1} - showWeapons={ - modelList.length > 1 || modelList[0].includes("x ") // show Weapons when multiple weapons of same type, for example (2x Atomiser Beam, Reanimator's Claws) - } /> ))}
@@ -417,37 +433,23 @@ const Unit = ({ unit, index, catalog, onePerPage, forceRules }) => { ); }; -const ModelStats = ({ modelStat, index, showName, showWeapons, modelList }) => { +const ModelStats = ({ modelStat, index, showName, modelList }) => { let { move, toughness, save, wounds, leadership, name, oc, bs, ws, attacks } = modelStat; if (!wounds) { wounds = "/"; } - if (!name.includes("Sgt")) { - modelList = modelList.filter((model) => !model.includes("Sgt")); - } - if (!name.includes("Sergeant")) { - modelList = modelList.filter((model) => !model.includes("Sergeant")); - } - let modelListMatches = modelList.filter((model) => - model.includes(name + " w") - ); - if (modelListMatches.length === 0) { - modelListMatches = modelList.filter((model) => model.includes(name)); - } - modelListMatches = modelListMatches.map((model) => - model.replaceAll(name, "") - ); + const showWeapons = index === 0; return ( -
+
-
+
{showName && (
{ fontSize: "0.7em", }} > - {modelListMatches.map((model, index) => ( + {modelList.map((model, index) => (
{model}
))}
diff --git a/src/roster40k-10th.js b/src/roster40k-10th.js index 886e76c..850fbd9 100644 --- a/src/roster40k-10th.js +++ b/src/roster40k-10th.js @@ -198,6 +198,7 @@ export class Model extends BaseNotes { getDedupedWeaponsAndUpgrades() { const deduped = []; + for (const upgrade of [ ...this.rangedWeapons, ...this.meleeWeapons, @@ -833,7 +834,7 @@ function ParseUnit(root) { const unitUpgradesModel = new Model(); unitUpgradesModel.name = "Unit Upgrades"; ParseModelProfiles(unseenProfiles, unitUpgradesModel, unit); - if (unitUpgradesModel.meleeWeapons.length > 0 && unit.models.length > 0) { + /* if (unitUpgradesModel.meleeWeapons.length > 0 && unit.models.length > 0) { // Apply weapons at the unit level to all models in the unit. for (const model of unit.models) { model.meleeWeapons.push(...unitUpgradesModel.meleeWeapons); @@ -846,7 +847,7 @@ function ParseUnit(root) { model.rangedWeapons.push(...unitUpgradesModel.rangedWeapons); } unitUpgradesModel.rangedWeapons.length = 0; // Clear the array. - } + } */ if (unitUpgradesModel.psychicPowers.length > 0) { // Add spells to the unit's spell list. However, we'll still need // to add spell upgrade selections to the upgrade list, below.