0ad/binaries/data/mods/public/globalscripts/ModificationTemplates.js
elexis c90d72deb5 Replace DataTemplateManager simulation component with a globalscript, refs #4868.
Removes the serialization of JSON files, shrinking savegame files and
rejoin states sent across the network, refs #3834, #4239, #3909,
f24523dc8f.
Removes the AI C++ code to read JSON files from e33d4a52e9 since the AI
can now use the globalscript.
Allows the AI to read Aura templates and removal of GUIInterface code to
improve performance.
Serialization of the JSON objects in other simulation components was
removed in 9c0e37f2c0 / D1109, a6f14f5631 / D1130.

Serialization removal planned by sanderd17
AI part proofread by mimo
Simulation part proofread by bb
Discussed with Itms on irc

Differential Revision: https://code.wildfiregames.com/D1108
This was SVN commit r20737.
2017-12-31 01:02:21 +00:00

45 lines
1 KiB
JavaScript

/**
* @file This provides a cache for Aura and Technology templates.
* They may not be serialized, otherwise rejoined clients would refer
* to different objects, triggering an Out-of-sync error.
*/
function ModificationTemplates(path)
{
let suffix = ".json";
this.names = deepfreeze(listFiles(path, suffix, true));
this.templates = {};
for (let name of this.names)
this.templates[name] = Engine.ReadJSONFile(path + name + suffix);
deepfreeze(this.templates);
}
ModificationTemplates.prototype.GetNames = function()
{
return this.names;
};
ModificationTemplates.prototype.Has = function(name)
{
return this.names.indexOf(name) != -1;
};
ModificationTemplates.prototype.Get = function(name)
{
return this.templates[name];
};
ModificationTemplates.prototype.GetAll = function()
{
return this.templates;
};
function LoadModificationTemplates()
{
global.AuraTemplates = new ModificationTemplates("simulation/data/auras/");
global.TechnologyTemplates = new ModificationTemplates("simulation/data/technologies/");
}