Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/attributes/Landscape.js
- This file was added.
GameSettings.prototype.Attributes.Landscape = class extends GameSetting | |||||
{ | |||||
Init() | |||||
{ | |||||
this.data = undefined; | |||||
this.value = undefined; | |||||
this.settings.map.watch(() => this.onMapChange(), ["map"]); | |||||
} | |||||
LegacySerialize(attribs) | |||||
{ | |||||
if (this.value) | |||||
attribs.settings.Landscape = this.value; | |||||
} | |||||
onMapChange() | |||||
{ | |||||
if (!this.getMapSetting("Landscapes")) | |||||
{ | |||||
this.value = undefined; | |||||
this.data = undefined; | |||||
return; | |||||
} | |||||
// TODO: validation | |||||
this.data = this.getMapSetting("Landscapes"); | |||||
this.value = "random"; | |||||
} | |||||
setValue(val) | |||||
{ | |||||
// TODO: validation. | |||||
this.value = val; | |||||
} | |||||
getPreviewFilename() | |||||
{ | |||||
if (!this.value) | |||||
return undefined; | |||||
for (let group of this.data) | |||||
for (let item of group.Items) | |||||
if (item.Id == this.value) | |||||
return item.Preview; | |||||
return undefined; | |||||
} | |||||
pickRandomItems() | |||||
{ | |||||
if (!this.value || this.value.startsWith("random")) | |||||
return false; | |||||
let items = []; | |||||
if (this.value.indexOf("_") !== -1) | |||||
{ | |||||
let subgroup = this.value.substr(this.value.indexOf("_")+1); | |||||
subgroup = this.data.find(x => x.Id == subgroup); | |||||
items = subgroup.map(x => x.Id); | |||||
} | |||||
else | |||||
items = this.data.map(x => x.Items.map(item => item.Id)); | |||||
this.value = pickRandom(items); | |||||
return true; | |||||
} | |||||
}; |
Wildfire Games · Phabricator