Differential D2652 Diff 13450 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
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("ValueModification.js"); | Engine.LoadHelperScript("ValueModification.js"); | ||||
Resources = { | Resources = { | ||||
"BuildSchema": type => { | "BuildSchema": type => { | ||||
let schema = ""; | let schema = ""; | ||||
for (let res of ["food", "metal", "stone", "wood"]) | for (let res of ["food", "metal", "stone", "wood"]) | ||||
schema += | schema += | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='" + res + "'>" + | "<element name='" + res + "'>" + | ||||
"<ref name='" + type + "'/>" + | "<ref name='" + type + "'/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>"; | "</optional>"; | ||||
return "<interleave>" + schema + "</interleave>"; | return "<interleave>" + schema + "</interleave>"; | ||||
} | } | ||||
}; | }; | ||||
Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | |||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js"); // Provides `IID_ModifiersManager`, used below. | Engine.LoadComponentScript("interfaces/ModifiersManager.js"); // Provides `IID_ModifiersManager`, used below. | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); // Provides `IID_Timer`, used below. | Engine.LoadComponentScript("interfaces/Timer.js"); // Provides `IID_Timer`, used below. | ||||
// What we're testing: | // What we're testing: | ||||
Engine.LoadComponentScript("interfaces/Upgrade.js"); | Engine.LoadComponentScript("interfaces/Upgrade.js"); | ||||
Engine.LoadComponentScript("Upgrade.js"); | Engine.LoadComponentScript("Upgrade.js"); | ||||
// Input (bare minimum needed for tests): | // Input (bare minimum needed for tests): | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"GetTemplate": () => template // Called in components/Upgrade.js::ChangeUpgradedEntityCount(). | "GetTemplate": () => template // Called in components/Upgrade.js::ChangeUpgradedEntityCount(). | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_Timer, { | AddMock(SYSTEM_ENTITY, IID_Timer, { | ||||
"SetInterval": () => 1, // Called in components/Upgrade.js::Upgrade(). | "SetInterval": () => 1, // Called in components/Upgrade.js::Upgrade(). | ||||
"CancelTimer": () => {} // Called in components/Upgrade.js::CancelUpgrade(). | "CancelTimer": () => {} // Called in components/Upgrade.js::CancelUpgrade(). | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_ModifiersManager, { | AddMock(SYSTEM_ENTITY, IID_ModifiersManager, { | ||||
"ApplyTemplateModifiers": (valueName, curValue, template, player) => { | "ApplyTemplateModifiers": (valueName, curValue, template, player) => { | ||||
Lint: ESLintBear (no-shadow): `'template' is already declared in the upper scope.` | |||||
// Called in helpers/ValueModification.js::ApplyValueModificationsToTemplate() | // Called in helpers/ValueModification.js::ApplyValueModificationsToTemplate() | ||||
// as part of Tests T2 and T5 below. | // as part of Tests T2 and T5 below. | ||||
let mods = isResearched ? templateTechModifications.with : templateTechModifications.without; | let mods = isResearched ? templateTechModifications.with : templateTechModifications.without; | ||||
if (mods[valueName]) | if (mods[valueName]) | ||||
return GetTechModifiedProperty(mods[valueName], GetIdentityClasses(template.Identity), curValue); | return GetTechModifiedProperty(mods[valueName], GetIdentityClasses(template.Identity), curValue); | ||||
return curValue; | return curValue; | ||||
}, | }, | ||||
Show All 14 Lines | |||||
// Create an entity with an Upgrade component: | // Create an entity with an Upgrade component: | ||||
AddMock(20, IID_Ownership, { | AddMock(20, IID_Ownership, { | ||||
"GetOwner": () => playerID // Called in helpers/Player.js::QueryOwnerInterface(). | "GetOwner": () => playerID // Called in helpers/Player.js::QueryOwnerInterface(). | ||||
}); | }); | ||||
AddMock(20, IID_Identity, { | AddMock(20, IID_Identity, { | ||||
"GetCiv": () => civCode // Called in components/Upgrade.js::init(). | "GetCiv": () => civCode // Called in components/Upgrade.js::init(). | ||||
}); | }); | ||||
AddMock(20, IID_ProductionQueue, { | |||||
"HasQueuedProduction": () => false | |||||
}) | |||||
Lint: ESLintBear (semi) Missing semicolon. Lint: ESLintBear (semi): `Missing semicolon.` | |||||
Lint: JSHintBear Missing semicolon. Lint: JSHintBear: `Missing semicolon.` | |||||
bbUnsubmitted Not Done Inline Actionsfix linter bb: fix linter | |||||
Not Done Inline ActionsIf it is false and not used one can omit it. Freagarach: If it is false and not used one can omit it. | |||||
Not Done Inline Actions^ Freagarach: ^ | |||||
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). | ||||
Show All 31 Lines |
Wildfire Games · Phabricator
'template' is already declared in the upper scope.