Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/attributes/MapPreview.js
/** | /** | ||||
* Map Preview. | * Map Preview. | ||||
* Can optionally overwrite the default map preview. | * Can optionally overwrite the default map preview. | ||||
*/ | */ | ||||
GameSettings.prototype.Attributes.MapPreview = class MapPreview extends GameSetting | GameSettings.prototype.Attributes.MapPreview = class MapPreview extends GameSetting | ||||
{ | { | ||||
init() | init() | ||||
{ | { | ||||
this.isDefault = true; | this.isDefault = true; | ||||
this.value = undefined; | |||||
wraitii: This is un-necessary and I don't think it really adds much? Per @Freagarach I believe that we… | |||||
Done Inline ActionsIs necessary bb: Is necessary | |||||
Not Done Inline Actions(Also not defining undefined properties is mostly in the sim, for stuff that gets serialised.) Freagarach: (Also not defining undefined properties is mostly in the sim, for stuff that gets serialised.) | |||||
Not Done Inline Actions
There's an error in onFinalizeAttributes otherwise? Storing undefined values in that object seems like not the greatest idea since JSON cannot represent those. wraitii: > Is necessary
There's an error in onFinalizeAttributes otherwise? Storing undefined values in… | |||||
Done Inline ActionsAs one might notice, there are checks in the toInitAttributes, checking for undefined stuff bb: As one might notice, there are checks in the toInitAttributes, checking for undefined stuff | |||||
this.settings.map.watch(() => this.updatePreview(), ["map"]); | this.settings.map.watch(() => this.updatePreview(), ["map"]); | ||||
this.settings.biome.watch(() => this.updatePreview(), ["biome"]); | this.settings.biome.watch(() => this.updatePreview(), ["biome"]); | ||||
this.settings.landscape.watch(() => this.updatePreview(), ["value"]); | this.settings.landscape.watch(() => this.updatePreview(), ["value"]); | ||||
this.settings.daytime.watch(() => this.updatePreview(), ["value"]); | this.settings.daytime.watch(() => this.updatePreview(), ["value"]); | ||||
} | } | ||||
toInitAttributes(attribs) | toInitAttributes(attribs) | ||||
{ | { | ||||
// TODO: this shouldn't be persisted, only serialised for the game proper. | if (this.value !== undefined) | ||||
if (this.value) | attribs.settings.mapPreview = this.value; | ||||
attribs.mapPreview = this.value; | |||||
} | } | ||||
fromInitAttributes(attribs) | fromInitAttributes(attribs) | ||||
{ | { | ||||
// For now - this won't be deserialized or persisted match settings will be problematic. | if (!!this.getLegacySetting(attribs, "mapPreview")) | ||||
Done Inline ActionsThis can just as well be persisted, if there are several map previews which we can scroll through, we should persist it. bb: This can just as well be persisted, if there are several map previews which we can scroll… | |||||
Not Done Inline ActionsSee my comment about loading order, essentially, but doing so possibly requires a "deserialise-don't validate or update anything" step that is not implemented at the moment, or softcoding in the loading code. wraitii: See my comment about loading order, essentially, but doing so possibly requires a "deserialise… | |||||
this.value = this.getLegacySetting(attribs, "mapPreview"); | |||||
} | } | ||||
getPreviewForSubtype(basepath, subtype) | getPreviewForSubtype(basepath, subtype) | ||||
{ | { | ||||
if (!subtype) | if (!subtype) | ||||
return undefined; | return undefined; | ||||
let substr = subtype.substr(subtype.lastIndexOf("/") + 1); | let substr = subtype.substr(subtype.lastIndexOf("/") + 1); | ||||
let path = basepath + "_" + substr + ".png"; | let path = basepath + "_" + substr + ".png"; | ||||
Show All 26 Lines | updatePreview() | ||||
// This handles "random" map type (mostly for convenience). | // This handles "random" map type (mostly for convenience). | ||||
let mapPath = basename(this.settings.map.map); | let mapPath = basename(this.settings.map.map); | ||||
this.value = this.getPreviewForSubtype(mapPath, this.settings.biome.biome) || | this.value = this.getPreviewForSubtype(mapPath, this.settings.biome.biome) || | ||||
this.getLandscapePreview() || | this.getLandscapePreview() || | ||||
this.getPreviewForSubtype(mapPath, this.settings.daytime.value) || | this.getPreviewForSubtype(mapPath, this.settings.daytime.value) || | ||||
this.settings.mapCache.getMapPreview(this.settings.map.type, this.settings.map.map); | this.settings.mapCache.getMapPreview(this.settings.map.type, this.settings.map.map); | ||||
} | } | ||||
setCustom(preview) | |||||
{ | |||||
this.isDefault = false; | |||||
this.value = preview; | |||||
} | |||||
}; | }; |
Wildfire Games · Phabricator
This is un-necessary and I don't think it really adds much? Per @Freagarach I believe that we try to avoid defining properties un-necessarily.