Differential D2315 Diff 9911 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ModifiersManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ModifiersManager.js
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
let data = cmpModifiersManager.Serialize(); | let data = cmpModifiersManager.Serialize(); | ||||
cmpModifiersManager = ConstructComponent(SYSTEM_ENTITY, "ModifiersManager", {}); | cmpModifiersManager = ConstructComponent(SYSTEM_ENTITY, "ModifiersManager", {}); | ||||
cmpModifiersManager.Deserialize(data); | cmpModifiersManager.Deserialize(data); | ||||
} | } | ||||
cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST, "from": -1, "to": PLAYER_ENTITY_ID }); | cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST, "from": -1, "to": PLAYER_ENTITY_ID }); | ||||
cmpModifiersManager.AddModifier("Test_A", "Test_A_0", { "affects": ["Structure"], "add": 10 }, 10, "testLol"); | cmpModifiersManager.AddModifier("Test_A", "Test_A_0", [{ "affects": ["Structure"], "add": 10 }], 10, "testLol"); | ||||
cmpModifiersManager.AddModifier("Test_A", "Test_A_0", { "affects": ["Structure"], "add": 10 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_A", "Test_A_0", [{ "affects": ["Structure"], "add": 10 }], PLAYER_ENTITY_ID); | ||||
cmpModifiersManager.AddModifier("Test_A", "Test_A_1", { "affects": ["Infantry"], "add": 5 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_A", "Test_A_1", [{ "affects": ["Infantry"], "add": 5 }], PLAYER_ENTITY_ID); | ||||
cmpModifiersManager.AddModifier("Test_A", "Test_A_2", { "affects": ["Unit"], "add": 3 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_A", "Test_A_2", [{ "affects": ["Unit"], "add": 3 }], PLAYER_ENTITY_ID); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, PLAYER_ENTITY_ID), 5); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, PLAYER_ENTITY_ID), 5); | ||||
cmpModifiersManager.AddModifier("Test_A", "Test_A_Player", { "affects": ["Player"], "add": 3 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_A", "Test_A_Player", [{ "affects": ["Player"], "add": 3 }], PLAYER_ENTITY_ID); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, PLAYER_ENTITY_ID), 8); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, PLAYER_ENTITY_ID), 8); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 6), 10); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 6), 10); | ||||
SerializationCycle(); | SerializationCycle(); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 6), 10); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 6), 10); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 7), 8); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 7), 8); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 8), 18); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 8), 18); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_B", 5, 8), 5); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_B", 5, 8), 5); | ||||
cmpModifiersManager.RemoveAllModifiers("Test_A_0", PLAYER_ENTITY_ID); | cmpModifiersManager.RemoveAllModifiers("Test_A_0", PLAYER_ENTITY_ID); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 5); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 5); | ||||
cmpModifiersManager.AddModifiers("Test_A_0", { | cmpModifiersManager.AddModifiers("Test_A_0", { | ||||
"Test_A": { "affects": ["Structure"], "add": 10 }, | "Test_A": [{ "affects": ["Structure"], "add": 10 }], | ||||
"Test_B": { "affects": ["Structure"], "add": 8 }, | "Test_B": [{ "affects": ["Structure"], "add": 8 }], | ||||
}, PLAYER_ENTITY_ID); | }, PLAYER_ENTITY_ID); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_A", 5, 5), 15); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_B", 5, 8), 13); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_B", 5, 8), 13); | ||||
// Add two local modifications, only the first should stick. | // Add two local modifications, only the first should stick. | ||||
cmpModifiersManager.AddModifier("Test_C", "Test_C_0", { "affects": ["Structure"], "add": 10 }, 5); | cmpModifiersManager.AddModifier("Test_C", "Test_C_0", [{ "affects": ["Structure"], "add": 10 }], 5); | ||||
cmpModifiersManager.AddModifier("Test_C", "Test_C_1", { "affects": ["Unit"], "add": 5 }, 5); | cmpModifiersManager.AddModifier("Test_C", "Test_C_1", [{ "affects": ["Unit"], "add": 5 }], 5); | ||||
SerializationCycle(); | SerializationCycle(); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 15); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 15); | ||||
// test that local modifications are indeed applied after global managers | // test that local modifications are indeed applied after global managers | ||||
cmpModifiersManager.AddModifier("Test_C", "Test_C_2", { "affects": ["Structure"], "replace": 0 }, 5); | cmpModifiersManager.AddModifier("Test_C", "Test_C_2", [{ "affects": ["Structure"], "replace": 0 }], 5); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 0); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 0); | ||||
TS_ASSERT(!cmpModifiersManager.HasAnyModifier("Test_C_3", PLAYER_ENTITY_ID)); | TS_ASSERT(!cmpModifiersManager.HasAnyModifier("Test_C_3", PLAYER_ENTITY_ID)); | ||||
SerializationCycle(); | SerializationCycle(); | ||||
// check that things still work properly if we change global modifications | // check that things still work properly if we change global modifications | ||||
cmpModifiersManager.AddModifier("Test_C", "Test_C_3", { "affects": ["Structure"], "add": 10 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_C", "Test_C_3", [{ "affects": ["Structure"], "add": 10 }], PLAYER_ENTITY_ID); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 0); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_C", 5, 5), 0); | ||||
TS_ASSERT(cmpModifiersManager.HasAnyModifier("Test_C_3", PLAYER_ENTITY_ID)); | TS_ASSERT(cmpModifiersManager.HasAnyModifier("Test_C_3", PLAYER_ENTITY_ID)); | ||||
TS_ASSERT(cmpModifiersManager.HasModifier("Test_C", "Test_C_3", PLAYER_ENTITY_ID)); | TS_ASSERT(cmpModifiersManager.HasModifier("Test_C", "Test_C_3", PLAYER_ENTITY_ID)); | ||||
TS_ASSERT(cmpModifiersManager.HasModifier("Test_C", "Test_C_2", 5)); | TS_ASSERT(cmpModifiersManager.HasModifier("Test_C", "Test_C_2", 5)); | ||||
// test removal | // test removal | ||||
cmpModifiersManager.RemoveModifier("Test_C", "Test_C_2", 5); | cmpModifiersManager.RemoveModifier("Test_C", "Test_C_2", 5); | ||||
Show All 11 Lines | |||||
AddMock(PLAYER_ENTITY_ID + 1, IID_Player, { | AddMock(PLAYER_ENTITY_ID + 1, IID_Player, { | ||||
"GetPlayerID": () => PLAYER_ID_FOR_TEST + 1 | "GetPlayerID": () => PLAYER_ID_FOR_TEST + 1 | ||||
}); | }); | ||||
cmpModifiersManager = ConstructComponent(SYSTEM_ENTITY, "ModifiersManager", {}); | cmpModifiersManager = ConstructComponent(SYSTEM_ENTITY, "ModifiersManager", {}); | ||||
cmpModifiersManager.Init(); | cmpModifiersManager.Init(); | ||||
cmpModifiersManager.AddModifier("Test_D", "Test_D_0", { "affects": ["Structure"], "add": 10 }, PLAYER_ENTITY_ID); | cmpModifiersManager.AddModifier("Test_D", "Test_D_0", [{ "affects": ["Structure"], "add": 10 }], PLAYER_ENTITY_ID); | ||||
cmpModifiersManager.AddModifier("Test_D", "Test_D_1", { "affects": ["Structure"], "add": 1 }, PLAYER_ENTITY_ID + 1); | cmpModifiersManager.AddModifier("Test_D", "Test_D_1", [{ "affects": ["Structure"], "add": 1 }], PLAYER_ENTITY_ID + 1); | ||||
cmpModifiersManager.AddModifier("Test_D", "Test_D_2", { "affects": ["Structure"], "add": 5 }, 5); | cmpModifiersManager.AddModifier("Test_D", "Test_D_2", [{ "affects": ["Structure"], "add": 5 }], 5); | ||||
cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST, "from": -1, "to": PLAYER_ENTITY_ID }); | cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST, "from": -1, "to": PLAYER_ENTITY_ID }); | ||||
cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST + 1, "from": -1, "to": PLAYER_ENTITY_ID + 1 }); | cmpModifiersManager.OnGlobalPlayerEntityChanged({ "player": PLAYER_ID_FOR_TEST + 1, "from": -1, "to": PLAYER_ENTITY_ID + 1 }); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_D", 10, 5), 25); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_D", 10, 5), 25); | ||||
cmpModifiersManager.OnGlobalOwnershipChanged({ "entity": 5, "from": PLAYER_ID_FOR_TEST, "to": PLAYER_ID_FOR_TEST + 1 }); | cmpModifiersManager.OnGlobalOwnershipChanged({ "entity": 5, "from": PLAYER_ID_FOR_TEST, "to": PLAYER_ID_FOR_TEST + 1 }); | ||||
AddMock(5, IID_Ownership, { | AddMock(5, IID_Ownership, { | ||||
"GetOwner": () => PLAYER_ID_FOR_TEST + 1 | "GetOwner": () => PLAYER_ID_FOR_TEST + 1 | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_D", 10, 5), 16); | TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test_D", 10, 5), 16); |
Wildfire Games · Phabricator