Differential D2652 Diff 13601 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("Sound.js"); | Engine.LoadHelperScript("Sound.js"); | ||||
Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | ||||
Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | Engine.LoadComponentScript("interfaces/ProductionQueue.js"); | ||||
Engine.LoadComponentScript("interfaces/BuildRestrictions.js"); | Engine.LoadComponentScript("interfaces/BuildRestrictions.js"); | ||||
Engine.LoadComponentScript("interfaces/EntityLimits.js"); | Engine.LoadComponentScript("interfaces/EntityLimits.js"); | ||||
Engine.LoadComponentScript("interfaces/Foundation.js"); | Engine.LoadComponentScript("interfaces/Foundation.js"); | ||||
Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); | Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); | Engine.LoadComponentScript("interfaces/Timer.js"); | ||||
Engine.LoadComponentScript("interfaces/TrainingRestrictions.js"); | Engine.LoadComponentScript("interfaces/TrainingRestrictions.js"); | ||||
Engine.LoadComponentScript("interfaces/Trigger.js"); | Engine.LoadComponentScript("interfaces/Trigger.js"); | ||||
Engine.LoadComponentScript("interfaces/Upgrade.js"); | |||||
Engine.LoadComponentScript("EntityLimits.js"); | Engine.LoadComponentScript("EntityLimits.js"); | ||||
Engine.RegisterGlobal("Resources", { | Engine.RegisterGlobal("Resources", { | ||||
"BuildSchema": (a, b) => {} | "BuildSchema": (a, b) => {} | ||||
}); | }); | ||||
Engine.LoadComponentScript("ProductionQueue.js"); | Engine.LoadComponentScript("ProductionQueue.js"); | ||||
Engine.LoadComponentScript("TrainingRestrictions.js"); | Engine.LoadComponentScript("TrainingRestrictions.js"); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | function testEntitiesList() | ||||
AddMock(productionQueueId, IID_Ownership, { | AddMock(productionQueueId, IID_Ownership, { | ||||
"GetOwner": () => playerId | "GetOwner": () => playerId | ||||
}); | }); | ||||
AddMock(productionQueueId, IID_Identity, { | AddMock(productionQueueId, IID_Identity, { | ||||
"GetCiv": () => "iber" | "GetCiv": () => "iber" | ||||
}); | }); | ||||
AddMock(productionQueueId, IID_Upgrade, { | |||||
"IsUpgrading": () => false | |||||
}); | |||||
cmpProductionQueue.CalculateEntitiesMap(); | cmpProductionQueue.CalculateEntitiesMap(); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), | cmpProductionQueue.GetEntitiesList(), | ||||
["units/iber_cavalry_javelineer_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | ["units/iber_cavalry_javelineer_b", "units/iber_infantry_swordsman_b", "units/iber_support_female_citizen"] | ||||
); | ); | ||||
TS_ASSERT_UNEVAL_EQUALS( | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetTechnologiesList(), | cmpProductionQueue.GetTechnologiesList(), | ||||
["gather_fishing_net", "phase_town_generic", "phase_city_generic"] | ["gather_fishing_net", "phase_town_generic", "phase_city_generic"] | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | function regression_test_d1879() | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 3); | TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 3); | ||||
// Now check that it doesn't get updated when the spawn doesn't succeed. | // Now check that it doesn't get updated when the spawn doesn't succeed. | ||||
AddMock(testEntity, IID_Footprint, { | AddMock(testEntity, IID_Footprint, { | ||||
"PickSpawnPoint": () => ({ "x": -1, "y": -1, "z": -1 }) | "PickSpawnPoint": () => ({ "x": -1, "y": -1, "z": -1 }) | ||||
}); | }); | ||||
AddMock(testEntity, IID_Upgrade, { | |||||
"IsUpgrading": () => false | |||||
}); | |||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
Engine.QueryInterface(testEntity, IID_ProductionQueue).ProgressTimeout(); | Engine.QueryInterface(testEntity, IID_ProductionQueue).ProgressTimeout(); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 6); | TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 6); | ||||
} | } | ||||
function test_batch_adding() | |||||
{ | |||||
let playerEnt = 2; | |||||
let playerID = 1; | |||||
let testEntity = 3; | |||||
ConstructComponent(playerEnt, "EntityLimits", { | |||||
"Limits": { | |||||
"some_limit": 8 | |||||
}, | |||||
"LimitChangers": {}, | |||||
"LimitRemovers": {} | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_GuiInterface, { | |||||
"PushNotification": () => {} | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_Trigger, { | |||||
"CallEvent": () => {} | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_Timer, { | |||||
"SetTimeout": (ent, iid, func) => {} | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | |||||
"TemplateExists": () => true, | |||||
"GetTemplate": name => ({ | |||||
"Cost": { | |||||
"BuildTime": 0, | |||||
"Population": 1, | |||||
"Resources": {} | |||||
}, | |||||
"TrainingRestrictions": { | |||||
"Category": "some_limit" | |||||
} | |||||
}) | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | |||||
"GetPlayerByID": id => playerEnt | |||||
}); | |||||
AddMock(playerEnt, IID_Player, { | |||||
"GetCiv": () => "iber", | |||||
"GetPlayerID": () => playerID, | |||||
"GetTimeMultiplier": () => 0, | |||||
"BlockTraining": () => {}, | |||||
"UnBlockTraining": () => {}, | |||||
"UnReservePopulationSlots": () => {}, | |||||
"TrySubtractResources": () => true, | |||||
"TryReservePopulationSlots": () => false // Always have pop space. | |||||
}); | |||||
AddMock(testEntity, IID_Ownership, { | |||||
"GetOwner": () => playerID | |||||
}); | |||||
let cmpProdQueue = ConstructComponent(testEntity, "ProductionQueue", { | |||||
"Entities": { "_string": "some_template" }, | |||||
"BatchTimeModifier": 1 | |||||
}); | |||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 0); | |||||
AddMock(testEntity, IID_Upgrade, { | |||||
"IsUpgrading": () => true | |||||
}); | |||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | |||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 0); | |||||
AddMock(testEntity, IID_Upgrade, { | |||||
"IsUpgrading": () => false | |||||
}); | |||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | |||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | |||||
} | |||||
function test_token_changes() | function test_token_changes() | ||||
{ | { | ||||
const ent = 10; | const ent = 10; | ||||
let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | ||||
"Entities": { "_string": "units/{civ}_a " + | "Entities": { "_string": "units/{civ}_a " + | ||||
"units/{civ}_b" }, | "units/{civ}_b" }, | ||||
"Technologies": { "_string": "a " + | "Technologies": { "_string": "a " + | ||||
"b_{civ} " + | "b_{civ} " + | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | TS_ASSERT_UNEVAL_EQUALS( | ||||
cmpProductionQueue.GetEntitiesList(), ["units/test_c", "units/test_d"] | cmpProductionQueue.GetEntitiesList(), ["units/test_c", "units/test_d"] | ||||
); | ); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test_c"); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue()[0].unitTemplate, "units/test_c"); | ||||
TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue().length, 1); | ||||
} | } | ||||
testEntitiesList(); | testEntitiesList(); | ||||
regression_test_d1879(); | regression_test_d1879(); | ||||
test_batch_adding(); | |||||
test_token_changes(); | test_token_changes(); |
Wildfire Games · Phabricator