forked from mirrors/0ad
9cb0a60d73
This reveals unintentional modifications to these objects which would most often imply hidden bugs. Differential Revision: https://code.wildfiregames.com/D829 Fixes #4257 Refs #3647 This was SVN commit r20100.
64 lines
1.5 KiB
JavaScript
64 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);
|
|
|
|
deepfreeze(this.allTechs);
|
|
deepfreeze(this.allAuras);
|
|
};
|
|
|
|
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);
|