Differential D3243 Diff 16503 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/VictoryConditionCheckbox.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/VictoryConditionCheckbox.js
/** | /** | ||||
* This is an abstract class instantiated per defined VictoryCondition. | * This is an abstract class instantiated per defined VictoryCondition. | ||||
*/ | */ | ||||
class VictoryConditionCheckbox extends GameSettingControlCheckbox | class VictoryConditionCheckbox extends GameSettingControlCheckbox | ||||
{ | { | ||||
constructor(victoryCondition, ...args) | constructor(victoryCondition, ...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.victoryCondition = victoryCondition; | this.victoryCondition = victoryCondition.Name; | ||||
this.setTitle(victoryCondition.Title); | |||||
this.setTooltip(victoryCondition.Description); | |||||
this.setTitle(this.victoryCondition.Title); | g_NewGameSettings.victoryConditions.watch(() => this.render(), ["active"]); | ||||
this.setTooltip(this.victoryCondition.Description); | g_NewGameSettings.map.watch(() => this.render(), ["type"]); | ||||
this.render(); | |||||
} | } | ||||
onMapChange(mapData) | render() | ||||
{ | { | ||||
let mapIndex = | this.setEnabled(g_NewGameSettings.map.type != "scenario" && | ||||
mapData && | !g_NewGameSettings.victoryConditions.disabled.has(this.victoryCondition)); | ||||
mapData.settings && | this.setChecked(g_NewGameSettings.victoryConditions.active.has(this.victoryCondition)); | ||||
mapData.settings.VictoryConditions && | |||||
mapData.settings.VictoryConditions.indexOf(this.victoryCondition.Name); | |||||
if (mapIndex === undefined) | |||||
return; | |||||
let index = | |||||
g_GameAttributes.settings && | |||||
g_GameAttributes.settings.VictoryConditions && | |||||
g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name); | |||||
if (index !== undefined && (mapIndex == -1) == (index == -1)) | |||||
return; | |||||
if (!g_GameAttributes.settings.VictoryConditions) | |||||
g_GameAttributes.settings.VictoryConditions = []; | |||||
if (mapIndex == -1) | |||||
{ | |||||
if (index !== undefined) | |||||
g_GameAttributes.settings.VictoryConditions.splice(index, 1); | |||||
} | |||||
else | |||||
g_GameAttributes.settings.VictoryConditions.push(this.victoryCondition.Name); | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
onGameAttributesChange() | |||||
{ | |||||
if (!g_GameAttributes.settings.VictoryConditions) | |||||
{ | |||||
g_GameAttributes.settings.VictoryConditions = []; | |||||
for (let victoryCondition of g_VictoryConditions) | |||||
if (victoryCondition.Default) | |||||
g_GameAttributes.settings.VictoryConditions.push(victoryCondition.Name); | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
onGameAttributesBatchChange() | |||||
{ | |||||
this.setEnabled( | |||||
g_GameAttributes.mapType != "scenario" && | |||||
(!this.victoryCondition.DisabledWhenChecked || | |||||
this.victoryCondition.DisabledWhenChecked.every(name => | |||||
g_GameAttributes.settings.VictoryConditions.indexOf(name) == -1))); | |||||
this.setChecked(g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name) != -1); | |||||
} | } | ||||
onPress(checked) | onPress(checked) | ||||
{ | { | ||||
let victoryCondition = new Set(g_GameAttributes.settings.VictoryConditions); | g_NewGameSettings.victoryConditions.setEnabled(this.victoryCondition, checked); | ||||
if (checked) | |||||
{ | |||||
victoryCondition.add(this.victoryCondition.Name); | |||||
if (this.victoryCondition.ChangeOnChecked) | |||||
for (let name in this.victoryCondition.ChangeOnChecked) | |||||
if (this.victoryCondition.ChangeOnChecked[name]) | |||||
victoryCondition.add(name); | |||||
else | |||||
victoryCondition.delete(name); | |||||
} | |||||
else | |||||
victoryCondition.delete(this.victoryCondition.Name); | |||||
g_GameAttributes.settings.VictoryConditions = Array.from(victoryCondition); | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
onGameAttributesFinalize() | |||||
{ | |||||
if (!g_GameAttributes.settings.TriggerScripts) | |||||
g_GameAttributes.settings.TriggerScripts = []; | |||||
if (g_GameAttributes.settings.VictoryConditions.indexOf(this.victoryCondition.Name) != -1) | |||||
for (let script of this.victoryCondition.Scripts) | |||||
if (g_GameAttributes.settings.TriggerScripts.indexOf(script) == -1) | |||||
g_GameAttributes.settings.TriggerScripts.push(script); | |||||
} | |||||
} | } |
Wildfire Games · Phabricator