Differential D3243 Diff 16503 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/Biome.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/Biome.js
GameSettingControls.Biome = class extends GameSettingControlDropdown | GameSettingControls.Biome = class Biome extends GameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.values = undefined; | g_NewGameSettings.biome.watch(() => this.render(), ["biome", "available"]); | ||||
this.biomeValues = undefined; | this.render(); | ||||
this.randomItem = { | |||||
"Id": this.RandomBiomeId, | |||||
"Title": setStringTags(this.RandomBiome, this.RandomItemTags), | |||||
"Autocomplete": this.RandomBiome, | |||||
"Description": this.RandomDescription | |||||
}; | |||||
} | } | ||||
onHoverChange() | onHoverChange() | ||||
{ | { | ||||
this.dropdown.tooltip = | if (!this.dropdown.list_data[this.dropdown.hovered]) | ||||
this.values && this.values.Description && this.values.Description[this.dropdown.hovered] || | this.dropdown.tooltip = ""; | ||||
this.Tooltip; | else if (this.dropdown.list_data[this.dropdown.hovered] == "random") | ||||
} | this.dropdown.tooltip = this.RandomDescription; | ||||
onMapChange(mapData) | |||||
{ | |||||
let available = g_GameAttributes.mapType == "random" && | |||||
mapData && mapData.settings && mapData.settings.SupportedBiomes || undefined; | |||||
this.setHidden(!available); | |||||
if (available) | |||||
{ | |||||
Engine.ProfileStart("updateBiomeList"); | |||||
this.biomeValues = | |||||
g_Settings.Biomes.filter(this.filterBiome(available)).map(this.createBiomeItem); | |||||
this.values = prepareForDropdown([ | |||||
this.randomItem, | |||||
...this.biomeValues | |||||
]); | |||||
this.dropdown.list = this.values.Title; | |||||
this.dropdown.list_data = this.values.Id; | |||||
Engine.ProfileStop(); | |||||
} | |||||
else | else | ||||
this.values = undefined; | this.dropdown.tooltip = g_NewGameSettings.biome.biomeData[ | ||||
this.dropdown.list_data[this.dropdown.hovered] | |||||
} | ].Description; | ||||
onGameAttributesChange() | |||||
{ | |||||
if (!g_GameAttributes.mapType || !g_GameAttributes.map) | |||||
return; | |||||
if (this.values) | |||||
{ | |||||
if (this.values.Id.indexOf(g_GameAttributes.settings.Biome || undefined) == -1) | |||||
{ | |||||
g_GameAttributes.settings.Biome = this.RandomBiomeId; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
let biomePreviewFile = | |||||
basename(g_GameAttributes.map) + "_" + | |||||
basename(g_GameAttributes.settings.Biome || "") + ".png"; | |||||
if (!g_GameAttributes.settings.Preview || g_GameAttributes.settings.Preview != biomePreviewFile && Engine.TextureExists(this.mapCache.TexturesPath + this.mapCache.PreviewsPath + biomePreviewFile)) | |||||
g_GameAttributes.settings.Preview = biomePreviewFile; | |||||
} | |||||
else if (g_GameAttributes.settings.Biome) | |||||
{ | |||||
delete g_GameAttributes.settings.Biome; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | } | ||||
onGameAttributesBatchChange() | render() | ||||
{ | { | ||||
if (this.values) | this.setHidden(!g_NewGameSettings.biome.available.size); | ||||
this.setSelectedValue(g_GameAttributes.settings.Biome); | |||||
} | |||||
filterBiome(available) | let values = prepareForDropdown([ | ||||
{ | { | ||||
if (typeof available == "string") | "Title": setStringTags(this.RandomBiome, this.RandomItemTags), | ||||
return biome => biome.Id.startsWith(available); | "Id": "random" | ||||
}, | |||||
...g_NewGameSettings.biome.getAvailableBiomeData() | |||||
]); | |||||
return biome => available.indexOf(biome.Id) != -1; | this.dropdown.list = values.Title; | ||||
} | this.dropdown.list_data = values.Id; | ||||
createBiomeItem(biome) | this.setSelectedValue(g_NewGameSettings.biome.biome); | ||||
{ | |||||
return { | |||||
"Id": biome.Id, | |||||
"Title": biome.Title, | |||||
"Autocomplete": biome.Title, | |||||
"Description": biome.Description | |||||
}; | |||||
} | } | ||||
getAutocompleteEntries() | getAutocompleteEntries() | ||||
{ | { | ||||
return this.values && this.values.Autocomplete; | return g_NewGameSettings.biome.biomes; | ||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
g_GameAttributes.settings.Biome = this.values.Id[itemIdx]; | g_NewGameSettings.biome.setBiome(this.dropdown.list_data[itemIdx]); | ||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
onPickRandomItems() | |||||
{ | |||||
if (this.values && g_GameAttributes.settings.Biome == this.RandomBiomeId) | |||||
{ | |||||
g_GameAttributes.settings.Biome = pickRandom(this.biomeValues).Id; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.pickRandomItems(); | |||||
} | |||||
} | |||||
}; | }; | ||||
GameSettingControls.Biome.prototype.TitleCaption = | GameSettingControls.Biome.prototype.TitleCaption = | ||||
translate("Biome"); | translate("Biome"); | ||||
GameSettingControls.Biome.prototype.RandomBiomeId = | GameSettingControls.Biome.prototype.RandomBiomeId = | ||||
"random"; | "random"; | ||||
Show All 10 Lines |
Wildfire Games · Phabricator