1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/components/tests/setup.js
Ykkrosh 4fed9b8242 # Added initial support for players and population counters in new simulation system, plus various infrastructure improvements.
Merge from 22b478ffed8d.
Pure scripted interface definitions.
Entity creation from scripts.
Improved messaging system.
Messages on entity deletion.
Basic player entities.
Player ownership.
Bug fixes.

This was SVN commit r7281.
2010-01-22 20:03:14 +00:00

45 lines
924 B
JavaScript

var g_NewIID = 1000; // some arbitrary not-yet-used number
var g_ComponentTypes = {};
var g_Components = {};
// Emulate some engine functions:
Engine.RegisterComponentType = function(iid, name, ctor)
{
TS_ASSERT(!g_ComponentTypes[name]);
g_ComponentTypes[name] = { iid: iid, ctor: ctor };
};
Engine.RegisterInterface = function(name)
{
global["IID_"+name] = g_NewIID++;
};
Engine.QueryInterface = function(ent, iid)
{
if (g_Components[ent] && g_Components[ent][iid])
return g_Components[ent][iid];
return null;
};
// TODO:
// Engine.RegisterGlobal
// Engine.PostMessage
// Engine.BroadcastMessage
global.AddMock = function(ent, iid, mock)
{
if (!g_Components[ent])
g_Components[ent] = {};
g_Components[ent][iid] = mock;
};
global.ConstructComponent = function(ent, name, template)
{
var cmp = new g_ComponentTypes[name].ctor();
cmp.entity = ent;
cmp.template = template;
cmp.Init();
return cmp;
};