Differential D4793 Diff 20936 ps/trunk/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gamesettings/attributes/VictoryConditions.js
Show All 11 Lines | GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions extends GameSetting | ||||
init() | init() | ||||
{ | { | ||||
this.settings.map.watch(() => this.onMapChange(), ["map"]); | this.settings.map.watch(() => this.onMapChange(), ["map"]); | ||||
let conditions = loadVictoryConditions(); | let conditions = loadVictoryConditions(); | ||||
for (let cond of conditions) | for (let cond of conditions) | ||||
this.conditions[cond.Name] = cond; | this.conditions[cond.Name] = cond; | ||||
let defaults = []; | |||||
for (let cond in this.conditions) | for (let cond in this.conditions) | ||||
if (this.conditions[cond].Default) | 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) | toInitAttributes(attribs) | ||||
{ | { | ||||
attribs.settings.VictoryConditions = Array.from(this.active); | attribs.settings.VictoryConditions = Array.from(this.active); | ||||
} | } | ||||
fromInitAttributes(attribs) | fromInitAttributes(attribs) | ||||
Show All 14 Lines | GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions extends GameSetting | ||||
} | } | ||||
fromList(conditionList) | fromList(conditionList) | ||||
{ | { | ||||
conditionList = conditionList.filter(cond => cond in this.conditions); | conditionList = conditionList.filter(cond => cond in this.conditions); | ||||
if (!conditionList) | if (!conditionList) | ||||
return; | return; | ||||
this.disabled = new Set(); | this._add(new Set(), new Set(), conditionList); | ||||
this.active = new Set(); | |||||
// TODO: could be optimised. | |||||
for (const cond of conditionList) | |||||
this._add(cond); | |||||
} | } | ||||
_reconstructDisabled(active) | _reconstructDisabled(active) | ||||
{ | { | ||||
let disabled = new Set(); | let disabled = new Set(); | ||||
for (let cond of active) | for (let cond of active) | ||||
if (this.conditions[cond].DisabledWhenChecked) | if (this.conditions[cond].DisabledWhenChecked) | ||||
this.conditions[cond].DisabledWhenChecked.forEach(x => disabled.add(x)); | this.conditions[cond].DisabledWhenChecked.forEach(x => disabled.add(x)); | ||||
return disabled; | return disabled; | ||||
} | } | ||||
_add(name) | _add(currentActive, currentDisabled, names) | ||||
{ | { | ||||
if (this.disabled.has(name)) | let active = clone(currentActive); | ||||
return; | for (const name of names) { | ||||
let active = clone(this.active); | if (currentDisabled.has(name)) | ||||
continue; | |||||
active.add(name); | active.add(name); | ||||
// Assume we want to remove incompatible ones. | // Assume we want to remove incompatible ones. | ||||
if (this.conditions[name].DisabledWhenChecked) | if (this.conditions[name].DisabledWhenChecked) | ||||
this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x)); | this.conditions[name].DisabledWhenChecked.forEach(x => active.delete(x)); | ||||
} | |||||
// TODO: sanity check | // TODO: sanity check | ||||
this.disabled = this._reconstructDisabled(active); | this.disabled = this._reconstructDisabled(active); | ||||
this.active = active; | this.active = active; | ||||
} | } | ||||
_delete(name) | _delete(names) | ||||
{ | { | ||||
let active = clone(this.active); | let active = clone(this.active); | ||||
for (const name of names) | |||||
active.delete(name); | active.delete(name); | ||||
// TODO: sanity check | // TODO: sanity check | ||||
this.disabled = this._reconstructDisabled(active); | this.disabled = this._reconstructDisabled(active); | ||||
this.active = active; | this.active = active; | ||||
} | } | ||||
setEnabled(name, enabled) | setEnabled(name, enabled) | ||||
{ | { | ||||
if (enabled) | if (enabled) | ||||
this._add(name); | this._add(this.active, this.disabled, [name]); | ||||
else | else | ||||
this._delete(name); | this._delete([name]); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator