Differential D5006 Diff 21823 binaries/data/mods/public/simulation/components/tests/test_Population.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Population.js
Show All 40 Lines | |||||
// Test no change. | // Test no change. | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", | ||||
(valueName, currentValue, entity) => currentValue | (valueName, currentValue, entity) => currentValue | ||||
); | ); | ||||
cmpPlayer = AddMock(player, IID_Player, { | cmpPlayer = AddMock(player, IID_Player, { | ||||
"AddPopulationBonuses": () => TS_ASSERT(false) | "AddPopulationBonuses": () => TS_ASSERT(false) | ||||
}); | }); | ||||
cmpPopulation.OnValueModification({ "component": "bogus" }); | cmpPopulation.OnValueModification(); | ||||
cmpPopulation.OnValueModification({ "component": "Population" }); | |||||
// Test changes. | // Test changes. | ||||
AddMock(entity, IID_Ownership, { | AddMock(entity, IID_Ownership, { | ||||
"GetOwner": () => player | "GetOwner": () => player | ||||
}); | }); | ||||
let difference = 3; | let difference = 3; | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", | ||||
(valueName, currentValue, entity) => currentValue + difference | (valueName, currentValue, entity) => currentValue + difference | ||||
); | ); | ||||
cmpPlayer = AddMock(player, IID_Player, { | cmpPlayer = AddMock(player, IID_Player, { | ||||
"AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, difference) | "AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, difference) | ||||
}); | }); | ||||
spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | ||||
// Foundations don't count yet. | // Foundations don't count yet. | ||||
AddMock(entity, IID_Foundation, {}); | AddMock(entity, IID_Foundation, {}); | ||||
cmpPopulation.OnValueModification({ "component": "Population" }); | cmpPopulation.OnValueModification(); | ||||
TS_ASSERT_EQUALS(spy._called, 0); | TS_ASSERT_EQUALS(spy._called, 0); | ||||
DeleteMock(entity, IID_Foundation); | DeleteMock(entity, IID_Foundation); | ||||
cmpPopulation.OnValueModification({ "component": "Population" }); | cmpPopulation.OnValueModification(); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
// Reset to no bonus. | // Reset to no bonus. | ||||
cmpPlayer = AddMock(player, IID_Player, { | cmpPlayer = AddMock(player, IID_Player, { | ||||
"AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, -3) | "AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, -3) | ||||
}); | }); | ||||
difference = 0; | difference = 0; | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", | ||||
(valueName, currentValue, entity) => currentValue + difference | (valueName, currentValue, entity) => currentValue + difference | ||||
); | ); | ||||
spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | ||||
cmpPopulation.OnValueModification({ "component": "Population" }); | cmpPopulation.OnValueModification(); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
// Test negative change. | // Test negative change. | ||||
difference = -2; | difference = -2; | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", | ||||
(valueName, currentValue, entity) => currentValue + difference | (valueName, currentValue, entity) => currentValue + difference | ||||
); | ); | ||||
cmpPlayer = AddMock(player, IID_Player, { | cmpPlayer = AddMock(player, IID_Player, { | ||||
"AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, difference) | "AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, difference) | ||||
}); | }); | ||||
spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | ||||
cmpPopulation.OnValueModification({ "component": "Population" }); | cmpPopulation.OnValueModification(); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); | ||||
// Test newly created entities also get affected by modifications. | // Test newly created entities also get affected by modifications. | ||||
difference = 3; | difference = 3; | ||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", | ||||
(valueName, currentValue, entity) => currentValue + difference | (valueName, currentValue, entity) => currentValue + difference | ||||
); | ); | ||||
cmpPlayer = AddMock(player, IID_Player, { | cmpPlayer = AddMock(player, IID_Player, { | ||||
"AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, entPopBonus + difference) | "AddPopulationBonuses": bonus => TS_ASSERT_EQUALS(bonus, entPopBonus + difference) | ||||
}); | }); | ||||
spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | spy = new Spy(cmpPlayer, "AddPopulationBonuses"); | ||||
cmpPopulation.OnOwnershipChanged({ "from": INVALID_PLAYER, "to": player }); | cmpPopulation.OnOwnershipChanged({ "from": INVALID_PLAYER, "to": player }); | ||||
TS_ASSERT_EQUALS(spy._called, 1); | TS_ASSERT_EQUALS(spy._called, 1); |
Wildfire Games · Phabricator