Index: ps/trunk/source/simulation2/system/ComponentManager.h =================================================================== --- ps/trunk/source/simulation2/system/ComponentManager.h +++ ps/trunk/source/simulation2/system/ComponentManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -286,6 +286,7 @@ void Script_BroadcastMessage(int mtid, JS::HandleValue data); int Script_AddEntity(const std::wstring& templateName); int Script_AddLocalEntity(const std::wstring& templateName); + const CParamNode& Script_GetTemplate(const std::string& templateName); CMessage* ConstructMessage(int mtid, JS::HandleValue data); void SendGlobalMessage(entity_id_t ent, const CMessage& msg); Index: ps/trunk/source/simulation2/system/ComponentManager.cpp =================================================================== --- ps/trunk/source/simulation2/system/ComponentManager.cpp +++ ps/trunk/source/simulation2/system/ComponentManager.cpp @@ -86,6 +86,8 @@ ScriptFunction::Register<&CComponentManager::QueryInterface, Getter>(rq, "QueryInterface"); ScriptFunction::Register<&CComponentManager::DestroyComponentsSoon, Getter>(rq, "DestroyEntity"); ScriptFunction::Register<&CComponentManager::FlushDestroyedComponents, Getter>(rq, "FlushDestroyedEntities"); + ScriptFunction::Register<&CComponentManager::Script_GetTemplate, Getter>(rq, "GetTemplate"); + } // Globalscripts may use VFS script functions @@ -382,6 +384,23 @@ m_ScriptInterface.SetGlobal(name.c_str(), value, m_CurrentlyHotloading); } +const CParamNode& CComponentManager::Script_GetTemplate(const std::string& templateName) +{ + static CParamNode nullNode(false); + + ICmpTemplateManager* cmpTemplateManager = static_cast (QueryInterface(SYSTEM_ENTITY, IID_TemplateManager)); + if (!cmpTemplateManager) + { + LOGERROR("Template manager is not loaded"); + return nullNode; + } + + const CParamNode* tmpl = cmpTemplateManager->GetTemplate(templateName); + if (!tmpl) + return nullNode; + return *tmpl; +} + std::vector CComponentManager::Script_GetEntitiesWithInterface(int iid) { std::vector ret;