From a0e006dbbe5eb7a59b39d2407cfcfa6596e532ca Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 8 Oct 2022 12:46:11 +0000 Subject: [PATCH] Fix victory conditions loading (fixes Hero Garrison in regicide crashloop). VictoryConditions.js gamesetting sends multiple updates to 'active' and 'disabled', instead of just one single update at the end. This is listened to by amongst others the regicide 'hero garrison' setting, thus `HeroGarrison` is deactivated, and then tries to be reactivated from the init attributes, and then disabled again later. This implements a simple fix, VictoryConditions only sends a single update in FromInitAttributes with the end-state. Differential Revision: https://code.wildfiregames.com/D4793 This was SVN commit r27135. --- .../attributes/VictoryConditions.js | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js b/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js index 2ba3cfa1ac..6ecb764c9b 100644 --- a/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js +++ b/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js @@ -17,9 +17,11 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex for (let cond of conditions) this.conditions[cond.Name] = cond; + let defaults = []; for (let cond in this.conditions) if (this.conditions[cond].Default) - this._add(this.conditions[cond].Name); + defaults.push(this.conditions[cond].Name); + this._add(this.active, this.disabled, defaults); } toInitAttributes(attribs) @@ -50,11 +52,7 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex if (!conditionList) return; - this.disabled = new Set(); - this.active = new Set(); - // TODO: could be optimised. - for (const cond of conditionList) - this._add(cond); + this._add(new Set(), new Set(), conditionList); } _reconstructDisabled(active) @@ -67,24 +65,27 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex return disabled; } - _add(name) + _add(currentActive, currentDisabled, names) { - if (this.disabled.has(name)) - return; - let active = clone(this.active); - active.add(name); - // Assume we want to remove incompatible ones. - if (this.conditions[name].DisabledWhenChecked) - this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x)); + let active = clone(currentActive); + for (const name of names) { + if (currentDisabled.has(name)) + continue; + active.add(name); + // Assume we want to remove incompatible ones. + if (this.conditions[name].DisabledWhenChecked) + this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x)); + } // TODO: sanity check this.disabled = this._reconstructDisabled(active); this.active = active; } - _delete(name) + _delete(names) { let active = clone(this.active); - active.delete(name); + for (const name of names) + active.delete(name); // TODO: sanity check this.disabled = this._reconstructDisabled(active); this.active = active; @@ -93,8 +94,8 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex setEnabled(name, enabled) { if (enabled) - this._add(name); + this._add(this.active, this.disabled, [name]); else - this._delete(name); + this._delete([name]); } };