Differential D1938 Diff 8554 binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | |||||
let cmpUpgrade = ConstructComponent(20, "Upgrade", template.Upgrade); | let cmpUpgrade = ConstructComponent(20, "Upgrade", template.Upgrade); | ||||
cmpUpgrade.owner = playerID; | cmpUpgrade.owner = playerID; | ||||
/** | /** | ||||
* Now to start the test proper | * Now to start the test proper | ||||
* To start with, no techs are researched... | * To start with, no techs are researched... | ||||
*/ | */ | ||||
// T1: Check the cost of the upgrade without a player value being passed (as it would be in the structree). | // T1: Check the cost of the upgrade without a player value being passed (as it would be in the structree). | ||||
let parsed_template = GetTemplateDataHelper(template, null, {}, Resources, DamageTypes); | let parsed_template = GetTemplateDataHelper(template, null, {}, Resources); | ||||
TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | ||||
// T2: Check the value, with a player ID (as it would be in-session). | // T2: Check the value, with a player ID (as it would be in-session). | ||||
parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources, DamageTypes); | parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources); | ||||
TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | ||||
// T3: Check that the value is correct within the Update Component. | // T3: Check that the value is correct within the Update Component. | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | ||||
/** | /** | ||||
* Tell the Upgrade component to start the Upgrade, | * Tell the Upgrade component to start the Upgrade, | ||||
* then mark the technology that alters the upgrade cost as researched. | * then mark the technology that alters the upgrade cost as researched. | ||||
*/ | */ | ||||
cmpUpgrade.Upgrade("structures/"+civCode+"_defense_tower"); | cmpUpgrade.Upgrade("structures/"+civCode+"_defense_tower"); | ||||
isResearched = true; | isResearched = true; | ||||
// T4: Check that the player-less value hasn't increased... | // T4: Check that the player-less value hasn't increased... | ||||
parsed_template = GetTemplateDataHelper(template, null, {}, Resources, DamageTypes); | parsed_template = GetTemplateDataHelper(template, null, {}, Resources); | ||||
TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 100, "wood": 50, "time": 100 }); | ||||
// T5: ...but the player-backed value has. | // T5: ...but the player-backed value has. | ||||
parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources, DamageTypes); | parsed_template = GetTemplateDataHelper(template, playerID, {}, Resources); | ||||
TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 160, "wood": 25, "time": 90 }); | TS_ASSERT_UNEVAL_EQUALS(parsed_template.upgrades[0].cost, { "stone": 160, "wood": 25, "time": 90 }); | ||||
// T6: The upgrade component should still be using the old resource cost (but new time cost) for the upgrade in progress... | // T6: The upgrade component should still be using the old resource cost (but new time cost) for the upgrade in progress... | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 90 }); | TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 100, "wood": 50, "time": 90 }); | ||||
// T7: ...but with the upgrade cancelled, it now uses the modified value. | // T7: ...but with the upgrade cancelled, it now uses the modified value. | ||||
cmpUpgrade.CancelUpgrade(playerID); | cmpUpgrade.CancelUpgrade(playerID); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 160, "wood": 25, "time": 90 }); | TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 160, "wood": 25, "time": 90 }); |
Wildfire Games · Phabricator