Fix sorting order of brackets, show degrading attacks/ different attacks

This commit is contained in:
NilsUeter
2023-05-07 21:02:37 +02:00
parent 5b48dd99e6
commit b11c1c64bc
4 changed files with 39 additions and 22 deletions
+20 -10
View File
@@ -142,9 +142,7 @@ const Unit = ({ unit, catalog }) => {
const rangedWeapons = weapons const rangedWeapons = weapons
.filter((weapon) => weapon.range !== "Melee" && weapon.range !== "-") .filter((weapon) => weapon.range !== "Melee" && weapon.range !== "-")
.sort((a, b) => a.selectionName.localeCompare(b.selectionName)); .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 ( return (
<div <div
className="avoid-page-break" className="avoid-page-break"
@@ -341,7 +339,8 @@ const ModelStats = ({
showWeapons, showWeapons,
modelList, modelList,
}) => { }) => {
let { move, toughness, save, wounds, leadership, name, bs, ws } = modelStat; let { move, toughness, save, wounds, leadership, name, bs, ws, attacks } =
modelStat;
if (!wounds) { if (!wounds) {
wounds = "/"; wounds = "/";
} }
@@ -360,8 +359,22 @@ const ModelStats = ({
modelListMatches = modelListMatches.map((model) => modelListMatches = modelListMatches.map((model) =>
model.replaceAll(name, "") model.replaceAll(name, "")
); );
const degradingStuff = [];
const bsChange = Math.abs(parseInt(modelStats[0].bs, 10) - parseInt(bs, 10)); 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)); 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 ( return (
<div style={{ display: "flex", gap: 16, alignItems: "center" }}> <div style={{ display: "flex", gap: 16, alignItems: "center" }}>
@@ -395,8 +408,7 @@ const ModelStats = ({
))} ))}
</div> </div>
)} )}
{name.toLowerCase().includes("wounds remaining") && {degradingStuff.length > 0 && (
(bsChange !== 0 || wsChange !== 0) && (
<div <div
style={{ style={{
whiteSpace: "normal", whiteSpace: "normal",
@@ -404,11 +416,9 @@ const ModelStats = ({
fontSize: "0.7em", fontSize: "0.7em",
}} }}
> >
{` Each time this model makes {`Each time this model makes
an attack, subtract an attack, subtract
${bsChange ? `${bsChange} from the balistic skill` : ""} ${degradingStuff.join(" and ")}.`}
${bsChange !== 0 && wsChange !== 0 ? " and " : ""}
${wsChange ? `${wsChange} from the weapon skill` : ""}.`}
</div> </div>
)} )}
</div> </div>
+1 -1
View File
@@ -228,7 +228,7 @@ const Weapon = ({ weapon, modelStats, isMelee, className }) => {
}} }}
> >
{differentProfiles && selectionName + " - "} {differentProfiles && selectionName + " - "}
{name} {differentProfiles ? name.replaceAll(selectionName, "") : name}
{type && ( {type && (
<span <span
style={{ style={{
+1 -1
View File
@@ -1,5 +1,5 @@
export const Arrow = ( export const Arrow = (
<svg viewBox="0 0 16 8" width={16} height={8} fill="#536766"> <svg viewBox="0 0 16 8" width={16} height={8} fill="var(--primary-color)">
<path d="m0 0h10l6 4-6 4h-10z" /> <path d="m0 0h10l6 4-6 4h-10z" />
</svg> </svg>
); );
+8 -1
View File
@@ -277,7 +277,14 @@ export class Unit extends BaseNotes {
normalize() { normalize() {
// Sort force units by role and name // Sort force units by role and name
this.models.sort(CompareModel); 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) { for (let model of this.models) {
model.normalize(); model.normalize();