Differential D2492 Diff 10733 binaries/data/mods/public/simulation/components/tests/test_Foundation.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Foundation.js
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("ValueModification.js"); | |||||
Engine.LoadComponentScript("interfaces/Builder.js"); | Engine.LoadComponentScript("interfaces/Builder.js"); | ||||
Engine.LoadComponentScript("interfaces/Cost.js"); | Engine.LoadComponentScript("interfaces/Cost.js"); | ||||
Engine.LoadComponentScript("interfaces/Foundation.js"); | Engine.LoadComponentScript("interfaces/Foundation.js"); | ||||
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js"); | |||||
Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); | Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); | ||||
Engine.LoadComponentScript("interfaces/TerritoryDecay.js"); | Engine.LoadComponentScript("interfaces/TerritoryDecay.js"); | ||||
Engine.LoadComponentScript("interfaces/Trigger.js"); | Engine.LoadComponentScript("interfaces/Trigger.js"); | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); | |||||
Engine.LoadComponentScript("Foundation.js"); | Engine.LoadComponentScript("Foundation.js"); | ||||
Engine.LoadComponentScript("Timer.js"); | |||||
let player = 1; | let player = 1; | ||||
let playerEnt = 3; | let playerEnt = 3; | ||||
let foundationEnt = 20; | let foundationEnt = 20; | ||||
let previewEnt = 21; | let previewEnt = 21; | ||||
let newEnt = 22; | let newEnt = 22; | ||||
let finalTemplate = "structures/athen_civil_centre.xml"; | |||||
function testFoundation(...mocks) | function testFoundation(...mocks) | ||||
{ | { | ||||
ResetState(); | ResetState(); | ||||
let finalTemplate = "structures/athen_civil_centre.xml"; | |||||
let foundationHP = 1; | let foundationHP = 1; | ||||
let maxHP = 100; | let maxHP = 100; | ||||
let rot = new Vector3D(1, 2, 3); | let rot = new Vector3D(1, 2, 3); | ||||
let pos = new Vector2D(4, 5); | let pos = new Vector2D(4, 5); | ||||
let cmpFoundation; | let cmpFoundation; | ||||
AddMock(SYSTEM_ENTITY, IID_Trigger, { | AddMock(SYSTEM_ENTITY, IID_Trigger, { | ||||
"CallEvent": () => {}, | "CallEvent": () => {}, | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | |||||
}]); | }]); | ||||
testFoundation([playerEnt, IID_StatisticsTracker, { | testFoundation([playerEnt, IID_StatisticsTracker, { | ||||
"IncreaseConstructedBuildingsCounter": ent => { | "IncreaseConstructedBuildingsCounter": ent => { | ||||
TS_ASSERT_EQUALS(ent, newEnt); | TS_ASSERT_EQUALS(ent, newEnt); | ||||
}, | }, | ||||
}]); | }]); | ||||
// Test autobuild feature. | |||||
const foundationEnt2 = 42; | |||||
let turnLength = 0.2; | |||||
let currentFoundationHP = 1; | |||||
let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer"); | |||||
const cmpAutoBuildingFoundation = ConstructComponent(foundationEnt2, "Foundation", { "AutoBuild": { "Rate": "1.0" } }); | |||||
AddMock(foundationEnt2, IID_Cost, { | |||||
"GetBuildTime": () => 50, | |||||
"GetResourceCosts": () => ({ "wood": 100 }), | |||||
}); | |||||
AddMock(foundationEnt2, IID_Health, { | |||||
"GetHitpoints": () => currentFoundationHP, | |||||
"GetMaxHitpoints": () => 100, | |||||
"Increase": hp => { | |||||
currentFoundationHP = Math.min(currentFoundationHP + hp, 100); | |||||
cmpAutoBuildingFoundation.OnHealthChanged(); | |||||
}, | |||||
Freagarach: This ought to be updated. | |||||
}); | |||||
cmpAutoBuildingFoundation.InitialiseConstruction(player, finalTemplate); | |||||
// We start at 3 cause there is no delay on the first run. | |||||
cmpTimer.OnUpdate({ "turnLength": turnLength }); | |||||
for (let i = 0; i < 10; ++i) | |||||
{ | |||||
if (i == 8) | |||||
{ | |||||
cmpAutoBuildingFoundation.CancelTimer(); | |||||
Done Inline Actionsbecause(/since/for) Freagarach: `because`(/`since`/`for`)
Although I am not sure where we start at three? | |||||
Done Inline ActionsNot sure either, it seems it executes the function no matter what the first time I run OnUpdate. Stan: Not sure either, it seems it executes the function no matter what the first time I run OnUpdate. | |||||
TS_ASSERT_EQUALS(cmpAutoBuildingFoundation.GetNumBuilders(), 0); | |||||
} | |||||
let currentPercentage = cmpAutoBuildingFoundation.GetBuildPercentage(); | |||||
cmpTimer.OnUpdate({ "turnLength": turnLength * 5 }); | |||||
let newPercentage = cmpAutoBuildingFoundation.GetBuildPercentage(); | |||||
if (i >= 8) | |||||
TS_ASSERT_EQUALS(currentPercentage, newPercentage); | |||||
else | |||||
// Rate * Max Health / Cost. | |||||
TS_ASSERT_EQUALS(currentPercentage + 2, newPercentage); | |||||
} |
Wildfire Games · Phabricator
This ought to be updated.