Skip to content

Commit b872256

Browse files
CopilotAzgaar
andauthored
Fix: Military regiment notes not updated on regeneration with new era/year (#1329)
* Initial plan * Fix: Military notes not updated on regiment or Era data change Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Refactor: update existing regiment note in-place; remove all regiment notes in one pass Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Bump version to 1.112.3 (patch: fix military notes not updated on regen) Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
1 parent 13ec798 commit b872256

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

public/modules/military-generator.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ window.Military = (function () {
246246
const expected = 3 * populationRate; // expected regiment size
247247
const mergeable = (n0, n1) => (!n0.s && !n1.s) || n0.u === n1.u; // check if regiments can be merged
248248

249+
// remove all existing regiment notes before regenerating
250+
for (let i = notes.length - 1; i >= 0; i--) {
251+
if (notes[i].id.startsWith("regiment")) notes.splice(i, 1);
252+
}
253+
249254
// get regiments for each state
250255
valid.forEach(s => {
251256
s.military = createRegiments(s.temp.platoons, s);
@@ -380,7 +385,14 @@ window.Military = (function () {
380385
: gauss(options.year - 100, 150, 1, options.year - 6);
381386
const conflict = campaign ? ` during the ${campaign.name}` : "";
382387
const legend = `Regiment was formed in ${year} ${options.era}${conflict}. ${station}${troops}`;
383-
notes.push({id: `regiment${s.i}-${r.i}`, name: r.name, legend});
388+
const id = `regiment${s.i}-${r.i}`;
389+
const existing = notes.find(n => n.id === id);
390+
if (existing) {
391+
existing.name = r.name;
392+
existing.legend = legend;
393+
} else {
394+
notes.push({id, name: r.name, legend});
395+
}
384396
};
385397

386398
return {

public/versioning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
1414
*/
1515

16-
const VERSION = "1.112.2";
16+
const VERSION = "1.112.3";
1717
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
1818

1919
{

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8494,7 +8494,7 @@
84948494

84958495
<script defer src="config/heightmap-templates.js"></script>
84968496
<script defer src="config/precreated-heightmaps.js"></script>
8497-
<script defer src="modules/military-generator.js?v=1.107.0"></script>
8497+
<script defer src="modules/military-generator.js?v=1.112.3"></script>
84988498
<script defer src="modules/resample.js?v=1.112.1"></script>
84998499
<script defer src="libs/alea.min.js?v1.105.0"></script>
85008500
<script defer src="libs/polylabel.min.js?v1.105.0"></script>

0 commit comments

Comments
 (0)