forked from mirrors/0ad
876b035336
Differential Revision: D2908 Reviewed by: @wraitii Comments by: @bb. This was SVN commit r24162.
69 lines
1.6 KiB
JavaScript
69 lines
1.6 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/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] = {
|
|
"applierTooltip": data.applierTooltip || "",
|
|
"code": data.code,
|
|
"icon": data.icon || "default",
|
|
"statusName": data.statusName || "data.code",
|
|
"receiverTooltip": data.receiverTooltip || ""
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {string} code - The code of the Status Effect.
|
|
* @return {Object} - The JSON data corresponding to the code.
|
|
*/
|
|
getData(code)
|
|
{
|
|
if (this.statusEffectData[code])
|
|
return this.statusEffectData[code];
|
|
|
|
warn("No status effects data found for: " + code + ".");
|
|
return {};
|
|
}
|
|
|
|
getApplierTooltip(code)
|
|
{
|
|
return this.getData(code).applierTooltip;
|
|
}
|
|
|
|
getIcon(code)
|
|
{
|
|
return this.getData(code).icon;
|
|
}
|
|
|
|
getName(code)
|
|
{
|
|
return this.getData(code).statusName;
|
|
}
|
|
|
|
getReceiverTooltip(code)
|
|
{
|
|
return this.getData(code).receiverTooltip;
|
|
}
|
|
}
|