Differential D3150 Diff 16734 binaries/data/mods/public/simulation/components/tests/test_Garrisonable.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Garrisonable.js
Engine.LoadHelperScript("Position.js"); | |||||
Engine.LoadComponentScript("interfaces/Garrisonable.js"); | Engine.LoadComponentScript("interfaces/Garrisonable.js"); | ||||
Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); | Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); | ||||
Engine.LoadComponentScript("interfaces/Health.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, | "IsAllowedToGarrison": () => true, | ||||
"OrderToRallyPoint": () => {}, | |||||
"Eject": () => true | "Eject": () => true | ||||
}); | }); | ||||
AddMock(garrisonHolderID, IID_Footprint, { | |||||
"PickSpawnPointBothPass": entity => new Vector3D(4, 3, 30), | |||||
"PickSpawnPoint": entity => new Vector3D(4, 3, 30) | |||||
}); | |||||
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(), size); | TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), 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(), size); | TS_ASSERT_EQUALS(cmpGarrisonable.UnitSize(), size); | ||||
TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size + extraSize); | TS_ASSERT_EQUALS(cmpGarrisonable.TotalSize(), size + extraSize); | ||||
// Test garrisoning. | // 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(); | TS_ASSERT(cmpGarrisonable.UnGarrison()); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | ||||
// Test renaming. | // Test renaming. | ||||
const newGarrisonableID = 3; | const newGarrisonableID = 3; | ||||
let cmpGarrisonableNew = ConstructComponent(newGarrisonableID, "Garrisonable", { | let cmpGarrisonableNew = ConstructComponent(newGarrisonableID, "Garrisonable", { | ||||
"Size": 1 | "Size": 1 | ||||
}); | }); | ||||
TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID)); | TS_ASSERT(cmpGarrisonable.Garrison(garrisonHolderID)); | ||||
cmpGarrisonable.OnEntityRenamed({ "entity": garrisonableID, "newentity": newGarrisonableID }); | cmpGarrisonable.OnEntityRenamed({ "entity": garrisonableID, "newentity": newGarrisonableID }); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonable.HolderID(), INVALID_ENTITY); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonableNew.HolderID(), garrisonHolderID); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonableNew.HolderID(), garrisonHolderID); |
Wildfire Games · Phabricator