Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/attributes/Map.js
- This file was added.
GameSettings.prototype.Attributes.Map = class Map extends GameSetting | |||||
{ | |||||
Init() | |||||
{ | |||||
this.watch(() => this.updateMapMetadata(), ["map"]); | |||||
this.map = undefined; | |||||
this.type = undefined; | |||||
this.script = undefined; | |||||
this.randomOptions = []; | |||||
} | |||||
LegacySerialize(attribs) | |||||
{ | |||||
attribs.map = this.map; | |||||
attribs.mapType = this.type; | |||||
if (this.script) | |||||
attribs.script = this.script; | |||||
if (!this.data) | |||||
return; | |||||
// Some map attributes cannot be changed but are required | |||||
// copy them explicitly. | |||||
let copy = ["CircularMap", | |||||
"StartingCamera", | |||||
"Garrison", | |||||
// Copy the map name so that the replay menu doesn't have to load hundreds of map descriptions on init | |||||
// Also it allows determining the english mapname from the replay file if the map is not available. | |||||
// TODO: this should probably be moved out of settings and into the core engine bit. | |||||
"Name"]; | |||||
for (let property of copy) | |||||
if (this.data.settings[property] !== undefined) | |||||
attribs.settings[property] = this.data.settings[property]; | |||||
} | |||||
LegacyDeserialize(attribs) | |||||
{ | |||||
if (attribs.mapType) | |||||
this.setType(attribs.mapType); | |||||
if (!attribs.map) | |||||
return; | |||||
this.selectMap(attribs.map); | |||||
} | |||||
setType(mapType) | |||||
{ | |||||
this.type = mapType; | |||||
} | |||||
selectMap(map) | |||||
{ | |||||
this.data = this.mapCache.getMapData(this.type, map); | |||||
this.map = map; | |||||
} | |||||
updateMapMetadata() | |||||
{ | |||||
if (this.type == "random" && this.data) | |||||
this.script = this.data.settings.Script; | |||||
else | |||||
this.script = undefined; | |||||
} | |||||
pickRandomItems() | |||||
{ | |||||
if (this.map !== "random") | |||||
return false; | |||||
this.selectMap(pickRandom(this.randomOptions)); | |||||
return true; | |||||
} | |||||
setRandomOptions(options) | |||||
{ | |||||
this.randomOptions = clone(options); | |||||
if (this.randomOptions.indexOf("random") !== -1) | |||||
this.randomOptions.splice(this.randomOptions.indexOf("random"), 1); | |||||
} | |||||
}; |
Wildfire Games · Phabricator