Differential D3150 Diff 16734 binaries/data/mods/public/simulation/components/tests/test_Garrisoning.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Garrisoning.js
Engine.LoadHelperScript("ValueModification.js"); | Engine.LoadHelperScript("ValueModification.js"); | ||||
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.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/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); | Engine.LoadComponentScript("interfaces/Timer.js"); | ||||
Engine.LoadComponentScript("interfaces/TurretHolder.js"); | |||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Garrisonable.js"); | Engine.LoadComponentScript("Garrisonable.js"); | ||||
Engine.LoadComponentScript("GarrisonHolder.js"); | Engine.LoadComponentScript("GarrisonHolder.js"); | ||||
Engine.LoadComponentScript("TurretHolder.js"); | |||||
const player = 1; | const player = 1; | ||||
const enemyPlayer = 2; | const enemyPlayer = 2; | ||||
const friendlyPlayer = 3; | const friendlyPlayer = 3; | ||||
const garrison = 10; | const garrison = 10; | ||||
const holder = 11; | const holder = 11; | ||||
let createGarrisonCmp = entity => { | let createGarrisonCmp = entity => { | ||||
AddMock(entity, IID_Identity, { | AddMock(entity, IID_Identity, { | ||||
"GetClassesList": () => ["Ranged"], | "GetClassesList": () => ["Ranged"], | ||||
"GetSelectionGroupName": () => "mace_infantry_archer_a" | "GetSelectionGroupName": () => "mace_infantry_archer_a" | ||||
}); | }); | ||||
AddMock(entity, IID_Ownership, { | AddMock(entity, IID_Ownership, { | ||||
"GetOwner": () => player | "GetOwner": () => player | ||||
}); | }); | ||||
AddMock(entity, IID_Position, { | AddMock(entity, IID_Position, { | ||||
"GetHeightOffset": () => 0, | "GetHeightOffset": () => 0, | ||||
"GetPosition": () => new Vector3D(4, 3, 25), | "GetPosition": () => new Vector3D(4, 3, 25), | ||||
"GetRotation": () => new Vector3D(4, 0, 6), | "GetRotation": () => new Vector3D(4, 0, 6), | ||||
"JumpTo": (posX, posZ) => {}, | "JumpTo": (posX, posZ) => {}, | ||||
"MoveOutOfWorld": () => {}, | "MoveOutOfWorld": () => {}, | ||||
"SetHeightOffset": height => {}, | "SetHeightOffset": height => {}, | ||||
"SetTurretParent": ent => {}, | |||||
"SetYRotation": angle => {} | "SetYRotation": angle => {} | ||||
}); | }); | ||||
return ConstructComponent(entity, "Garrisonable", { | return ConstructComponent(entity, "Garrisonable", { | ||||
"Size": "1" | "Size": "1" | ||||
}); | }); | ||||
}; | }; | ||||
Show All 37 Lines | |||||
AddMock(garrison, IID_Position, { | AddMock(garrison, IID_Position, { | ||||
"GetHeightOffset": () => 0, | "GetHeightOffset": () => 0, | ||||
"GetPosition": () => new Vector3D(4, 3, 25), | "GetPosition": () => new Vector3D(4, 3, 25), | ||||
"GetRotation": () => new Vector3D(4, 0, 6), | "GetRotation": () => new Vector3D(4, 0, 6), | ||||
"JumpTo": (posX, posZ) => {}, | "JumpTo": (posX, posZ) => {}, | ||||
"MoveOutOfWorld": () => {}, | "MoveOutOfWorld": () => {}, | ||||
"SetHeightOffset": height => {}, | "SetHeightOffset": height => {}, | ||||
"SetTurretParent": entity => {}, | |||||
"SetYRotation": angle => {} | "SetYRotation": angle => {} | ||||
}); | }); | ||||
let cmpGarrisonable = ConstructComponent(garrison, "Garrisonable", { | let cmpGarrisonable = ConstructComponent(garrison, "Garrisonable", { | ||||
"Size": "1" | "Size": "1" | ||||
}); | }); | ||||
let cmpGarrisonHolder = ConstructComponent(holder, "GarrisonHolder", { | let cmpGarrisonHolder = ConstructComponent(holder, "GarrisonHolder", { | ||||
Show All 38 Lines | AddMock(entities[0], IID_Ownership, { | ||||
"GetOwner": () => enemyPlayer | "GetOwner": () => enemyPlayer | ||||
}); | }); | ||||
cmpGarrisonHolder.OnDiplomacyChanged(); | cmpGarrisonHolder.OnDiplomacyChanged(); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetGarrisonedEntitiesCount(), entities.length - 1); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetGarrisonedEntitiesCount(), entities.length - 1); | ||||
TS_ASSERT(cmpGarrisonHolder.UnloadAll()); | TS_ASSERT(cmpGarrisonHolder.UnloadAll()); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetEntities(), []); | TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetEntities(), []); | ||||
// Turrets! | |||||
AddMock(holder, IID_Position, { | |||||
"GetPosition": () => new Vector3D(4, 3, 25), | |||||
"GetRotation": () => new Vector3D(4, 0, 6) | |||||
}); | |||||
let cmpTurretHolder = ConstructComponent(holder, "TurretHolder", { | |||||
"TurretPoints": { | |||||
"archer1": { | |||||
"X": "12.0", | |||||
"Y": "5.", | |||||
"Z": "6.0" | |||||
}, | |||||
"archer2": { | |||||
"X": "15.0", | |||||
"Y": "5.0", | |||||
"Z": "6.0" | |||||
} | |||||
} | |||||
}); | |||||
TS_ASSERT(cmpGarrisonable.Garrison(holder)); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetEntities(), [garrison]); | |||||
TS_ASSERT(cmpTurretHolder.OccupiesTurret(garrison)); | |||||
TS_ASSERT(cmpGarrisonable.UnGarrison()); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpGarrisonHolder.GetEntities(), []); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpTurretHolder.GetEntities(), []); | |||||
// Test renaming on a turret. | |||||
// Ensure we test renaming from the second spot, not the first. | |||||
const newGarrison = 31; | |||||
let cmpGarrisonableNew = createGarrisonCmp(newGarrison); | |||||
TS_ASSERT(cmpGarrisonableNew.Garrison(holder)); | |||||
TS_ASSERT(cmpGarrisonable.Garrison(holder)); | |||||
TS_ASSERT(cmpGarrisonableNew.UnGarrison()); | |||||
let previousTurret = cmpTurretHolder.GetOccupiedTurretName(garrison); | |||||
cmpGarrisonable.OnEntityRenamed({ | |||||
"entity": garrison, | |||||
"newentity": newGarrison | |||||
}); | |||||
let newTurret = cmpTurretHolder.GetOccupiedTurretName(newGarrison); | |||||
TS_ASSERT_UNEVAL_EQUALS(newTurret, previousTurret); | |||||
TS_ASSERT(cmpGarrisonableNew.UnGarrison()); | |||||
// Test initTurrets. | |||||
cmpTurretHolder.SetInitEntity("archer1", garrison); | |||||
cmpTurretHolder.SetInitEntity("archer2", newGarrison); | |||||
cmpTurretHolder.OnGlobalInitGame(); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpTurretHolder.GetEntities(), [garrison, newGarrison]); |
Wildfire Games · Phabricator