Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/StatusEffects.js
- This file was added.
/** | |||||
* This class provides a cache for accessing status effects metadata stored in JSON files. | |||||
* Note that status effects need not be defined in JSON files to be handled in-game. | |||||
* This class must be initialised before using, as initialising it directly in globalscripts would | |||||
* introduce disk I/O every time e.g. a GUI page is loaded. | |||||
*/ | |||||
class StatusEffectsMetadata | |||||
{ | |||||
constructor() | |||||
{ | |||||
this.statusEffectData = {}; | |||||
for (let filename of Engine.ListDirectoryFiles("simulation/data/template_helpers/status_effects", "*.json", false)) | |||||
{ | |||||
let data = Engine.ReadJSONFile(filename); | |||||
if (!data) | |||||
continue; | |||||
if (data.code in this.statusEffectData) | |||||
{ | |||||
error("Encountered two status effects with the code " + data.code); | |||||
continue; | |||||
} | |||||
this.statusEffectData[data.code] = data; | |||||
} | |||||
this._sort = (a, b) => this.damageTypeData[a].order - this.damageTypeData[b].order; | |||||
} | |||||
/** | |||||
* @returns a copy in sorted order. | |||||
*/ | |||||
sort(damageTypes) | |||||
{ | |||||
let sorted = damageTypes.slice(); | |||||
sorted.sort(this._sort); | |||||
return sorted; | |||||
Stan: Maybe
```lang=js
if (templateData)
return Object.assign(this.statusEffectData[code]… | |||||
Not Done Inline ActionsI think the stored data should take precedence? Freagarach: I think the stored data should take precedence? | |||||
Not Done Inline ActionsI think template data should take precedence. wraitii: I think template data should take precedence. | |||||
} | |||||
wraitiiAuthorUnsubmitted Done Inline Actionsneeds to be nuked. wraitii: needs to be nuked. | |||||
/** | |||||
* @returns the default data for @param code status effects, augmented with the given template data, | |||||
* or simply @param templateData if the code is not found in JSON files. | |||||
*/ | |||||
augment(code, templateData) | |||||
{ | |||||
if (!this.statusEffectData[code]) | |||||
return templateData; | |||||
else if (!templateData && this.statusEffectData[code]) | |||||
return this.statusEffectData[code]; | |||||
else if (!this.statusEffectData[code] && !templateData) | |||||
{ | |||||
error("Unknown status effect code " + code + " and no template data given."); | |||||
return {}; | |||||
} | |||||
return Object.assign(this.statusEffectData[code], templateData); | |||||
} | |||||
} |
Wildfire Games · Phabricator
Maybe