diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 525353638f..8565f821da 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -254,7 +254,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent) }; } - if (!cmpFoundation && cmpIdentity.HasClass("BarterMarket")) + if (!cmpFoundation && cmpIdentity && cmpIdentity.HasClass("BarterMarket")) { var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter); ret.barterMarket = { "prices": cmpBarter.GetPrices() }; diff --git a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js index b8ec7e8de5..09a6fa59f2 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js @@ -1,4 +1,5 @@ Engine.LoadComponentScript("interfaces/Attack.js"); +Engine.LoadComponentScript("interfaces/Barter.js"); Engine.LoadComponentScript("interfaces/Builder.js"); Engine.LoadComponentScript("interfaces/BuildLimits.js"); Engine.LoadComponentScript("interfaces/DamageReceiver.js"); @@ -18,14 +19,17 @@ Engine.LoadComponentScript("GuiInterface.js"); var cmp = ConstructComponent(SYSTEM_ENTITY, "GuiInterface"); -AddMock(SYSTEM_ENTITY, IID_PlayerManager, { - GetNumPlayers: function() { return 2; }, - GetPlayerByID: function(id) { TS_ASSERT(id === 0 || id === 1); return 100+id; } + +AddMock(SYSTEM_ENTITY, IID_Barter, { + GetPrices: function() { return { + "buy": { "food": 150 }, + "sell": { "food": 25 }, + }}, }); -AddMock(SYSTEM_ENTITY, IID_TemplateManager, { - GetCurrentTemplateName: function(ent) { return "example"; }, - GetTemplate: function(name) { return ""; }, +AddMock(SYSTEM_ENTITY, IID_PlayerManager, { + GetNumPlayers: function() { return 2; }, + GetPlayerByID: function(id) { TS_ASSERT(id === 0 || id === 1); return 100+id; }, }); AddMock(SYSTEM_ENTITY, IID_RangeManager, { @@ -33,6 +37,11 @@ AddMock(SYSTEM_ENTITY, IID_RangeManager, { GetLosCircular: function() { return false; }, }); +AddMock(SYSTEM_ENTITY, IID_TemplateManager, { + GetCurrentTemplateName: function(ent) { return "example"; }, + GetTemplate: function(name) { return ""; }, +}); + AddMock(SYSTEM_ENTITY, IID_Timer, { GetTime: function() { return 0; }, SetTimeout: function(ent, iid, funcname, time, data) { return 0; }, @@ -133,6 +142,9 @@ AddMock(101, IID_StatisticsTracker, { IncreaseBuiltCivCentresCounter: function() { return 1; }, }); +// Note: property order matters when using TS_ASSERT_UNEVAL_EQUALS, +// because uneval preserves property order. So make sure this object +// matches the ordering in GuiInterface. TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { players: [ { @@ -248,12 +260,9 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { }); -AddMock(10, IID_Position, { - GetPosition: function() { - return {x:1, y:2, z:3}; - }, - IsInWorld: function() { - return true; +AddMock(10, IID_Builder, { + GetEntitiesList: function() { + return ["test1", "test2"]; }, }); @@ -263,20 +272,40 @@ AddMock(10, IID_Health, { IsRepairable: function() { return false; }, }); -AddMock(10, IID_Builder, { - GetEntitiesList: function() { - return ["test1", "test2"]; - } +AddMock(10, IID_Identity, { + GetClassesList: function() { return ["class1", "class2"]; }, + GetRank: function() { return "foo"; }, + GetSelectionGroupName: function() { return "Selection Group Name"; }, + HasClass: function() { return true; }, }); -var state = cmp.GetEntityState(-1, 10); -TS_ASSERT_UNEVAL_EQUALS(state, { +AddMock(10, IID_Position, { + GetPosition: function() { + return {x:1, y:2, z:3}; + }, + IsInWorld: function() { + return true; + }, +}); + +// Note: property order matters when using TS_ASSERT_UNEVAL_EQUALS, +// because uneval preserves property order. So make sure this object +// matches the ordering in GuiInterface. +TS_ASSERT_UNEVAL_EQUALS(cmp.GetEntityState(-1, 10), { id: 10, template: "example", + identity: { + rank: "foo", + classes: ["class1", "class2"], + selectionGroupName: "Selection Group Name", + }, position: {x:1, y:2, z:3}, hitpoints: 50, maxHitpoints: 60, needsRepair: false, buildEntities: ["test1", "test2"], + barterMarket: { + prices: { "buy": {"food":150}, "sell": {"food":25} }, + }, visibility: "visible", }); diff --git a/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js b/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js index ed0f5fb718..be0ac855d0 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js +++ b/binaries/data/mods/public/simulation/components/tests/test_UnitAI.js @@ -1,5 +1,6 @@ Engine.LoadHelperScript("FSM.js"); Engine.LoadHelperScript("Entity.js"); +Engine.LoadHelperScript("Player.js"); Engine.LoadComponentScript("interfaces/Attack.js"); Engine.LoadComponentScript("interfaces/DamageReceiver.js"); Engine.LoadComponentScript("interfaces/Formation.js");