Files
0ad/binaries/data/mods/public/globalscripts/StatusEffects.js
T
wraitii c1ddc0c4b9 Internationalise Damage Types and Status Effects using (optional) JSON files.
.json files in simulation/data/template/helpers/damage_types and
status_effects will be used to internationalise damage types and status
effects, as well as share common text.
Fixes the order of damage types being inconsistent.

Add the possibility for i10n xml extractor to set a custom context.

Fixes #4801
Related to D2296.

Featuring work from: Freagarach

Differential Revision: https://code.wildfiregames.com/D2337
This was SVN commit r23681.
2020-05-20 17:26:37 +00:00

45 lines
1.2 KiB
JavaScript

/**
* 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 = {};
let files = Engine.ListDirectoryFiles("simulation/data/template_helpers/status_effects", "*.json", false);
for (let filename of files)
{
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;
}
}
/**
* @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 (!templateData && this.statusEffectData[code])
return this.statusEffectData[code];
if (this.statusEffectData[code])
return Object.assign({}, this.statusEffectData[code], templateData);
return templateData;
}
}