Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/campaigns/default_menu/Difficulty.js
- This file was added.
/** | |||||
* Split off for easier moddability - combines AI & trigger difficulties. | |||||
*/ | |||||
var g_CampaignDifficulties = [ | |||||
{ | |||||
"name": "Very easy", | |||||
"aidiff": 1, | |||||
"triggerdiff": 1 | |||||
}, | |||||
{ | |||||
"name": "Easy", | |||||
"aidiff": 2, | |||||
"triggerdiff": 2 | |||||
}, | |||||
{ | |||||
"name": "Medium", | |||||
"aidiff": 3, | |||||
"triggerdiff": 3 | |||||
}, | |||||
{ | |||||
"name": "Hard", | |||||
"aidiff": 4, | |||||
"triggerdiff": 4 | |||||
}, | |||||
{ | |||||
"name": "Very hard", | |||||
"aidiff": 5, | |||||
"triggerdiff": 5 | |||||
} | |||||
]; | |||||
class CampaignDifficulty | |||||
{ | |||||
constructor(run) | |||||
{ | |||||
this.run = run; | |||||
this.perLevel = this.run.template?.Difficulty === "PerLevel"; | |||||
this.difficulty = this.run?.data?.difficulty ?? 2; // Defaults to 'Medium'. | |||||
this.object = Engine.GetGUIObjectByName("perLevelDifficulty"); | |||||
this.label = Engine.GetGUIObjectByName("perLevelDifficultyLabel"); | |||||
this.input = Engine.GetGUIObjectByName("perLevelDifficultyInput"); | |||||
this.input.onSelectionChange = () => { | |||||
this.difficulty = this.input.selected; | |||||
}; | |||||
} | |||||
isPerLevel() | |||||
{ | |||||
return this.perLevel; | |||||
} | |||||
serialize() | |||||
{ | |||||
this.run.data.difficulty = this.difficulty; | |||||
} | |||||
getAIDifficulty() | |||||
{ | |||||
if (this.input.selected !== -1) | |||||
return g_CampaignDifficulties[this.input.list_data[this.input.selected]].aidiff; | |||||
return 3; // Defaults to medium. | |||||
} | |||||
getTriggerDifficulty() | |||||
{ | |||||
if (this.input.selected !== -1) | |||||
return g_CampaignDifficulties[this.input.list_data[this.input.selected]].triggerdiff; | |||||
return 3; // Defaults to medium. | |||||
} | |||||
render() | |||||
{ | |||||
if (!this.isPerLevel()) | |||||
{ | |||||
this.object.hidden = true; | |||||
return this.object; | |||||
} | |||||
this.object.hidden = false; | |||||
this.label.caption = translate("Difficulty"); | |||||
this.input.list = g_CampaignDifficulties.map(x => x.name); | |||||
this.input.list_data = g_CampaignDifficulties.map((_, i) => i); | |||||
if (this.input.selected === -1 && this.difficulty < this.input.list.length) | |||||
this.input.selected = this.difficulty; | |||||
return this.object; | |||||
} | |||||
} |
Wildfire Games · Phabricator