Rename TechnologyTemplateManager to DataTemplateManager in order to reflect its new function. Fixes #3909. Disable serialisation of technology templates. Refs #3834

This was SVN commit r18100.
This commit is contained in:
sanderd17 2016-04-27 08:25:47 +00:00
parent f7a618d233
commit f24523dc8f
11 changed files with 51 additions and 44 deletions

View File

@ -8,14 +8,14 @@ Auras.prototype.Schema =
Auras.prototype.Init = function()
{
let cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
this.auras = {};
this.affectedPlayers = {};
let auraNames = this.GetAuraNames();
for (let name of auraNames)
{
this.affectedPlayers[name] = [];
this.auras[name] = cmpTechnologyTemplateManager.GetAuraTemplate(name);
this.auras[name] = cmpDataTemplateManager.GetAuraTemplate(name);
}
// In case of autogarrisoning, this component can be called before ownership is set.
// So it needs to be completely initialised from the start.

View File

@ -1,21 +1,28 @@
/**
* System component which loads the technology and the aura data files
*/
function TechnologyTemplateManager() {}
function DataTemplateManager() {}
TechnologyTemplateManager.prototype.Schema =
DataTemplateManager.prototype.Schema =
"<a:component type='system'/><empty/>";
TechnologyTemplateManager.prototype.Init = function()
DataTemplateManager.prototype.Init = function()
{
this.allTechs = {};
this.allAuras = {};
var techNames = this.ListAllTechs();
for (var i in techNames)
this.GetTemplate(techNames[i]);
this.GetTechnologyTemplate(techNames[i]);
};
TechnologyTemplateManager.prototype.GetTemplate = function(template)
DataTemplateManager.prototype.Serialize = null; // we have no dynamic state to save
DataTemplateManager.prototype.Deserialize = function()
{
this.Init();
};
DataTemplateManager.prototype.GetTechnologyTemplate = function(template)
{
if (!this.allTechs[template])
{
@ -27,7 +34,7 @@ TechnologyTemplateManager.prototype.GetTemplate = function(template)
return this.allTechs[template];
};
TechnologyTemplateManager.prototype.GetAuraTemplate = function(template)
DataTemplateManager.prototype.GetAuraTemplate = function(template)
{
if (!this.allAuras[template])
{
@ -39,14 +46,14 @@ TechnologyTemplateManager.prototype.GetAuraTemplate = function(template)
return this.allAuras[template];
};
TechnologyTemplateManager.prototype.ListAllTechs = function()
DataTemplateManager.prototype.ListAllTechs = function()
{
return Engine.FindJSONFiles("technologies", true);
};
TechnologyTemplateManager.prototype.GetAllTechs = function()
DataTemplateManager.prototype.GetAllTechs = function()
{
return this.allTechs;
};
Engine.RegisterSystemComponentType(IID_TechnologyTemplateManager, "TechnologyTemplateManager", TechnologyTemplateManager);
Engine.RegisterSystemComponentType(IID_DataTemplateManager, "DataTemplateManager", DataTemplateManager);

View File

@ -591,13 +591,13 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
// Add aura name and description loaded from JSON file
let auraNames = template.Auras._string.split(/\s+/);
let cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
for (let name of auraNames)
{
let auraTemplate = cmpTechnologyTemplateManager.GetAuraTemplate(name);
let auraTemplate = cmpDataTemplateManager.GetAuraTemplate(name);
if (!auraTemplate)
{
// the following warning is perhaps useless since it's yet done in TechnologyTemplateManager
// the following warning is perhaps useless since it's yet done in DataTemplateManager
warn("Tried to get data for invalid aura: " + name);
continue;
}
@ -610,8 +610,8 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
GuiInterface.prototype.GetTechnologyData = function(player, name)
{
let cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
let template = cmpTechnologyTemplateManager.GetTemplate(name);
let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
let template = cmpDataTemplateManager.GetTechnologyTemplate(name);
if (!template)
{

View File

@ -316,8 +316,8 @@ ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat
else if (type == "technology")
{
// Load the technology template
var cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
var template = cmpTechnologyTemplateManager.GetTemplate(templateName);
var cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
var template = cmpDataTemplateManager.GetTechnologyTemplate(templateName);
if (!template)
return;
var cmpPlayer = QueryOwnerInterface(this.entity);

View File

@ -41,7 +41,7 @@ TechnologyManager.prototype.Init = function()
// 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_TechnologyTemplateManager).GetAllTechs();
var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs();
for (var key in allTechs)
{
if (allTechs[key].autoResearch || allTechs[key].top)
@ -58,10 +58,10 @@ TechnologyManager.prototype.OnUpdate = function()
// This function checks if the requirements of any autoresearch techs are met and if they are it researches them
TechnologyManager.prototype.UpdateAutoResearch = function()
{
var cmpTechTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
for (var key in this.autoResearchTech)
{
var tech = cmpTechTempMan.GetTemplate(key);
var tech = cmpDataTempMan.GetTechnologyTemplate(key);
if ((tech.autoResearch && this.CanResearch(key))
|| (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom))))
{
@ -74,7 +74,7 @@ TechnologyManager.prototype.UpdateAutoResearch = function()
TechnologyManager.prototype.GetTechnologyTemplate = function(tech)
{
return Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager).GetTemplate(tech);
return Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetTechnologyTemplate(tech);
};
// Checks an entity template to see if its technology requirements have been met

View File

@ -25,7 +25,7 @@ AddMock(SYSTEM_ENTITY, IID_RangeManager, {
GetEntityFlagMask: function(identifier) { },
});
AddMock(SYSTEM_ENTITY, IID_TechnologyTemplateManager, {
AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, {
GetAuraTemplate: function(name) {
if (name == "test1")
return {

View File

@ -90,8 +90,8 @@ function Cheat(input)
return;
// check if specialised tech exists (like phase_town_athen)
var cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
if (cmpTechnologyTemplateManager.ListAllTechs().indexOf(parameter + "_" + cmpPlayer.civ) > -1)
var cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
if (cmpDataTemplateManager.ListAllTechs().indexOf(parameter + "_" + cmpPlayer.civ) > -1)
parameter += "_" + cmpPlayer.civ;
Cheat({ "player": input.player, "action": "researchTechnology", "parameter": parameter, "selected": input.selected });

View File

@ -160,8 +160,8 @@ COMPONENT(SoundManager)
INTERFACE(ValueModificationManager)
COMPONENT(ValueModificationManagerScripted)
INTERFACE(TechnologyTemplateManager)
COMPONENT(TechnologyTemplateManagerScripted)
INTERFACE(DataTemplateManager)
COMPONENT(DataTemplateManagerScripted)
INTERFACE(Terrain)
COMPONENT(Terrain)

View File

@ -34,7 +34,7 @@
#include "simulation2/components/ICmpObstructionManager.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "simulation2/components/ICmpTemplateManager.h"
#include "simulation2/components/ICmpTechnologyTemplateManager.h"
#include "simulation2/components/ICmpDataTemplateManager.h"
#include "simulation2/components/ICmpTerritoryManager.h"
#include "simulation2/helpers/LongPathfinder.h"
#include "simulation2/serialization/DebugSerializer.h"
@ -979,12 +979,12 @@ public:
JSAutoRequest rq(cx);
// load the technology templates
CmpPtr<ICmpTechnologyTemplateManager> cmpTechTemplateManager(GetSystemEntity());
ENSURE(cmpTechTemplateManager);
CmpPtr<ICmpDataTemplateManager> cmpDataTemplateManager(GetSystemEntity());
ENSURE(cmpDataTemplateManager);
// Get the game state from AIInterface
JS::RootedValue techTemplates(cx);
cmpTechTemplateManager->GetAllTechs(&techTemplates);
cmpDataTemplateManager->GetAllTechs(&techTemplates);
m_Worker.RegisterTechTemplates(scriptInterface.WriteStructuredClone(techTemplates));
m_Worker.TryLoadSharedComponent(true);

View File

@ -17,18 +17,18 @@
#include "precompiled.h"
#include "ICmpTechnologyTemplateManager.h"
#include "ICmpDataTemplateManager.h"
#include "simulation2/system/InterfaceScripted.h"
#include "simulation2/scripting/ScriptComponent.h"
BEGIN_INTERFACE_WRAPPER(TechnologyTemplateManager)
END_INTERFACE_WRAPPER(TechnologyTemplateManager)
BEGIN_INTERFACE_WRAPPER(DataTemplateManager)
END_INTERFACE_WRAPPER(DataTemplateManager)
class CCmpTechnologyTemplateManagerScripted : public ICmpTechnologyTemplateManager
class CCmpDataTemplateManagerScripted : public ICmpDataTemplateManager
{
public:
DEFAULT_SCRIPT_WRAPPER(TechnologyTemplateManagerScripted)
DEFAULT_SCRIPT_WRAPPER(DataTemplateManagerScripted)
virtual void GetAllTechs(JS::MutableHandleValue ret)
{
@ -36,4 +36,4 @@ public:
}
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(TechnologyTemplateManagerScripted)
REGISTER_COMPONENT_SCRIPT_WRAPPER(DataTemplateManagerScripted)

View File

@ -15,24 +15,24 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ICMPTECHNOLOGYTEMPLATEMANAGER
#define INCLUDED_ICMPTECHNOLOGYTEMPLATEMANAGER
#ifndef INCLUDED_ICMPDATATEMPLATEMANAGER
#define INCLUDED_ICMPDATATEMPLATEMANAGER
#include "simulation2/system/Interface.h"
#include "maths/Fixed.h"
/**
* Technology template manager interface.
* Data template manager interface.
* (This interface only includes the functions needed by native code for accessing
* technology template data, the associated logic is handled in scripts)
* json template data, the associated logic is handled in scripts)
*/
class ICmpTechnologyTemplateManager : public IComponent
class ICmpDataTemplateManager : public IComponent
{
public:
virtual void GetAllTechs(JS::MutableHandleValue ret) = 0;
DECLARE_INTERFACE_TYPE(TechnologyTemplateManager)
DECLARE_INTERFACE_TYPE(DataTemplateManager)
};
#endif // INCLUDED_ICMPTECHNOLOGYTEMPLATEMANAGER
#endif // INCLUDED_ICMPDATATEMPLATEMANAGER