fix count

This commit is contained in:
NilsUeter
2025-04-18 11:56:22 +02:00
parent 8a7cbf7f14
commit d197a804ca
2 changed files with 41 additions and 7 deletions
+4
View File
@@ -1239,6 +1239,10 @@ const makeKeywordsBold = (text) => {
); );
} }
} }
// replace words wrapped in ^^ ^^ with <strong> tags
newValue = newValue.replace(/\^\^([^\^]+)\^\^/g, "<strong>$1</strong>");
// replace two newlines with one but only if there are two newlines in a row // replace two newlines with one but only if there are two newlines in a row
return newValue.replace(/\n\n+/g, "\n\n"); return newValue.replace(/\n\n+/g, "\n\n");
}; };
+35 -5
View File
@@ -21,7 +21,7 @@ ChartJS.register(
); );
export const ShortSummaryTable = ({ force, primaryColor, name, points }) => { export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
const [hide, setHide] = useState(true); const [hide, setHide] = useState(false);
const { units, factionRules, rules, catalog } = force; const { units, factionRules, rules, catalog } = force;
const sortedUnits = units.sort((a, b) => { const sortedUnits = units.sort((a, b) => {
@@ -158,7 +158,7 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
fontWeight: 600, fontWeight: 600,
}} }}
> >
Wounds W
</div> </div>
<div <div
className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right" className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right"
@@ -184,19 +184,49 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
</div> </div>
<div className="table-row-group" style={{ lineHeight: 1.05 }}> <div className="table-row-group" style={{ lineHeight: 1.05 }}>
{sortedUnits.map((unit, index) => { {sortedUnits.map((unit, index) => {
const { name, cost, models } = unit; const {
const count = name,
cost,
models,
modelStats,
abilities,
rangedWeapons,
meleeWeapons,
} = unit;
let count =
models?.filter((model) => model.count > 0)?.length === 1 models?.filter((model) => model.count > 0)?.length === 1
? models?.[0]?.count || 1 ? models?.[0]?.count || 1
: 1; : 1;
if (modelStats?.length === 1) {
// sum of all counts of the models
count =
models?.reduce((sum, model) => sum + model.count, 0) || 1;
}
return ( return (
<div <div
key={name + index} key={name + index}
className={`table-row ${index % 2 === 0 ? "" : "bg-[#c4c4c480]"}`} className={`table-row ${index % 2 === 0 ? "" : "bg-[#c4c4c480]"}`}
> >
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1"> <div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1">
<div className="flex flex-wrap items-center gap-2 gap-y-1">
{count > 1 ? `${count}x ` : ""} {count > 1 ? `${count}x ` : ""}
{name} {name}
{abilities?.Abilities?.keys()?.some(
(key) => key === "Leader",
) && (
<span
style={{
fontSize: ".8em",
fontWeight: 700,
color: "var(--primary-color)",
textTransform: "uppercase",
lineHeight: 1.05,
}}
>
[Leader]
</span>
)}
</div>
</div> </div>
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right"> <div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
{unit.modelStats?.reduce((sum, stat, index) => { {unit.modelStats?.reduce((sum, stat, index) => {
@@ -284,7 +314,7 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
})} })}
<div className="table-row bg-[var(--primary-color)] font-bold text-white"> <div className="table-row bg-[var(--primary-color)] font-bold text-white">
<div className="table-cell border border-[var(--primary-color)] px-4 py-1"> <div className="table-cell border border-[var(--primary-color)] px-4 py-1">
Total {sortedUnits.length} Units
</div> </div>
<div className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right"> <div className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right">
{/* Sum of all wound values */} {/* Sum of all wound values */}