0ad/binaries/data/mods/public/simulation/components/tests/setup.js
wraitii 7440523ade Enable garrisoning on gates / fix movement of units with visible garrison points (2nd commit)
This is the same commit as 2abd9cead2 / D1418, fixing noted issues.

This addresses two related issues:
- Units visibly garrisoned on gates keep the gate open.
- Units visibly garrisoned on entities keep their pathfinding blocker
flags.

De-activate the obstruction of visibly-garrisoned entities, fixing the
2nd issue.
Keep a list of entities that cannot move and thus should not count
towards gate-opening logic.

Packing logic is kept separate: it is more related to entities having
'alternate forms' with different capabilities than being currently
incapable of moving.

Based on work by temple

Fixes #2679.
Fixes #5151.

Differential Revision: https://code.wildfiregames.com/D2775
This was SVN commit r23731.
2020-06-02 11:40:29 +00:00

137 lines
2.6 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;
return g_Components[ent][iid];
};
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;
};
/**
* A simple Spy proxy that tracks and forward function calls.
* NB: this immediately replaces obj's func.
*/
global.Spy = function(obj, func)
{
this._called = 0;
this._callargs = [];
let og_func = obj[func];
let spy = (...args) => {
++this._called;
this._callargs.push(args);
return og_func.apply(obj, args);
};
obj[func] = spy;
this._reset = () => {
this._called = 0;
this._callargs = [];
};
return this;
};