Index: binaries/data/mods/public/globalscripts/VFS.js =================================================================== --- binaries/data/mods/public/globalscripts/VFS.js +++ binaries/data/mods/public/globalscripts/VFS.js @@ -1,71 +1,65 @@ -/** - * System component which loads the technology and the aura data files - */ -function DataTemplateManager() {} - -DataTemplateManager.prototype.Schema = - ""; - -DataTemplateManager.prototype.Init = function() +function VFS() { this.technologiesPath = "simulation/data/technologies/"; this.aurasPath = "simulation/data/auras/"; - this.allTechs = {}; - this.allAuras = {}; - - for (let techName of this.ListAllTechs()) - this.GetTechnologyTemplate(techName); - - for (let auraName of this.ListAllAuras()) - this.GetAuraTemplate(auraName); + let loadTemplates = (path, templates, templateNames) => + { + templates = {}; + templateNames = []; + for (let filename of Engine.ListDirectoryFiles(path, "*.json", true)) + { + let templateName = filename.slice(path.length, -".json".length); + templateNames.push(templateName); + templates[templateName] = Engine.ReadJSONFile(path + templateName + ".json"); + } + return [deepfreeze(templateNames), deepfreeze(templates)]; + } - deepfreeze(this.allTechs); - deepfreeze(this.allAuras); + [this.techNames, this.allTechs] = loadTemplates(this.technologiesPath); + [this.auraNames, this.allAuras] = loadTemplates(this.aurasPath); }; -DataTemplateManager.prototype.GetTechnologyTemplate = function(template) +VFS.prototype.GetTechnologyNames = function() { - if (!this.allTechs[template]) - { - this.allTechs[template] = Engine.ReadJSONFile(this.technologiesPath + template + ".json"); - if (!this.allTechs[template]) - error("Failed to load technology \"" + template + "\""); - } + return this.techNames; +}; - return this.allTechs[template]; +VFS.prototype.GetAuraNames = function() +{ + return this.auraNames; }; -DataTemplateManager.prototype.GetAuraTemplate = function(template) +VFS.prototype.TechnologyExists = function(template) { - if (!this.allAuras[template]) - { - this.allAuras[template] = Engine.ReadJSONFile(this.aurasPath + template + ".json"); - if (!this.allAuras[template]) - error("Failed to load aura \"" + template + "\""); - } + return this.techNames.indexOf(template) != -1; +}; - return this.allAuras[template]; +VFS.prototype.AuraExists = function(template) +{ + return this.auraNames.indexOf(template) != -1; }; -DataTemplateManager.prototype.ListAllTechs = function() +VFS.prototype.GetTechnology = function(template) { - return Engine.ListDirectoryFiles(this.technologiesPath, "*.json", true).map(file => file.slice(this.technologiesPath.length, -".json".length)); + return this.allTechs[template]; }; -DataTemplateManager.prototype.ListAllAuras = function() +VFS.prototype.GetAura = function(template) { - return Engine.ListDirectoryFiles(this.aurasPath, "*.json", true).map(file => file.slice(this.aurasPath.length, -".json".length)); + return this.allAuras[template]; }; -DataTemplateManager.prototype.GetAllTechs = function() +VFS.prototype.GetAllTechnologies = function() { return this.allTechs; }; -DataTemplateManager.prototype.TechnologyExists = function(template) +VFS.prototype.GetAllAuras = function() { - return !!this.allTechs[template]; + return this.allAuras; }; -Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager); +// The GUI Manager doesn't use VFS functions +if (Engine.ReadJSONFile) + VFS = new VFS(); Index: binaries/data/mods/public/simulation/ai/common-api/gamestate.js =================================================================== --- binaries/data/mods/public/simulation/ai/common-api/gamestate.js +++ binaries/data/mods/public/simulation/ai/common-api/gamestate.js @@ -10,12 +10,12 @@ }; m.GameState.prototype.init = function(SharedScript, state, player) { + this.sharedScript = SharedScript; this.EntCollecNames = SharedScript._entityCollectionsName; this.timeElapsed = SharedScript.timeElapsed; this.circularMap = SharedScript.circularMap; this.templates = SharedScript._templates; - this.techTemplates = SharedScript._techTemplates; this.entities = SharedScript.entities; this.player = player; this.playerData = SharedScript.playersData[this.player]; @@ -24,6 +24,8 @@ this.ceasefireActive = SharedScript.ceasefireActive; this.ceasefireTimeRemaining = SharedScript.ceasefireTimeRemaining; + this.techTemplates = VFS.GetAllTechnologies(); + // get the list of possible phases for this civ: // we assume all of them are researchable from the civil centre this.phases = [{ name: "phase_village" }, { name: "phase_town" }, { name: "phase_city" }]; Index: binaries/data/mods/public/simulation/ai/common-api/shared.js =================================================================== --- binaries/data/mods/public/simulation/ai/common-api/shared.js +++ binaries/data/mods/public/simulation/ai/common-api/shared.js @@ -9,7 +9,6 @@ this._players = Object.keys(settings.players).map(key => settings.players[key]); // TODO SM55 Object.values(settings.players) this._templates = settings.templates; - this._techTemplates = settings.techTemplates; this._entityMetadata = {}; for (let player of this._players) @@ -30,7 +29,6 @@ { return { "players": this._players, - "techTemplates": this._techTemplates, "templatesModifications": this._templatesModifications, "entitiesModifications": this._entitiesModifications, "metadata": this._entityMetadata @@ -44,7 +42,6 @@ m.SharedScript.prototype.Deserialize = function(data) { this._players = data.players; - this._techTemplates = data.techTemplates; this._templatesModifications = data.templatesModifications; this._entitiesModifications = data.entitiesModifications; this._entityMetadata = data.metadata; Index: binaries/data/mods/public/simulation/components/Auras.js =================================================================== --- binaries/data/mods/public/simulation/components/Auras.js +++ binaries/data/mods/public/simulation/components/Auras.js @@ -8,14 +8,15 @@ Auras.prototype.Init = function() { - let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); this.auras = {}; this.affectedPlayers = {}; + for (let name of this.GetAuraNames()) { this.affectedPlayers[name] = []; - this.auras[name] = cmpDataTemplateManager.GetAuraTemplate(name); + this.auras[name] = VFS.GetAura(name); } + // In case of autogarrisoning, this component can be called before ownership is set. // So it needs to be completely initialised from the start. this.Clean(); Index: binaries/data/mods/public/simulation/components/DataTemplateManager.js =================================================================== --- binaries/data/mods/public/simulation/components/DataTemplateManager.js +++ binaries/data/mods/public/simulation/components/DataTemplateManager.js @@ -1,71 +0,0 @@ -/** - * System component which loads the technology and the aura data files - */ -function DataTemplateManager() {} - -DataTemplateManager.prototype.Schema = - ""; - -DataTemplateManager.prototype.Init = function() -{ - this.technologiesPath = "simulation/data/technologies/"; - this.aurasPath = "simulation/data/auras/"; - - 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(this.technologiesPath + 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(this.aurasPath + template + ".json"); - if (!this.allAuras[template]) - error("Failed to load aura \"" + template + "\""); - } - - return this.allAuras[template]; -}; - -DataTemplateManager.prototype.ListAllTechs = function() -{ - return Engine.ListDirectoryFiles(this.technologiesPath, "*.json", true).map(file => file.slice(this.technologiesPath.length, -".json".length)); -}; - -DataTemplateManager.prototype.ListAllAuras = function() -{ - return Engine.ListDirectoryFiles(this.aurasPath, "*.json", true).map(file => file.slice(this.aurasPath.length, -".json".length)); -}; - -DataTemplateManager.prototype.GetAllTechs = function() -{ - return this.allTechs; -}; - -DataTemplateManager.prototype.TechnologyExists = function(template) -{ - return !!this.allTechs[template]; -}; - -Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager); Index: binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/GuiInterface.js +++ binaries/data/mods/public/simulation/components/GuiInterface.js @@ -658,25 +658,17 @@ if (!template.Auras) return GetTemplateDataHelper(template, player, aurasTemplate, Resources, DamageTypes); - // Add aura name and description loaded from JSON file let auraNames = template.Auras._string.split(/\s+/); - let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); + for (let name of auraNames) - aurasTemplate[name] = cmpDataTemplateManager.GetAuraTemplate(name); + aurasTemplate[name] = VFS.GetAura(name); + return GetTemplateDataHelper(template, player, aurasTemplate, Resources, DamageTypes); }; GuiInterface.prototype.GetTechnologyData = function(player, data) { - let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); - let template = cmpDataTemplateManager.GetTechnologyTemplate(data.name); - - if (!template) - { - warn("Tried to get data for invalid technology: " + data.name); - return null; - } - + let template = VFS.GetTechnology(data.name); return GetTechnologyDataHelper(template, data.civ, Resources); }; Index: binaries/data/mods/public/simulation/components/ProductionQueue.js =================================================================== --- binaries/data/mods/public/simulation/components/ProductionQueue.js +++ binaries/data/mods/public/simulation/components/ProductionQueue.js @@ -161,20 +161,18 @@ var techs = string.split(/\s+/); // Replace the civ specific technologies - let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); for (let i = 0; i < techs.length; ++i) { let tech = techs[i]; if (tech.indexOf("{civ}") == -1) continue; let civTech = tech.replace("{civ}", cmpPlayer.GetCiv()); - techs[i] = cmpDataTemplateManager.TechnologyExists(civTech) ? - civTech : tech.replace("{civ}", "generic"); + techs[i] = VFS.TechnologyExists(civTech) ? civTech : tech.replace("{civ}", "generic"); } // Remove any technologies that can't be researched by this civ techs = techs.filter(tech => { - let reqs = DeriveTechnologyRequirements(cmpTechnologyManager.GetTechnologyTemplate(tech), cmpPlayer.GetCiv()); + let reqs = DeriveTechnologyRequirements(VFS.GetTechnology(tech), cmpPlayer.GetCiv()); return cmpTechnologyManager.CheckTechnologyRequirements(reqs, true); }); @@ -190,7 +188,8 @@ var tech = techs[i]; if (disabledTechnologies && disabledTechnologies[tech]) continue; - var template = cmpTechnologyManager.GetTechnologyTemplate(tech); + + let template = VFS.GetTechnology(tech); if (!template.supersedes || techs.indexOf(template.supersedes) === -1) techList.push(tech); else @@ -221,7 +220,7 @@ continue; } - var template = cmpTechnologyManager.GetTechnologyTemplate(tech); + let template = VFS.GetTechnology(tech); if (template.top) ret[i] = {"pair": true, "top": template.top, "bottom": template.bottom}; else @@ -246,7 +245,7 @@ var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); - var template = cmpTechnologyManager.GetTechnologyTemplate(tech); + let template = VFS.GetTechnology(tech); if (template.top) { return (cmpTechnologyManager.IsTechnologyResearched(template.top) || cmpTechnologyManager.IsInProgress(template.top) @@ -344,12 +343,6 @@ } else if (type == "technology") { - // Load the technology template - var cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); - var template = cmpDataTemplateManager.GetTechnologyTemplate(templateName); - if (!template) - return; - if (!this.GetTechnologiesList().some(tech => tech && (tech == templateName || @@ -360,6 +353,7 @@ return; } + let template = VFS.GetTechnology(templateName); let techCostMultiplier = this.GetTechCostMultiplier(); let time = techCostMultiplier.time * template.researchTime * cmpPlayer.GetCheatTimeMultiplier(); @@ -809,7 +803,7 @@ var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); cmpTechnologyManager.ResearchTechnology(item.technologyTemplate); - var template = cmpTechnologyManager.GetTechnologyTemplate(item.technologyTemplate); + let template = VFS.GetTechnology(item.technologyTemplate); if (template && template.soundComplete) { Index: binaries/data/mods/public/simulation/components/TechnologyManager.js =================================================================== --- binaries/data/mods/public/simulation/components/TechnologyManager.js +++ binaries/data/mods/public/simulation/components/TechnologyManager.js @@ -41,12 +41,10 @@ // Some technologies are automatically researched when their conditions are met. They have no cost and are // researched instantly. This allows civ bonuses and more complicated technologies. this.autoResearchTech = {}; - var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); - for (var key in allTechs) - { + let allTechs = VFS.GetAllTechnologies(); + for (let key in allTechs) if (allTechs[key].autoResearch || allTechs[key].top) this.autoResearchTech[key] = allTechs[key]; - } }; TechnologyManager.prototype.OnUpdate = function() @@ -54,14 +52,12 @@ this.UpdateAutoResearch(); }; - // This function checks if the requirements of any autoresearch techs are met and if they are it researches them TechnologyManager.prototype.UpdateAutoResearch = function() { - var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); for (var key in this.autoResearchTech) { - var tech = cmpDataTempMan.GetTechnologyTemplate(key); + let tech = VFS.GetTechnology(key); if ((tech.autoResearch && this.CanResearch(key)) || (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) { @@ -72,11 +68,6 @@ } }; -TechnologyManager.prototype.GetTechnologyTemplate = function(tech) -{ - return Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetTechnologyTemplate(tech); -}; - // Checks an entity template to see if its technology requirements have been met TechnologyManager.prototype.CanProduce = function (templateName) { @@ -107,7 +98,7 @@ // Checks the requirements for a technology to see if it can be researched at the current time TechnologyManager.prototype.CanResearch = function(tech) { - let template = this.GetTechnologyTemplate(tech); + let template = VFS.GetTechnology(tech); if (!template) { @@ -267,13 +258,7 @@ { this.StoppedResearch(tech, false); - var template = this.GetTechnologyTemplate(tech); - - if (!template) - { - error("Tried to research invalid technology: " + uneval(tech)); - return; - } + let template = VFS.GetTechnology(tech); var modifiedComponents = {}; this.researchedTechs[tech] = template; @@ -302,8 +287,7 @@ if (!i || this.IsTechnologyResearched(i)) continue; - var template = this.GetTechnologyTemplate(i); - this.researchedTechs[i] = template; + this.researchedTechs[i] = VFS.GetTechnology(i); // Change the EntityLimit if any let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); Index: binaries/data/mods/public/simulation/components/tests/test_Auras.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Auras.js +++ binaries/data/mods/public/simulation/components/tests/test_Auras.js @@ -34,8 +34,8 @@ "GetEntitiesByPlayer": id => [30, 31, 32] }); - AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, { - "GetAuraTemplate": (name) => { + VFS = { + "GetAura": (name) => { let template = { "type": name, "affectedPlayers": ["Ally"], @@ -48,7 +48,7 @@ template.radius = auraRange; return template; } - }); + }; AddMock(playerEnt[1], IID_Player, { "IsAlly": id => id == playerID[1] || id == playerID[2], Index: binaries/data/mods/public/simulation/components/tests/test_TechnologyManager.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_TechnologyManager.js +++ binaries/data/mods/public/simulation/components/tests/test_TechnologyManager.js @@ -1,9 +1,9 @@ Engine.LoadComponentScript("interfaces/TechnologyManager.js"); Engine.LoadComponentScript("TechnologyManager.js"); - AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, { - "GetAllTechs": () => {} - }); +VFS = { + "GetAllTechnologies": () => {}, +}; let cmpTechnologyManager = ConstructComponent(SYSTEM_ENTITY, "TechnologyManager", {}); Index: binaries/data/mods/public/simulation/helpers/Cheat.js =================================================================== --- binaries/data/mods/public/simulation/helpers/Cheat.js +++ binaries/data/mods/public/simulation/helpers/Cheat.js @@ -88,9 +88,7 @@ else return; - // check if specialised tech exists (like phase_town_athen) - var cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); - if (cmpDataTemplateManager.ListAllTechs().indexOf(parameter + "_" + cmpPlayer.civ) > -1) + if (VFS.TechnologyExists(parameter + "_" + cmpPlayer.civ)) parameter += "_" + cmpPlayer.civ; else parameter += "_generic"; @@ -140,12 +138,7 @@ } } - // check, if technology exists - var template = cmpTechnologyManager.GetTechnologyTemplate(techname); - if (!template) - return; - - // check, if technology is already researched + let template = VFS.GetTechnology(techname); if (!cmpTechnologyManager.IsTechnologyResearched(techname)) cmpTechnologyManager.ResearchTechnology(techname); return; Index: source/graphics/MapGenerator.cpp =================================================================== --- source/graphics/MapGenerator.cpp +++ source/graphics/MapGenerator.cpp @@ -97,7 +97,6 @@ // Replace RNG with a seeded deterministic function m_ScriptInterface->ReplaceNondeterministicRNG(m_MapGenRNG); - m_ScriptInterface->LoadGlobalScripts(); // Functions for RMS JSI_VFS::RegisterScriptFunctions_Maps(*m_ScriptInterface); @@ -110,6 +109,9 @@ m_ScriptInterface->RegisterFunction, std::string, bool, CMapGeneratorWorker::FindActorTemplates>("FindActorTemplates"); m_ScriptInterface->RegisterFunction("GetTerrainTileSize"); + // Globalscripts can use above script functions + m_ScriptInterface->LoadGlobalScripts(); + // Parse settings JS::RootedValue settingsVal(cx); if (!m_ScriptInterface->ParseJSON(m_Settings, &settingsVal) && settingsVal.isUndefined()) Index: source/simulation2/TypeList.h =================================================================== --- source/simulation2/TypeList.h +++ source/simulation2/TypeList.h @@ -162,9 +162,6 @@ INTERFACE(ValueModificationManager) COMPONENT(ValueModificationManagerScripted) -INTERFACE(DataTemplateManager) -COMPONENT(DataTemplateManagerScripted) - INTERFACE(Terrain) COMPONENT(Terrain) Index: source/simulation2/components/CCmpAIManager.cpp =================================================================== --- source/simulation2/components/CCmpAIManager.cpp +++ source/simulation2/components/CCmpAIManager.cpp @@ -29,6 +29,7 @@ #include "ps/CLogger.h" #include "ps/Filesystem.h" #include "ps/Profile.h" +#include "ps/scripting/JSInterface_VFS.h" #include "ps/TemplateLoader.h" #include "ps/Util.h" #include "simulation2/components/ICmpAIInterface.h" @@ -36,7 +37,6 @@ #include "simulation2/components/ICmpObstructionManager.h" #include "simulation2/components/ICmpRangeManager.h" #include "simulation2/components/ICmpTemplateManager.h" -#include "simulation2/components/ICmpDataTemplateManager.h" #include "simulation2/components/ICmpTerritoryManager.h" #include "simulation2/helpers/LongPathfinder.h" #include "simulation2/serialization/DebugSerializer.h" @@ -212,20 +212,20 @@ m_HasSharedComponent(false), m_SerializablePrototypes(new ObjectIdCache(g_ScriptRuntime)), m_EntityTemplates(g_ScriptRuntime->m_rt), - m_TechTemplates(g_ScriptRuntime->m_rt), m_SharedAIObj(g_ScriptRuntime->m_rt), m_PassabilityMapVal(g_ScriptRuntime->m_rt), m_TerritoryMapVal(g_ScriptRuntime->m_rt) { m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG); - m_ScriptInterface->LoadGlobalScripts(); m_ScriptInterface->SetCallbackData(static_cast (this)); m_SerializablePrototypes->init(); JS_AddExtraGCRootsTracer(m_ScriptInterface->GetJSRuntime(), Trace, this); + JSI_VFS::RegisterScriptFunctions_Simulation(*m_ScriptInterface.get()); + m_ScriptInterface->RegisterFunction("PostCommand"); m_ScriptInterface->RegisterFunction("IncludeModule"); m_ScriptInterface->RegisterFunction("Exit"); @@ -234,6 +234,9 @@ m_ScriptInterface->RegisterFunction, u32, u32, u32, CAIWorker::DumpImage>("DumpImage"); m_ScriptInterface->RegisterFunction("GetTemplate"); + + // Globalscripts can use above script functions + m_ScriptInterface->LoadGlobalScripts(); } ~CAIWorker() @@ -394,7 +397,7 @@ m_RNG.seed(seed); } - bool TryLoadSharedComponent(bool hasTechs) + bool TryLoadSharedComponent() { JSContext* cx = m_ScriptInterface->GetContext(); JSAutoRequest rq(cx); @@ -449,18 +452,6 @@ ENSURE(m_HasLoadedEntityTemplates); m_ScriptInterface->SetProperty(settings, "templates", m_EntityTemplates, false); - if (hasTechs) - { - m_ScriptInterface->SetProperty(settings, "techTemplates", m_TechTemplates, false); - } - else - { - // won't get the tech templates directly. - JS::RootedValue fakeTech(cx); - m_ScriptInterface->Eval("({})", &fakeTech); - m_ScriptInterface->SetProperty(settings, "techTemplates", fakeTech, false); - } - JS::AutoValueVector argv(cx); argv.append(settings); m_ScriptInterface->CallConstructor(ctor, argv, &m_SharedAIObj); @@ -621,11 +612,6 @@ } } - void RegisterTechTemplates(const shared_ptr& techTemplates) - { - m_ScriptInterface->ReadStructuredClone(techTemplates, &m_TechTemplates); - } - void LoadEntityTemplates(const std::vector >& templates) { JSContext* cx = m_ScriptInterface->GetContext(); @@ -747,8 +733,7 @@ deserializer.Bool("useSharedScript", m_HasSharedComponent); if (m_HasSharedComponent) { - TryLoadSharedComponent(false); - + TryLoadSharedComponent(); JS::RootedValue sharedData(cx); deserializer.ScriptVal("sharedData", &sharedData); if (!m_ScriptInterface->CallFunctionVoid(m_SharedAIObj, "Deserialize", sharedData)) @@ -913,7 +898,6 @@ JS::PersistentRootedValue m_EntityTemplates; bool m_HasLoadedEntityTemplates; - JS::PersistentRootedValue m_TechTemplates; std::map > m_PlayerMetadata; std::vector > m_Players; // use shared_ptr just to avoid copying @@ -1017,19 +1001,7 @@ virtual void TryLoadSharedComponent() { - const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); - JSContext* cx = scriptInterface.GetContext(); - JSAutoRequest rq(cx); - - // load the technology templates - CmpPtr cmpDataTemplateManager(GetSystemEntity()); - ENSURE(cmpDataTemplateManager); - - JS::RootedValue techTemplates(cx); - cmpDataTemplateManager->GetAllTechs(&techTemplates); - m_Worker.RegisterTechTemplates(scriptInterface.WriteStructuredClone(techTemplates)); - - m_Worker.TryLoadSharedComponent(true); + m_Worker.TryLoadSharedComponent(); } virtual void RunGamestateInit() Index: source/simulation2/components/ICmpDataTemplateManager.h =================================================================== --- source/simulation2/components/ICmpDataTemplateManager.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 2012 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#ifndef INCLUDED_ICMPDATATEMPLATEMANAGER -#define INCLUDED_ICMPDATATEMPLATEMANAGER - -#include "simulation2/system/Interface.h" - -#include "maths/Fixed.h" - -/** - * Data template manager interface. - * (This interface only includes the functions needed by native code for accessing - * json template data, the associated logic is handled in scripts) - */ -class ICmpDataTemplateManager : public IComponent -{ -public: - virtual void GetAllTechs(JS::MutableHandleValue ret) = 0; - - DECLARE_INTERFACE_TYPE(DataTemplateManager) -}; - -#endif // INCLUDED_ICMPDATATEMPLATEMANAGER Index: source/simulation2/components/ICmpDataTemplateManager.cpp =================================================================== --- source/simulation2/components/ICmpDataTemplateManager.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2017 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#include "precompiled.h" - -#include "ICmpDataTemplateManager.h" - -#include "simulation2/system/InterfaceScripted.h" -#include "simulation2/scripting/ScriptComponent.h" - -BEGIN_INTERFACE_WRAPPER(DataTemplateManager) -END_INTERFACE_WRAPPER(DataTemplateManager) - -class CCmpDataTemplateManagerScripted : public ICmpDataTemplateManager -{ -public: - DEFAULT_SCRIPT_WRAPPER(DataTemplateManagerScripted) - - virtual void GetAllTechs(JS::MutableHandleValue ret) - { - m_Script.CallRef("GetAllTechs", ret); - } -}; - -REGISTER_COMPONENT_SCRIPT_WRAPPER(DataTemplateManagerScripted) Index: source/simulation2/system/ComponentManager.cpp =================================================================== --- source/simulation2/system/ComponentManager.cpp +++ source/simulation2/system/ComponentManager.cpp @@ -63,7 +63,6 @@ m_ScriptInterface.SetCallbackData(static_cast (this)); m_ScriptInterface.ReplaceNondeterministicRNG(m_RNG); - m_ScriptInterface.LoadGlobalScripts(); // For component script tests, the test system sets up its own scripted implementation of // these functions, so we skip registering them here in those cases @@ -87,6 +86,9 @@ m_ScriptInterface.RegisterFunction ("FlushDestroyedEntities"); } + // Globalscripts can use above script functions + m_ScriptInterface.LoadGlobalScripts(); + // Define MT_*, IID_* as script globals, and store their names #define MESSAGE(name) m_ScriptInterface.SetGlobal("MT_" #name, (int)MT_##name); #define INTERFACE(name) \