Differential D681 Diff 4748 binaries/data/mods/public/simulation/components/tests/test_AlertRaiser.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_AlertRaiser.js
Engine.LoadHelperScript("Entity.js"); | |||||
Engine.LoadComponentScript("interfaces/AlertRaiser.js") | Engine.LoadComponentScript("interfaces/AlertRaiser.js") | ||||
Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); | ||||
Engine.LoadComponentScript("interfaces/Sound.js"); | |||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("AlertRaiser.js"); | Engine.LoadComponentScript("AlertRaiser.js"); | ||||
const alertRaiserId = 5; | const alertRaiserID = 5; | ||||
const unitsIds = [10, 11, 12]; | const unitIDs = [10, 11, 12]; | ||||
const buildingsIds = [13, 14, 15]; | const buildingIDs = [13, 14, 15]; | ||||
let cmpAlertRaiser = ConstructComponent(alertRaiserId, "AlertRaiser", { | let cmpAlertRaiser = ConstructComponent(alertRaiserID, "AlertRaiser", { | ||||
"MaximumLevel": 0, | "MaximumLevel": 0, | ||||
"Range": 50 | "Range": 50 | ||||
}); | }); | ||||
Engine.RegisterGlobal("PlaySound", (name, source) => { | Engine.RegisterGlobal("PlaySound", (name, source) => { | ||||
TS_ASSERT_EQUALS(name, "alert" + cmpAlertRaiser.GetLevel()); | TS_ASSERT_EQUALS(name, "alert" + cmpAlertRaiser.GetLevel()); | ||||
TS_ASSERT_EQUALS(source, alertRaiserId); | TS_ASSERT_EQUALS(source, alertRaiserID); | ||||
}); | |||||
AddMock(alertRaiserID, IID_Ownership, { | |||||
"GetOwner": () => 1 | |||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
"ExecuteQuery": (ent, value, range, players, iid) => iid === IID_UnitAI ? unitsIds : buildingsIds | "ExecuteQuery": (ent, value, range, players, iid) => iid === IID_UnitAI ? unitIDs : buildingIDs | ||||
}); | }); | ||||
unitsIds.forEach((unitId) => { | for (let unitID of unitIDs) | ||||
AddMock(unitId, IID_UnitAI, { | AddMock(unitID, IID_UnitAI, { | ||||
"ReactsToAlert": (alertLevel) => alertLevel >= 2, | "ReactsToAlert": (alertLevel) => alertLevel >= 2, | ||||
"ReplaceOrder": () => {}, | "ReplaceOrder": () => {}, | ||||
"IsUnderAlert": () => {}, | |||||
"HasWorkOrders": () => true, | "HasWorkOrders": () => true, | ||||
"BackToWork": () => {}, | "HasGarrisonOrder": () => true, | ||||
"ResetAlert": () => {} | "BackToWork": () => {} | ||||
}); | |||||
}); | }); | ||||
buildingsIds.forEach((buildingId) => { | for (let buildingID of buildingIDs) | ||||
AddMock(buildingId, IID_ProductionQueue, { | AddMock(buildingID, IID_GarrisonHolder, { | ||||
"PutUnderAlert": (alertRaiserId) => {}, | "GetCapacity": () => 10, | ||||
"ResetAlert": () => {} | "GetGarrisonedEntitiesCount": () => 0, | ||||
}); | "IsAllowedToGarrison": () => true, | ||||
"GetEntities": () => [] | |||||
}); | }); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); | TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), false); | TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), false); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), false); | TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), false); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), false); | TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), false); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); | |||||
cmpAlertRaiser = ConstructComponent(alertRaiserId, "AlertRaiser", { | cmpAlertRaiser = ConstructComponent(alertRaiserID, "AlertRaiser", { | ||||
"MaximumLevel": 2, | "MaximumLevel": 2, | ||||
"Range": 50 | "Range": 50 | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), false); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), true); | TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), true); | ||||
cmpAlertRaiser.UpdateUnits([]); | |||||
cmpAlertRaiser.UpdateUnits(unitsIds); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpAlertRaiser.walkingUnits, []); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), true); | TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), true); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 1); | TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAlertRaiser.prodBuildings, buildingsIds); | TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), true); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), true); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), true); | TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), true); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 2); | TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 2); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAlertRaiser.walkingUnits, unitsIds); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), false); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), true); | TS_ASSERT_EQUALS(cmpAlertRaiser.HasRaisedAlert(), true); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.CanIncreaseLevel(), false); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.IncreaseAlertLevel(), false); | |||||
TS_ASSERT_EQUALS(cmpAlertRaiser.EndOfAlert(), true); | TS_ASSERT_EQUALS(cmpAlertRaiser.EndOfAlert(), true); | ||||
TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); | TS_ASSERT_EQUALS(cmpAlertRaiser.GetLevel(), 0); |
Wildfire Games · Phabricator