Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/attributes/MapName.js
/** | /** | ||||
* Map name. | * Map name. | ||||
* This is usually just the regular map name, but can be overwritten. | * This is usually just the regular map name, but can be overwritten. | ||||
*/ | */ | ||||
GameSettings.prototype.Attributes.MapName = class MapName extends GameSetting | GameSettings.prototype.Attributes.MapName = class MapName extends GameSetting | ||||
{ | { | ||||
init() | init() | ||||
{ | { | ||||
this.value = undefined; | |||||
this.settings.map.watch(() => this.updateName(), ["map"]); | |||||
} | } | ||||
toInitAttributes(attribs) | toInitAttributes(attribs) | ||||
{ | { | ||||
if (this.value) | if (this.value !== undefined) | ||||
attribs.settings.Name = this.value; | attribs.settings.Name = this.value; | ||||
else | |||||
{ | |||||
// Copy from the map data by default - this helps make InitAttributes self-sufficient, | |||||
// which is nice for replays / saved games. | |||||
wraitii: You've lost this particular comment in the rewrite (which I otherwise like), which I think was… | |||||
Done Inline ActionsDon't see how this comment adds anything to the new code. bb: Don't see how this comment adds anything to the new code. | |||||
Not Done Inline ActionsOne could wonder why the name is always stored when it can be deduced from the map default name. The reason is to simplify replay / saved game parsing. wraitii: One could wonder why the name is always stored when it can be deduced from the map default name. | |||||
// Fallback to the map name to avoid 'undefined' errors. | |||||
attribs.settings.Name = this.settings.map?.data?.settings?.Name || this.settings.map.map; | |||||
} | |||||
} | } | ||||
fromInitAttributes(attribs) | fromInitAttributes(attribs) | ||||
{ | { | ||||
// Ser/Deser from a different attribute name as a poor man's not-persisted-setting. | |||||
// TODO: split this off more properly. | |||||
if (attribs.mapName) | if (attribs.mapName) | ||||
this.value = attribs.mapName; | this.value = attribs.mapName; | ||||
} | } | ||||
set(name) | updateName() | ||||
{ | { | ||||
this.value = name; | this.value = this.settings.map?.data?.settings?.Name || this.settings.map.map; | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator
You've lost this particular comment in the rewrite (which I otherwise like), which I think was useful.