mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 22:03:56 -07:00
Thus throw errors if a simulation test tries to alternate the template
instead of silently passing tests with wrong values (as happened tests
fixed by ff90bb8490).
Remove the two clones from simulation components that were only relevant
for that test.
Add test to test the test.
Differential Revision: https://code.wildfiregames.com/D871
Fixes #4759
setup.js and setup_test.js Reviewed By: leper
This was SVN commit r20134.
112 lines
2.1 KiB
JavaScript
112 lines
2.1 KiB
JavaScript
var g_NewIID = 1000; // some arbitrary not-yet-used number
|
|
var g_NewMTID = 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.RegisterSystemComponentType = 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.RegisterMessageType = function(name)
|
|
{
|
|
global["MT_" + name] = g_NewMTID++;
|
|
};
|
|
|
|
Engine.QueryInterface = function(ent, iid)
|
|
{
|
|
if (g_Components[ent] && g_Components[ent][iid])
|
|
return g_Components[ent][iid];
|
|
return null;
|
|
};
|
|
|
|
Engine.RegisterGlobal = function(name, value)
|
|
{
|
|
global[name] = value;
|
|
};
|
|
|
|
Engine.DestroyEntity = function(ent)
|
|
{
|
|
for (let cid in g_Components[ent])
|
|
{
|
|
let cmp = g_Components[ent][cid];
|
|
if (cmp && cmp.Deinit)
|
|
cmp.Deinit();
|
|
}
|
|
|
|
delete g_Components[ent];
|
|
|
|
// TODO: should send Destroy message
|
|
};
|
|
|
|
Engine.PostMessage = function(ent, iid, message)
|
|
{
|
|
// TODO: make this send a message if necessary
|
|
};
|
|
|
|
|
|
Engine.BroadcastMessage = function(iid, message)
|
|
{
|
|
// TODO: make this send a message if necessary
|
|
};
|
|
|
|
global.ResetState = function()
|
|
{
|
|
g_Components = {};
|
|
};
|
|
|
|
global.AddMock = function(ent, iid, mock)
|
|
{
|
|
if (!g_Components[ent])
|
|
g_Components[ent] = {};
|
|
g_Components[ent][iid] = mock;
|
|
};
|
|
|
|
global.DeleteMock = function(ent, iid)
|
|
{
|
|
if (!g_Components[ent])
|
|
g_Components[ent] = {};
|
|
delete g_Components[ent][iid];
|
|
};
|
|
|
|
global.ConstructComponent = function(ent, name, template)
|
|
{
|
|
let cmp = new g_ComponentTypes[name].ctor();
|
|
|
|
Object.defineProperties(cmp, {
|
|
"entity": {
|
|
"value": ent,
|
|
"configurable": false,
|
|
"enumerable": false,
|
|
"writable": false
|
|
},
|
|
"template": {
|
|
"value": template && deepfreeze(clone(template)),
|
|
"configurable": false,
|
|
"enumerable": false,
|
|
"writable": false
|
|
}
|
|
});
|
|
|
|
cmp.Init();
|
|
|
|
if (!g_Components[ent])
|
|
g_Components[ent] = {};
|
|
g_Components[ent][g_ComponentTypes[name].iid] = cmp;
|
|
|
|
return cmp;
|
|
};
|