Differential D1103 Diff 4548 ps/trunk/binaries/data/mods/public/simulation/components/DataTemplateManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/DataTemplateManager.js
/** | /** | ||||
* System component which loads the technology and the aura data files | * System component which loads the technology and the aura data files | ||||
*/ | */ | ||||
function DataTemplateManager() {} | function DataTemplateManager() {} | ||||
DataTemplateManager.prototype.Schema = | DataTemplateManager.prototype.Schema = | ||||
"<a:component type='system'/><empty/>"; | "<a:component type='system'/><empty/>"; | ||||
DataTemplateManager.prototype.Init = function() | DataTemplateManager.prototype.Init = function() | ||||
{ | { | ||||
this.technologiesPath = "simulation/data/technologies/"; | |||||
this.aurasPath = "simulation/data/auras/"; | |||||
this.allTechs = {}; | this.allTechs = {}; | ||||
this.allAuras = {}; | this.allAuras = {}; | ||||
for (let techName of this.ListAllTechs()) | for (let techName of this.ListAllTechs()) | ||||
this.GetTechnologyTemplate(techName); | this.GetTechnologyTemplate(techName); | ||||
for (let auraName of this.ListAllAuras()) | for (let auraName of this.ListAllAuras()) | ||||
this.GetAuraTemplate(auraName); | this.GetAuraTemplate(auraName); | ||||
deepfreeze(this.allTechs); | deepfreeze(this.allTechs); | ||||
deepfreeze(this.allAuras); | deepfreeze(this.allAuras); | ||||
}; | }; | ||||
DataTemplateManager.prototype.GetTechnologyTemplate = function(template) | DataTemplateManager.prototype.GetTechnologyTemplate = function(template) | ||||
{ | { | ||||
if (!this.allTechs[template]) | if (!this.allTechs[template]) | ||||
{ | { | ||||
this.allTechs[template] = Engine.ReadJSONFile("simulation/data/technologies/" + template + ".json"); | this.allTechs[template] = Engine.ReadJSONFile(this.technologiesPath + template + ".json"); | ||||
if (!this.allTechs[template]) | if (!this.allTechs[template]) | ||||
error("Failed to load technology \"" + template + "\""); | error("Failed to load technology \"" + template + "\""); | ||||
} | } | ||||
return this.allTechs[template]; | return this.allTechs[template]; | ||||
}; | }; | ||||
DataTemplateManager.prototype.GetAuraTemplate = function(template) | DataTemplateManager.prototype.GetAuraTemplate = function(template) | ||||
{ | { | ||||
if (!this.allAuras[template]) | if (!this.allAuras[template]) | ||||
{ | { | ||||
this.allAuras[template] = Engine.ReadJSONFile("simulation/data/auras/" + template + ".json"); | this.allAuras[template] = Engine.ReadJSONFile(this.aurasPath + template + ".json"); | ||||
if (!this.allAuras[template]) | if (!this.allAuras[template]) | ||||
error("Failed to load aura \"" + template + "\""); | error("Failed to load aura \"" + template + "\""); | ||||
} | } | ||||
return this.allAuras[template]; | return this.allAuras[template]; | ||||
}; | }; | ||||
DataTemplateManager.prototype.ListAllTechs = function() | DataTemplateManager.prototype.ListAllTechs = function() | ||||
{ | { | ||||
return Engine.FindJSONFiles("technologies", true); | return Engine.ListDirectoryFiles(this.technologiesPath, "*.json", true).map(file => file.slice(this.technologiesPath.length, -".json".length)); | ||||
}; | }; | ||||
DataTemplateManager.prototype.ListAllAuras = function() | DataTemplateManager.prototype.ListAllAuras = function() | ||||
{ | { | ||||
return Engine.FindJSONFiles("auras", true); | return Engine.ListDirectoryFiles(this.aurasPath, "*.json", true).map(file => file.slice(this.aurasPath.length, -".json".length)); | ||||
}; | }; | ||||
DataTemplateManager.prototype.GetAllTechs = function() | DataTemplateManager.prototype.GetAllTechs = function() | ||||
{ | { | ||||
return this.allTechs; | return this.allTechs; | ||||
}; | }; | ||||
DataTemplateManager.prototype.TechFileExists = function(template) | DataTemplateManager.prototype.TechFileExists = function(template) | ||||
{ | { | ||||
return Engine.DataFileExists("technologies/" + template + ".json"); | return Engine.DataFileExists("technologies/" + template + ".json"); | ||||
}; | }; | ||||
Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager); | Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager); |
Wildfire Games · Phabricator