always show modelStats to see weapon loadouts

This commit is contained in:
NilsUeter
2023-10-13 12:20:20 +02:00
parent af9a990a3f
commit f6b45bcaac
3 changed files with 32 additions and 25 deletions
+4
View File
@@ -16,7 +16,11 @@
/> />
<script> <script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]); !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
// if localhost then return
if(window.location.hostname !== 'localhost')
{
posthog.init('phc_QqImEAwwTBa3yh4DhiQ1bCHWA3DBr3lPuosKNRwSuEq',{api_host:'https://eu.posthog.com'}) posthog.init('phc_QqImEAwwTBa3yh4DhiQ1bCHWA3DBr3lPuosKNRwSuEq',{api_host:'https://eu.posthog.com'})
}
</script> </script>
</head> </head>
<body> <body>
+24 -22
View File
@@ -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 ( return (
<div <div
className={ className={
@@ -246,9 +265,6 @@ const Unit = ({ unit, index, catalog, onePerPage, forceRules }) => {
modelList={modelList} modelList={modelList}
index={index} index={index}
showName={modelStats.length > 1} 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)
}
/> />
))} ))}
</div> </div>
@@ -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 } = let { move, toughness, save, wounds, leadership, name, oc, bs, ws, attacks } =
modelStat; modelStat;
if (!wounds) { if (!wounds) {
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 ( return (
<div style={{ display: "flex", gap: 16, alignItems: "center" }}> <div style={{ display: "flex", gap: 16 }}>
<Characteristic title="M" characteristic={move} index={index} /> <Characteristic title="M" characteristic={move} index={index} />
<Characteristic title="T" characteristic={toughness} index={index} /> <Characteristic title="T" characteristic={toughness} index={index} />
<Characteristic title="SV" characteristic={save} index={index} /> <Characteristic title="SV" characteristic={save} index={index} />
<Characteristic title="W" characteristic={wounds} index={index} /> <Characteristic title="W" characteristic={wounds} index={index} />
<Characteristic title="LD" characteristic={leadership} index={index} /> <Characteristic title="LD" characteristic={leadership} index={index} />
<Characteristic title="OC" characteristic={oc} index={index} /> <Characteristic title="OC" characteristic={oc} index={index} />
<div> <div style={{ display: "flex", alignItems: "center" }}>
{showName && ( {showName && (
<div <div
style={{ style={{
@@ -467,7 +469,7 @@ const ModelStats = ({ modelStat, index, showName, showWeapons, modelList }) => {
fontSize: "0.7em", fontSize: "0.7em",
}} }}
> >
{modelListMatches.map((model, index) => ( {modelList.map((model, index) => (
<div key={model}>{model}</div> <div key={model}>{model}</div>
))} ))}
</div> </div>
+3 -2
View File
@@ -198,6 +198,7 @@ export class Model extends BaseNotes {
getDedupedWeaponsAndUpgrades() { getDedupedWeaponsAndUpgrades() {
const deduped = []; const deduped = [];
for (const upgrade of [ for (const upgrade of [
...this.rangedWeapons, ...this.rangedWeapons,
...this.meleeWeapons, ...this.meleeWeapons,
@@ -833,7 +834,7 @@ function ParseUnit(root) {
const unitUpgradesModel = new Model(); const unitUpgradesModel = new Model();
unitUpgradesModel.name = "Unit Upgrades"; unitUpgradesModel.name = "Unit Upgrades";
ParseModelProfiles(unseenProfiles, unitUpgradesModel, unit); 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. // Apply weapons at the unit level to all models in the unit.
for (const model of unit.models) { for (const model of unit.models) {
model.meleeWeapons.push(...unitUpgradesModel.meleeWeapons); model.meleeWeapons.push(...unitUpgradesModel.meleeWeapons);
@@ -846,7 +847,7 @@ function ParseUnit(root) {
model.rangedWeapons.push(...unitUpgradesModel.rangedWeapons); model.rangedWeapons.push(...unitUpgradesModel.rangedWeapons);
} }
unitUpgradesModel.rangedWeapons.length = 0; // Clear the array. unitUpgradesModel.rangedWeapons.length = 0; // Clear the array.
} } */
if (unitUpgradesModel.psychicPowers.length > 0) { if (unitUpgradesModel.psychicPowers.length > 0) {
// Add spells to the unit's spell list. However, we'll still need // Add spells to the unit's spell list. However, we'll still need
// to add spell upgrade selections to the upgrade list, below. // to add spell upgrade selections to the upgrade list, below.