diff --git a/modules/ui/battle-screen.js b/modules/ui/battle-screen.js index 6bf2e0c7..53b1e739 100644 --- a/modules/ui/battle-screen.js +++ b/modules/ui/battle-screen.js @@ -608,8 +608,8 @@ class Battle { losses > .05 ? "suffered significant losses" : losses > 0 ? "suffered unsignificant losses" : "left the battle without loss"; - const casualties = Object.keys(r.casualties).map(t => r.casualties[t] ? `${Math.abs(r.casualties[t])} ${t}` : null).filter(c => c).join(", "); - const casualtiesText = casualties ? " Casualties: " + casualties : ""; + const casualties = Object.keys(r.casualties).map(t => r.casualties[t] ? `${Math.abs(r.casualties[t])} ${t}` : null).filter(c => c); + const casualtiesText = casualties.length ? " Casualties: " + list(casualties) + "." : ""; const legend = `\r\n\r\n${battleName} (${options.year} ${options.eraShort}): ${status}. The regiment ${regStatus}.${casualtiesText}`; note.legend += legend; } @@ -631,11 +631,11 @@ class Battle { }() const getSide = (regs, n) => regs.length > 1 ? - `${n ? "regiments" : "forces"} of ${[... new Set(regs.map(r => pack.states[r.state].name))].join(", ")}` : + `${n ? "regiments" : "forces"} of ${list([... new Set(regs.map(r => pack.states[r.state].name))])}` : getAdjective(pack.states[regs[0].state].name) + " " + regs[0].name; const getLosses = casualties => Math.min(rn(casualties * 100), 100); - const legend = `${this.name} took place in ${options.year} ${options.eraShort}. It was fought between ${getSide(this.attackers.regiments, 1)} and ${getSide(this.defenders.regiments, 0)}. The battle ended in ${battleStatus[+P(.7)]}. + const legend = `${this.name} took place in ${options.year} ${options.eraShort}. It was fought between ${getSide(this.attackers.regiments, 1)} and ${getSide(this.defenders.regiments, 0)}. The ${this.type} ended in ${battleStatus[+P(.7)]}. \r\nAttackers losses: ${getLosses(this.attackers.casualties)}%, defenders losses: ${getLosses(this.defenders.casualties)}%`; const id = getNextId("markerElement"); notes.push({id, name:this.name, legend}); diff --git a/modules/utils.js b/modules/utils.js index a7c0328e..7882f37a 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -416,6 +416,12 @@ function getAdjective(string) { // get ordinal out of integer: 1 => 1st const nth = n => n+(["st","nd","rd"][((n+90)%100-10)%10-1]||"th"); +// conjunct array: [A,B,C] => "A, B and C" +function list(array) { + const conjunction = new Intl.ListFormat(window.lang || "en", {style:"long", type:"conjunction"}); + return conjunction.format(array); +} + // split string into 2 almost equal parts not breaking words function splitInTwo(str) { const half = str.length / 2;