Differential D3628 Diff 16325 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Garrisonable.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Garrisonable.js
Engine.LoadComponentScript("interfaces/Auras.js"); | Engine.LoadComponentScript("interfaces/Auras.js"); | ||||
Engine.LoadComponentScript("interfaces/Garrisonable.js"); | Engine.LoadComponentScript("interfaces/Garrisonable.js"); | ||||
Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); | Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); | ||||
Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | ||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Garrisonable.js"); | Engine.LoadComponentScript("Garrisonable.js"); | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", (prop, oVal, ent) => oVal); | Engine.RegisterGlobal("ApplyValueModificationsToEntity", (prop, oVal, ent) => oVal); | ||||
const garrisonHolderID = 1; | const garrisonHolderID = 1; | ||||
const garrisonableID = 2; | const garrisonableID = 2; | ||||
AddMock(garrisonHolderID, IID_GarrisonHolder, { | AddMock(garrisonHolderID, IID_GarrisonHolder, { | ||||
"Garrison": () => true | "Garrison": () => true, | ||||
"GetSpawnPosition": () => new Vector3D(0, 0, 0), | |||||
"IsAllowedToGarrison": () => true, | |||||
"OrderToRallyPoint": () => {}, | |||||
"Eject": () => true | |||||
}); | }); | ||||
let size = 1; | let size = 1; | ||||
let cmpGarrisonable = ConstructComponent(garrisonableID, "Garrisonable", { | let cmpGarrisonable = ConstructComponent(garrisonableID, "Garrisonable", { | ||||
"Size": size | "Size": size | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(garrisonHolderID), size); | TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(garrisonHolderID), size); | TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size); | ||||
let extraSize = 2; | let extraSize = 2; | ||||
AddMock(garrisonableID, IID_GarrisonHolder, { | AddMock(garrisonableID, IID_GarrisonHolder, { | ||||
"OccupiedSlots": () => extraSize | "OccupiedSlots": () => extraSize | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(garrisonHolderID), size); | TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(garrisonHolderID), size + extraSize); | TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size + extraSize); | ||||
// Test garrisoning. | |||||
TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID)); | TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID)); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID); | ||||
TS_ASSERT(!cmpGarrisonable.Garrison(garrisonHolderID)); | TS_ASSERT(!cmpGarrisonable.Garrison(garrisonHolderID)); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), garrisonHolderID); | ||||
cmpGarrisonable.UnGarrison(); | cmpGarrisonable.UnGarrison(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | ||||
// Test renaming. | |||||
const newGarrisonableID = 3; | |||||
let cmpGarrisonableNew = ConstructComponent(newGarrisonableID, "Garrisonable", { | |||||
"Size": 1 | |||||
}); | |||||
TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID)); | |||||
cmpGarrisonable.OnEntityRenamed({ "entity": garrisonableID, "newentity": newGarrisonableID }); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonableNew.HolderID(), garrisonHolderID); |
Wildfire Games · Phabricator