Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/attributes/Daytime.js
- This file was added.
GameSettings.prototype.Attributes.Daytime = class extends GameSetting | |||||
{ | |||||
Init() | |||||
{ | |||||
this.data = undefined; | |||||
this.value = undefined; | |||||
this.settings.map.watch(() => this.onMapChange(), ["map"]); | |||||
} | |||||
LegacySerialize(attribs) | |||||
{ | |||||
if (this.value) | |||||
attribs.settings.Daytime = this.value; | |||||
} | |||||
LegacyDeserialize(attribs) | |||||
{ | |||||
if (!this.getLegacySetting(attribs, "Daytime")) | |||||
this.setValue(undefined); | |||||
else | |||||
this.setValue(this.getLegacySetting(attribs, "Daytime")); | |||||
} | |||||
onMapChange() | |||||
{ | |||||
let mapData = this.settings.map.data; | |||||
if (!mapData || !mapData.settings || !mapData.settings.Daytime) | |||||
{ | |||||
this.value = undefined; | |||||
this.data = undefined; | |||||
return; | |||||
} | |||||
// TODO: validation | |||||
this.data = mapData.settings.Daytime; | |||||
this.value = "random"; | |||||
} | |||||
setValue(val) | |||||
{ | |||||
// TODO: validation. | |||||
this.value = val; | |||||
} | |||||
pickRandomItems() | |||||
{ | |||||
if (this.value !== "random") | |||||
return false; | |||||
this.value = pickRandom(this.data).Id; | |||||
return true; | |||||
} | |||||
}; |
Wildfire Games · Phabricator