0ad/binaries/data/mods/public/simulation/components/DataTemplateManager.js
elexis d7e51f2a4f Fix an OOS without rejoin after selecting the first unit.
Introduced by 46ead523b8, caused by serializing the aura cache which is
initialized by the tooltip calls from the GUI.
Reviewed by Itms, in combination with 09e775446e fixes #4239.

This was SVN commit r18804.
2016-10-06 14:11:56 +00:00

60 lines
1.5 KiB
JavaScript

/**
* System component which loads the technology and the aura data files
*/
function DataTemplateManager() {}
DataTemplateManager.prototype.Schema =
"<a:component type='system'/><empty/>";
DataTemplateManager.prototype.Init = function()
{
this.allTechs = {};
this.allAuras = {};
for (let techName of this.ListAllTechs())
this.GetTechnologyTemplate(techName);
for (let auraName of this.ListAllAuras())
this.GetAuraTemplate(auraName);
};
DataTemplateManager.prototype.GetTechnologyTemplate = function(template)
{
if (!this.allTechs[template])
{
this.allTechs[template] = Engine.ReadJSONFile("technologies/" + template + ".json");
if (!this.allTechs[template])
error("Failed to load technology \"" + template + "\"");
}
return this.allTechs[template];
};
DataTemplateManager.prototype.GetAuraTemplate = function(template)
{
if (!this.allAuras[template])
{
this.allAuras[template] = Engine.ReadJSONFile("auras/" + template + ".json");
if (!this.allAuras[template])
error("Failed to load aura \"" + template + "\"");
}
return this.allAuras[template];
};
DataTemplateManager.prototype.ListAllTechs = function()
{
return Engine.FindJSONFiles("technologies", true);
};
DataTemplateManager.prototype.ListAllAuras = function()
{
return Engine.FindJSONFiles("auras", true);
};
DataTemplateManager.prototype.GetAllTechs = function()
{
return this.allTechs;
};
Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager);