Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/StatusEffects.js
/** | /** | ||||
* This class provides a cache for accessing status effects metadata stored in JSON files. | * 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. | * 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 | * 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. | * introduce disk I/O every time e.g. a GUI page is loaded. | ||||
*/ | */ | ||||
class StatusEffectsMetadata | class StatusEffectsMetadata | ||||
Stan: Can we make this back to a prototype? | |||||
Done Inline ActionsCould, but this is loaded merely once, so not much gain in that. Freagarach: Could, but this is loaded merely once, so not much gain in that. | |||||
{ | { | ||||
constructor() | constructor() | ||||
{ | { | ||||
this.statusEffectData = {}; | this.statusEffectData = {}; | ||||
let files = Engine.ListDirectoryFiles("simulation/data/template_helpers/status_effects", "*.json", false); | let files = Engine.ListDirectoryFiles("simulation/data/template_helpers/status_effects", "*.json", false); | ||||
for (let filename of files) | for (let filename of files) | ||||
{ | { | ||||
let data = Engine.ReadJSONFile(filename); | let data = Engine.ReadJSONFile(filename); | ||||
if (!data) | if (!data) | ||||
continue; | continue; | ||||
if (data.code in this.statusEffectData) | if (data.code in this.statusEffectData) | ||||
{ | { | ||||
error("Encountered two status effects with the code " + data.code); | error("Encountered two status effects with the code " + data.code); | ||||
continue; | continue; | ||||
} | } | ||||
this.statusEffectData[data.code] = data; | this.statusEffectData[data.code] = data; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* @returns the default data for @param code status effects, augmented with the given template data, | * @returns the default data for @param code status effects, augmented with the given template data, | ||||
Done Inline ActionsTo be changed. Freagarach: To be changed. | |||||
* or simply @param templateData if the code is not found in JSON files. | * or simply @param templateData if the code is not found in JSON files. | ||||
*/ | */ | ||||
augment(code, templateData) | augment(code, templateData) | ||||
{ | { | ||||
bbUnsubmitted Done Inline ActionsI guess we can get away with triggering the error here. bb: I guess we can get away with triggering the error here. | |||||
if (!templateData && this.statusEffectData[code]) | if (!templateData && this.statusEffectData[code]) | ||||
return this.statusEffectData[code]; | return this.statusEffectData[code]; | ||||
if (this.statusEffectData[code]) | if (this.statusEffectData[code]) | ||||
return Object.assign({}, this.statusEffectData[code], templateData); | return Object.assign({}, this.statusEffectData[code], templateData); | ||||
return templateData; | return templateData; | ||||
} | } | ||||
getName(code) | |||||
{ | |||||
Done Inline Actionseither the data check is redundant or the above function should return something when not finding the code bb: either the data check is redundant or the above function should return something when not… | |||||
let knownData = this.augment(code); | |||||
return knownData ? knownData.name || code : code; | |||||
FreagarachAuthorUnsubmitted Done Inline ActionsStatusName Freagarach: `StatusName` | |||||
} | |||||
} | } |
Wildfire Games · Phabricator
Can we make this back to a prototype?