Changeset 27135

Timestamp:
Oct 8, 2022, 2:46:11 PM (22 months ago)
Author:
wraitii
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js

    r26933 r27135  
    1818            this.conditions[cond.Name] = cond;
    1919
     20
    2021        for (let cond in this.conditions)
    2122            if (this.conditions[cond].Default)
    22                 this._add(this.conditions[cond].Name);
     23                defaults.push(this.conditions[cond].Name);
     24        this._add(this.active, this.disabled, defaults);
    2325    }
    2426
     
    5153            return;
    5254
    53         this.disabled = new Set();
    54         this.active = new Set();
    55         // TODO: could be optimised.
    56         for (const cond of conditionList)
    57             this._add(cond);
     55        this._add(new Set(), new Set(), conditionList);
    5856    }
    5957
     
    6866    }
    6967
    70     _add(name)
     68    _add()
    7169    {
    72         if (this.disabled.has(name))
    73             return;
    74         let active = clone(this.active);
    75         active.add(name);
    76         // Assume we want to remove incompatible ones.
    77         if (this.conditions[name].DisabledWhenChecked)
    78             this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x));
     70        let active = clone(currentActive);
     71        for (const name of names) {
     72            if (currentDisabled.has(name))
     73                continue;
     74            active.add(name);
     75            // Assume we want to remove incompatible ones.
     76            if (this.conditions[name].DisabledWhenChecked)
     77                this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x));
     78        }
    7979        // TODO: sanity check
    8080        this.disabled = this._reconstructDisabled(active);
     
    8282    }
    8383
    84     _delete(name)
     84    _delete(name)
    8585    {
    8686        let active = clone(this.active);
    87         active.delete(name);
     87        for (const name of names)
     88            active.delete(name);
    8889        // TODO: sanity check
    8990        this.disabled = this._reconstructDisabled(active);
     
    9495    {
    9596        if (enabled)
    96             this._add(name);
     97            this._add();
    9798        else
    98             this._delete(name);
     99            this._delete();
    99100    }
    100101};
Note: See TracChangeset for help on using the changeset viewer.