Index: binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/GuiInterface.js +++ binaries/data/mods/public/simulation/components/GuiInterface.js @@ -5,9 +5,9 @@ GuiInterface.prototype.Serialize = function() { - // This component isn't network-synchronised for the biggest part - // So most of the attributes shouldn't be serialized - // Return an object with a small selection of deterministic data + // This component isn't network-synchronised for the biggest part, + // so most of the attributes shouldn't be serialized. + // Return an object with a small selection of deterministic data. return { "timeNotifications": this.timeNotifications, "timeNotificationID": this.timeNotificationID @@ -62,20 +62,18 @@ let cmpPlayer = QueryPlayerIDInterface(i); let cmpPlayerEntityLimits = QueryPlayerIDInterface(i, IID_EntityLimits); - // Work out what phase we are in + // Work out what phase we are in. let phase = ""; let cmpTechnologyManager = QueryPlayerIDInterface(i, IID_TechnologyManager); if (cmpTechnologyManager) - { if (cmpTechnologyManager.IsTechnologyResearched("phase_city")) phase = "city"; else if (cmpTechnologyManager.IsTechnologyResearched("phase_town")) phase = "town"; else if (cmpTechnologyManager.IsTechnologyResearched("phase_village")) phase = "village"; - } - // store player ally/neutral/enemy data as arrays + // Store player ally/neutral/enemy data as arrays. let allies = []; let mutualAllies = []; let neutrals = []; @@ -135,11 +133,11 @@ if (cmpTerrain) ret.mapSize = cmpTerrain.GetMapSize(); - // Add timeElapsed + // Add timeElapsed. let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); ret.timeElapsed = cmpTimer.GetTime(); - // Add ceasefire info + // Add ceasefire info. let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager); if (cmpCeasefireManager) { @@ -147,17 +145,17 @@ ret.ceasefireTimeRemaining = ret.ceasefireActive ? cmpCeasefireManager.GetCeasefireStartedTime() + cmpCeasefireManager.GetCeasefireTime() - ret.timeElapsed : 0; } - // Add cinema path info + // Add cinema path info. let cmpCinemaManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CinemaManager); if (cmpCinemaManager) ret.cinemaPlaying = cmpCinemaManager.IsPlaying(); - // Add the game type and allied victory + // Add the game type and allied victory. let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); ret.victoryConditions = cmpEndGameManager.GetVictoryConditions(); ret.alliedVictory = cmpEndGameManager.GetAlliedVictory(); - // Add basic statistics to each player + // Add basic statistics to each player. for (let i = 0; i < numPlayers; ++i) { let cmpPlayerStatisticsTracker = QueryPlayerIDInterface(i, IID_StatisticsTracker); @@ -176,10 +174,10 @@ */ GuiInterface.prototype.GetExtendedSimulationState = function() { - // Get basic simulation info + // Get basic simulation info. let ret = this.GetSimulationState(); - // Add statistics to each player + // Add statistics to each player. let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); for (let i = 0; i < numPlayers; ++i) { @@ -214,13 +212,13 @@ }; /** - * Get common entity info, often used in the gui + * Get common entity info, often used in the gui. */ GuiInterface.prototype.GetEntityState = function(player, ent) { let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - // All units must have a template; if not then it's a nonexistent entity id + // All units must have a template; if not then it's a nonexistent entity id. let template = cmpTemplateManager.GetCurrentTemplateName(ent); if (!template) return null; @@ -406,7 +404,7 @@ if (type != "Ranged") { - // not a ranged attack, set some defaults + // Not a ranged attack, set some defaults. ret.attack[type].elevationBonus = 0; ret.attack[type].elevationAdaptedRange = ret.attack.maxRange; continue; @@ -414,21 +412,15 @@ ret.attack[type].elevationBonus = range.elevationBonus; + // For units, take the range in front of it, no spread. So angle = 0. if (cmpUnitAI && cmpPosition && cmpPosition.IsInWorld()) - { - // For units, take the range in front of it, no spread. So angle = 0 ret.attack[type].elevationAdaptedRange = cmpRangeManager.GetElevationAdaptedRange(cmpPosition.GetPosition(), cmpPosition.GetRotation(), range.max, range.elevationBonus, 0); - } + // For buildings, take the average elevation around it. So angle = 2*pi. else if(cmpPosition && cmpPosition.IsInWorld()) - { - // For buildings, take the average elevation around it. So angle = 2*pi ret.attack[type].elevationAdaptedRange = cmpRangeManager.GetElevationAdaptedRange(cmpPosition.GetPosition(), cmpPosition.GetRotation(), range.max, range.elevationBonus, 2*Math.PI); - } + // Not in world, set a default? else - { - // not in world, set a default? ret.attack[type].elevationAdaptedRange = ret.attack.maxRange; - } } } @@ -570,7 +562,7 @@ return cmpTechnologyManager.IsTechnologyResearched(data.tech); }; -// Checks whether the requirements for this technology have been met +// Checks whether the requirements for this technology have been met. GuiInterface.prototype.CheckTechnologyRequirements = function(player, data) { let cmpTechnologyManager = QueryPlayerIDInterface(data.player || player, IID_TechnologyManager); @@ -662,7 +654,7 @@ notification.endTime = duration + cmpTimer.GetTime(); notification.id = ++this.timeNotificationID; - // Let all players and observers receive the notification by default + // Let all players and observers receive the notification by default. if (!notification.players) { notification.players = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetAllPlayers(); @@ -685,7 +677,7 @@ GuiInterface.prototype.GetTimeNotifications = function(player) { let time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); - // filter on players and time, since the delete timer might be executed with a delay + // Filter on players and time, since the delete timer might be executed with a delay. return this.timeNotifications.filter(n => n.players.indexOf(player) != -1 && n.endTime > time); }; @@ -796,7 +788,7 @@ updateEntityColor(data.showAllStatusBars && (i == player || player == -1) ? [IID_Minimap, IID_RangeOverlayRenderer, IID_RallyPointRenderer, IID_StatusBars] : [IID_Minimap, IID_RangeOverlayRenderer, IID_RallyPointRenderer], - cmpRangeManager.GetEntitiesByPlayer(i)); + cmpRangeManager.GetEntitiesByPlayer(i)); } updateEntityColor([IID_Selectable, IID_StatusBars], data.selected); Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager).UpdateColors(); @@ -804,7 +796,7 @@ GuiInterface.prototype.SetSelectionHighlight = function(player, cmd) { - let playerColors = {}; // cache of owner -> color map + let playerColors = {}; // Cache of owner -> color map. for (let ent of cmd.entities) { @@ -812,7 +804,7 @@ if (!cmpSelectable) continue; - // Find the entity's owner's color: + // Find the entity's owner's color. let owner = INVALID_PLAYER; let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); if (cmpOwnership) @@ -916,7 +908,7 @@ { let cmpPlayer = QueryPlayerIDInterface(player); - // If there are some rally points already displayed, first hide them + // If there are some rally points already displayed, first hide them. for (let ent of this.entsRallyPointsDisplayed) { let cmpRallyPointRenderer = Engine.QueryInterface(ent, IID_RallyPointRenderer); @@ -926,27 +918,27 @@ this.entsRallyPointsDisplayed = []; - // Show the rally points for the passed entities + // Show the rally points for the passed entities. for (let ent of cmd.entities) { let cmpRallyPointRenderer = Engine.QueryInterface(ent, IID_RallyPointRenderer); if (!cmpRallyPointRenderer) continue; - // entity must have a rally point component to display a rally point marker - // (regardless of whether cmd specifies a custom location) + // Entity must have a rally point component to display a rally point marker + // (regardless of whether cmd specifies a custom location). let cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); if (!cmpRallyPoint) continue; - // Verify the owner + // Verify the owner. let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); if (!(cmpPlayer && cmpPlayer.CanControlAllUnits())) if (!cmpOwnership || cmpOwnership.GetOwner() != player) continue; // If the command was passed an explicit position, use that and - // override the real rally point position; otherwise use the real position + // override the real rally point position; otherwise use the real position. let pos; if (cmd.x && cmd.z) pos = cmd; @@ -955,21 +947,21 @@ if (pos) { - // Only update the position if we changed it (cmd.queued is set) + // Only update the position if we changed it (cmd.queued is set). if ("queued" in cmd) if (cmd.queued == true) - cmpRallyPointRenderer.AddPosition({ 'x': pos.x, 'y': pos.z }); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z + cmpRallyPointRenderer.AddPosition({ 'x': pos.x, 'y': pos.z }); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z. else - cmpRallyPointRenderer.SetPosition({ 'x': pos.x, 'y': pos.z }); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z + cmpRallyPointRenderer.SetPosition({ 'x': pos.x, 'y': pos.z }); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z. - // rebuild the renderer when not set (when reading saved game or in case of building update) + // Rebuild the renderer when not set (when reading saved game or in case of building update). else if (!cmpRallyPointRenderer.IsSet()) for (let posi of cmpRallyPoint.GetPositions()) cmpRallyPointRenderer.AddPosition({ 'x': posi.x, 'y': posi.z }); cmpRallyPointRenderer.SetDisplayed(true); - // remember which entities have their rally points displayed so we can hide them again + // Remember which entities have their rally points displayed so we can hide them again. this.entsRallyPointsDisplayed.push(ent); } } @@ -1011,14 +1003,14 @@ "translateParameters": [], }; - // See if we're changing template + // See if we're changing template. if (!this.placementEntity || this.placementEntity[0] != cmd.template) { - // Destroy the old preview if there was one + // Destroy the old preview if there was one. if (this.placementEntity) Engine.DestroyEntity(this.placementEntity[1]); - // Load the new template + // Load the new template. if (cmd.template == "") this.placementEntity = undefined; else @@ -1029,7 +1021,7 @@ { let ent = this.placementEntity[1]; - // Move the preview into the right location + // Move the preview into the right location. let pos = Engine.QueryInterface(ent, IID_Position); if (pos) { @@ -1040,7 +1032,7 @@ let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); cmpOwnership.SetOwner(player); - // Check whether building placement is valid + // Check whether building placement is valid. let cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); if (!cmpBuildRestrictions) error("cmpBuildRestrictions not defined"); @@ -1051,7 +1043,7 @@ if (cmpRangeOverlayManager) cmpRangeOverlayManager.SetEnabled(true, this.enabledVisualRangeOverlayTypes); - // Set it to a red shade if this is an invalid location + // Set it to a red shade if this is an invalid location. let cmpVisual = Engine.QueryInterface(ent, IID_Visual); if (cmpVisual) { @@ -1136,26 +1128,26 @@ let start = { "pos": cmd.start, "angle": 0, - "snapped": false, // did the start position snap to anything? - "snappedEnt": INVALID_ENTITY, // if we snapped, was it to an entity? if yes, holds that entity's ID + "snapped": false, // Did the start position snap to anything? + "snappedEnt": INVALID_ENTITY, // If we snapped, was it to an entity? If yes, holds that entity's ID }; let end = { "pos": cmd.end, "angle": 0, - "snapped": false, // did the start position snap to anything? - "snappedEnt": INVALID_ENTITY, // if we snapped, was it to an entity? if yes, holds that entity's ID + "snapped": false, // Did the start position snap to anything? + "snappedEnt": INVALID_ENTITY, // If we snapped, was it to an entity? If yes, holds that entity's ID. }; // -------------------------------------------------------------------------------- - // do some entity cache management and check for snapping + // Do some entity cache management and check for snapping. if (!this.placementWallEntities) this.placementWallEntities = {}; if (!wallSet) { - // we're clearing the preview, clear the entity cache and bail + // We're clearing the preview, clear the entity cache and bail. for (let tpl in this.placementWallEntities) { for (let ent of this.placementWallEntities[tpl].entities) @@ -1163,13 +1155,13 @@ this.placementWallEntities[tpl].numUsed = 0; this.placementWallEntities[tpl].entities = []; - // keep template data around + // Keep template data around. } return false; } - // Move all existing cached entities outside of the world and reset their use count + // Move all existing cached entities outside of the world and reset their use count. for (let tpl in this.placementWallEntities) { for (let ent of this.placementWallEntities[tpl].entities) @@ -1182,7 +1174,7 @@ this.placementWallEntities[tpl].numUsed = 0; } - // Create cache entries for templates we haven't seen before + // Create cache entries for templates we haven't seen before. for (let type in wallSet.templates) { if (type == "curves") @@ -1197,7 +1189,7 @@ "templateData": this.GetTemplateData(player, tpl), }; - // ensure that the loaded template data contains a wallPiece component + // Ensure that the loaded template data contains a wallPiece component. if (!this.placementWallEntities[tpl].templateData.wallPiece) { error("[SetWallPlacementPreview] No WallPiece component found for wall set template '" + tpl + "'"); @@ -1206,7 +1198,7 @@ } } - // prevent division by zero errors further on if the start and end positions are the same + // Prevent division by zero errors further on if the start and end positions are the same. if (end.pos && (start.pos.x === end.pos.x && start.pos.z === end.pos.z)) end.pos = undefined; @@ -1215,7 +1207,7 @@ // data to determine whether it snapped to an entity (if any), and to which one (see GetFoundationSnapData). if (cmd.snapEntities) { - let snapRadius = this.placementWallEntities[wallSet.templates.tower].templateData.wallPiece.length * 0.5; // determined through trial and error + let snapRadius = this.placementWallEntities[wallSet.templates.tower].templateData.wallPiece.length * 0.5; // Determined through trial and error. let startSnapData = this.GetFoundationSnapData(player, { "x": start.pos.x, "z": start.pos.z, @@ -1258,11 +1250,11 @@ } } - // clear the single-building preview entity (we'll be rolling our own) + // Clear the single-building preview entity (we'll be rolling our own). this.SetBuildingPlacementPreview(player, { "template": "" }); // -------------------------------------------------------------------------------- - // calculate wall placement and position preview entities + // Calculate wall placement and position preview entities. let result = { "pieces": [], @@ -1299,7 +1291,7 @@ if (previewEntities.length > 0 && startEntObstruction) previewEntities[0].controlGroups = [startEntObstruction.GetControlGroup()]; - // if we're snapping to merely a foundation, add an extra preview tower and also set it to the same control group + // If we're snapping to merely a foundation, add an extra preview tower and also set it to the same control group. let startEntState = this.GetEntityState(player, start.snappedEnt); if (startEntState.foundation) { @@ -1310,37 +1302,34 @@ "pos": start.pos, "angle": cmpPosition.GetRotation().y, "controlGroups": [startEntObstruction ? startEntObstruction.GetControlGroup() : undefined], - "excludeFromResult": true, // preview only, must not appear in the result + "excludeFromResult": true, // Preview only, must not appear in the result. }); } } - else - { - // Didn't snap to an existing entity, add the starting tower manually. To prevent odd-looking rotation jumps - // when shift-clicking to build a wall, reuse the placement angle that was last seen on a validly positioned - // wall piece. - - // To illustrate the last point, consider what happens if we used some constant instead, say, 0. Issuing the - // build command for a wall is asynchronous, so when the preview updates after shift-clicking, the wall piece - // foundations are not registered yet in the simulation. This means they cannot possibly be picked in the list - // of candidate entities for snapping. In the next preview update, we therefore hit this case, and would rotate - // the preview to 0 radians. Then, after one or two simulation updates or so, the foundations register and - // onSimulationUpdate in session.js updates the preview again. It first grabs a new list of snapping candidates, - // which this time does include the new foundations; so we snap to the entity, and rotate the preview back to - // the foundation's angle. + // Didn't snap to an existing entity, add the starting tower manually. To prevent odd-looking rotation jumps + // when shift-clicking to build a wall, reuse the placement angle that was last seen on a validly positioned + // wall piece. + + // To illustrate the last point, consider what happens if we used some constant instead, say, 0. Issuing the + // build command for a wall is asynchronous, so when the preview updates after shift-clicking, the wall piece + // foundations are not registered yet in the simulation. This means they cannot possibly be picked in the list + // of candidate entities for snapping. In the next preview update, we therefore hit this case, and would rotate + // the preview to 0 radians. Then, after one or two simulation updates or so, the foundations register and + // onSimulationUpdate in session.js updates the preview again. It first grabs a new list of snapping candidates, + // which this time does include the new foundations; so we snap to the entity, and rotate the preview back to + // the foundation's angle. - // The result is a noticeable rotation to 0 and back, which is undesirable. So, for a split second there until - // the simulation updates, we fake it by reusing the last angle and hope the player doesn't notice. + // The result is a noticeable rotation to 0 and back, which is undesirable. So, for a split second there until + // the simulation updates, we fake it by reusing the last angle and hope the player doesn't notice. + else previewEntities.unshift({ "template": wallSet.templates.tower, "pos": start.pos, "angle": previewEntities.length > 0 ? previewEntities[0].angle : this.placementWallLastAngle }); - } + // Analogous to the starting side case above. if (end.pos) - { - // Analogous to the starting side case above if (end.snappedEnt && end.snappedEnt != INVALID_ENTITY) { let endEntObstruction = Engine.QueryInterface(end.snappedEnt, IID_Obstruction); @@ -1356,7 +1345,7 @@ previewEntities[previewEntities.length-1].controlGroups.push(endEntObstruction.GetControlGroup()); } - // if we're snapping to a foundation, add an extra preview tower and also set it to the same control group + // If we're snapping to a foundation, add an extra preview tower and also set it to the same control group. let endEntState = this.GetEntityState(player, end.snappedEnt); if (endEntState.foundation) { @@ -1370,14 +1359,13 @@ "excludeFromResult": true }); } + else + previewEntities.push({ + "template": wallSet.templates.tower, + "pos": end.pos, + "angle": previewEntities.length > 0 ? previewEntities[previewEntities.length-1].angle : this.placementWallLastAngle + }); } - else - previewEntities.push({ - "template": wallSet.templates.tower, - "pos": end.pos, - "angle": previewEntities.length > 0 ? previewEntities[previewEntities.length-1].angle : this.placementWallLastAngle - }); - } let cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); if (!cmpTerrain) @@ -1398,7 +1386,7 @@ // but cannot validly be, constructed). See method-level documentation for more details. let allPiecesValid = true; - let numRequiredPieces = 0; // number of entities that are required to build the entire wall, regardless of validity + let numRequiredPieces = 0; // Number of entities that are required to build the entire wall, regardless of validity. for (let i = 0; i < previewEntities.length; ++i) { @@ -1411,12 +1399,12 @@ if (entPool.numUsed >= entPool.entities.length) { - // allocate new entity + // Allocate new entity. ent = Engine.AddLocalEntity("preview|" + tpl); entPool.entities.push(ent); } else - // reuse an existing one + // Reuse an existing one. ent = entPool.entities[entPool.numUsed]; if (!ent) @@ -1425,15 +1413,15 @@ continue; } - // move piece to right location - // TODO: consider reusing SetBuildingPlacementReview for this, enhanced to be able to deal with multiple entities + // Move piece to right location. + // TODO: Consider reusing SetBuildingPlacementReview for this, enhanced to be able to deal with multiple entities. let cmpPosition = Engine.QueryInterface(ent, IID_Position); if (cmpPosition) { cmpPosition.JumpTo(entInfo.pos.x, entInfo.pos.z); cmpPosition.SetYRotation(entInfo.angle); - // if this piece is a tower, then it should have a Y position that is at least as high as its surrounding pieces + // If this piece is a tower, then it should have a Y position that is at least as high as its surrounding pieces. if (tpl === wallSet.templates.tower) { let terrainGroundPrev = null; @@ -1489,14 +1477,14 @@ cmpObstruction.SetControlGroup(primaryControlGroup); cmpObstruction.SetControlGroup2(secondaryControlGroup); - // check whether this wall piece can be validly positioned here + // Check whether this wall piece can be validly positioned here. let validPlacement = false; let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); cmpOwnership.SetOwner(player); - // Check whether it's in a visible or fogged region - // TODO: should definitely reuse SetBuildingPlacementPreview, this is just straight up copy/pasta + // Check whether it's in a visible or fogged region. + // TODO: Should definitely reuse SetBuildingPlacementPreview, this is just straight up copy/pasta. let visible = cmpRangeManager.GetLosVisibility(ent, player) != "hidden"; if (visible) { @@ -1507,7 +1495,7 @@ continue; } - // TODO: Handle results of CheckPlacement + // TODO: Handle results of CheckPlacement. validPlacement = cmpBuildRestrictions && cmpBuildRestrictions.CheckPlacement().success; // If a wall piece has two control groups, it's likely a segment that spans @@ -1540,9 +1528,9 @@ }); this.placementWallLastAngle = entInfo.angle; - // grab the cost of this wall piece and add it up (note; preview entities don't have their Cost components + // Grab the cost of this wall piece and add it up (note; preview entities don't have their Cost components // copied over, so we need to fetch it from the template instead). - // TODO: we should really use a Cost object or at least some utility functions for this, this is mindless + // TODO: We should really use a Cost object or at least some utility functions for this, this is mindless // boilerplate that's probably duplicated in tons of places. for (let res of Resources.GetCodes().concat(["population", "populationBonus", "time"])) result.cost[res] += tplData.cost[res]; @@ -1555,12 +1543,10 @@ let cmpVisual = Engine.QueryInterface(ent, IID_Visual); if (cmpVisual) - { if (!allPiecesValid || !canAfford) cmpVisual.SetShadingColor(1.4, 0.4, 0.4, 1); else cmpVisual.SetShadingColor(1, 1, 1, 1); - } ++entPool.numUsed; } @@ -1607,8 +1593,8 @@ if (data.snapEntities && data.snapRadius && data.snapRadius > 0) { - // see if {data.x, data.z} is inside the snap radius of any of the snap entities; and if so, to which it is closest - // (TODO: break unlikely ties by choosing the lowest entity ID) + // See if {data.x, data.z} is inside the snap radius of any of the snap entities; and if so, to which it is closest. + // (TODO: Break unlikely ties by choosing the lowest entity ID.) let minDist2 = -1; let minDistEntitySnapData = null; @@ -1629,10 +1615,10 @@ { minDist2 = dist2; minDistEntitySnapData = { - "x": pos.x, - "z": pos.z, - "angle": cmpPosition.GetRotation().y, - "ent": ent + "x": pos.x, + "z": pos.z, + "angle": cmpPosition.GetRotation().y, + "ent": ent }; } } @@ -1688,7 +1674,7 @@ // If the entity is in the 'current' (first, 0) bucket on a resumed search, it must be after the "previous" unit, if any. // By adding to the 'end', there is no pause if the series of units loops. - var bucket = filtered.bucket; + let bucket = filtered.bucket; if(bucket == 0 && data.prevUnit && entity <= data.prevUnit) bucket = data.idleClasses.length; @@ -1777,28 +1763,21 @@ result.gain = cmpEntityTrader.GetGoods().amount; } else if (data.target === secondMarket) - { result = { "type": "is second", "gain": cmpEntityTrader.GetGoods().amount, }; - } else if (!firstMarket) - { result = { "type": "set first" }; - } else if (!secondMarket) - { result = { "type": "set second", "gain": cmpEntityTrader.CalculateGain(firstMarket, data.target), }; - } + // Else both markets are not null and target is different from them else - { - // Else both markets are not null and target is different from them result = { "type": "set first" }; - } + return result; }; Index: binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js +++ binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js @@ -47,7 +47,7 @@ "GetResource": resource => ({ "aiAnalysisInfluenceGroup": resource == "food" ? "ignore" : - resource == "wood" ? "abundant" : "sparse" + resource == "wood" ? "abundant" : "sparse" }) }; @@ -55,71 +55,71 @@ AddMock(SYSTEM_ENTITY, IID_Barter, { - GetPrices: function() { + "GetPrices": function() { return { "buy": { "food": 150 }, "sell": { "food": 25 } }; }, - PlayerHasMarket: function () { return false; } + "PlayerHasMarket": function() { return false; } }); AddMock(SYSTEM_ENTITY, IID_EndGameManager, { - GetVictoryConditions: () => ["conquest", "wonder"], - GetAlliedVictory: function() { return false; } + "GetVictoryConditions": () => ["conquest", "wonder"], + "GetAlliedVictory": function() { return false; } }); AddMock(SYSTEM_ENTITY, IID_PlayerManager, { - GetNumPlayers: function() { return 2; }, - GetPlayerByID: function(id) { TS_ASSERT(id === 0 || id === 1); return 100+id; } + "GetNumPlayers": function() { return 2; }, + "GetPlayerByID": function(id) { TS_ASSERT(id === 0 || id === 1); return 100+id; } }); AddMock(SYSTEM_ENTITY, IID_RangeManager, { - GetLosVisibility: function(ent, player) { return "visible"; }, - GetLosCircular: function() { return false; } + "GetLosVisibility": function(ent, player) { return "visible"; }, + "GetLosCircular": function() { return false; } }); AddMock(SYSTEM_ENTITY, IID_TemplateManager, { - GetCurrentTemplateName: function(ent) { return "example"; }, - GetTemplate: function(name) { return ""; } + "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; } + "GetTime": function() { return 0; }, + "SetTimeout": function(ent, iid, funcname, time, data) { return 0; } }); AddMock(100, IID_Player, { - GetName: function() { return "Player 1"; }, - GetCiv: function() { return "gaia"; }, - GetColor: function() { return { r: 1, g: 1, b: 1, a: 1}; }, - CanControlAllUnits: function() { return false; }, - GetPopulationCount: function() { return 10; }, - GetPopulationLimit: function() { return 20; }, - GetMaxPopulation: function() { return 200; }, - GetResourceCounts: function() { return { food: 100 }; }, - GetPanelEntities: function() { return []; }, - IsTrainingBlocked: function() { return false; }, - GetState: function() { return "active"; }, - GetTeam: function() { return -1; }, - GetLockTeams: function() { return false; }, - GetCheatsEnabled: function() { return false; }, - GetDiplomacy: function() { return [-1, 1]; }, - IsAlly: function() { return false; }, - IsMutualAlly: function() { return false; }, - IsNeutral: function() { return false; }, - IsEnemy: function() { return true; }, - GetDisabledTemplates: function() { return {}; }, - GetDisabledTechnologies: function() { return {}; }, - GetSpyCostMultiplier: function() { return 1; }, - HasSharedDropsites: function() { return false; }, - HasSharedLos: function() { return false; } + "GetName": function() { return "Player 1"; }, + "GetCiv": function() { return "gaia"; }, + "GetColor": function() { return { "r": 1, "g": 1, "b": 1, "a": 1 }; }, + "CanControlAllUnits": function() { return false; }, + "GetPopulationCount": function() { return 10; }, + "GetPopulationLimit": function() { return 20; }, + "GetMaxPopulation": function() { return 200; }, + "GetResourceCounts": function() { return { "food": 100 }; }, + "GetPanelEntities": function() { return []; }, + "IsTrainingBlocked": function() { return false; }, + "GetState": function() { return "active"; }, + "GetTeam": function() { return -1; }, + "GetLockTeams": function() { return false; }, + "GetCheatsEnabled": function() { return false; }, + "GetDiplomacy": function() { return [-1, 1]; }, + "IsAlly": function() { return false; }, + "IsMutualAlly": function() { return false; }, + "IsNeutral": function() { return false; }, + "IsEnemy": function() { return true; }, + "GetDisabledTemplates": function() { return {}; }, + "GetDisabledTechnologies": function() { return {}; }, + "GetSpyCostMultiplier": function() { return 1; }, + "HasSharedDropsites": function() { return false; }, + "HasSharedLos": function() { return false; } }); AddMock(100, IID_EntityLimits, { - GetLimits: function() { return {"Foo": 10}; }, - GetCounts: function() { return {"Foo": 5}; }, - GetLimitChangers: function() {return {"Foo": {}}; } + "GetLimits": function() { return { "Foo": 10 }; }, + "GetCounts": function() { return { "Foo": 5 }; }, + "GetLimitChangers": function() {return { "Foo": {} }; } }); AddMock(100, IID_TechnologyManager, { @@ -132,7 +132,7 @@ }); AddMock(100, IID_StatisticsTracker, { - GetBasicStatistics: function() { + "GetBasicStatistics": function() { return { "resourcesGathered": { "food": 100, @@ -144,7 +144,7 @@ "percentMapExplored": 10 }; }, - GetSequences: function() { + "GetSequences": function() { return { "unitsTrained": [0, 10], "unitsLost": [0, 42], @@ -169,42 +169,42 @@ "teamPeakPercentOfMapControlled": [0, 10] }; }, - IncreaseTrainedUnitsCounter: function() { return 1; }, - IncreaseConstructedBuildingsCounter: function() { return 1; }, - IncreaseBuiltCivCentresCounter: function() { return 1; } + "IncreaseTrainedUnitsCounter": function() { return 1; }, + "IncreaseConstructedBuildingsCounter": function() { return 1; }, + "IncreaseBuiltCivCentresCounter": function() { return 1; } }); AddMock(101, IID_Player, { - GetName: function() { return "Player 2"; }, - GetCiv: function() { return "mace"; }, - GetColor: function() { return { r: 1, g: 0, b: 0, a: 1}; }, - CanControlAllUnits: function() { return true; }, - GetPopulationCount: function() { return 40; }, - GetPopulationLimit: function() { return 30; }, - GetMaxPopulation: function() { return 300; }, - GetResourceCounts: function() { return { food: 200 }; }, - GetPanelEntities: function() { return []; }, - IsTrainingBlocked: function() { return false; }, - GetState: function() { return "active"; }, - GetTeam: function() { return -1; }, - GetLockTeams: function() {return false; }, - GetCheatsEnabled: function() { return false; }, - GetDiplomacy: function() { return [-1, 1]; }, - IsAlly: function() { return true; }, - IsMutualAlly: function() {return false; }, - IsNeutral: function() { return false; }, - IsEnemy: function() { return false; }, - GetDisabledTemplates: function() { return {}; }, - GetDisabledTechnologies: function() { return {}; }, - GetSpyCostMultiplier: function() { return 1; }, - HasSharedDropsites: function() { return false; }, - HasSharedLos: function() { return false; } + "GetName": function() { return "Player 2"; }, + "GetCiv": function() { return "mace"; }, + "GetColor": function() { return { "r": 1, "g": 0, "b": 0, "a": 1 }; }, + "CanControlAllUnits": function() { return true; }, + "GetPopulationCount": function() { return 40; }, + "GetPopulationLimit": function() { return 30; }, + "GetMaxPopulation": function() { return 300; }, + "GetResourceCounts": function() { return { "food": 200 }; }, + "GetPanelEntities": function() { return []; }, + "IsTrainingBlocked": function() { return false; }, + "GetState": function() { return "active"; }, + "GetTeam": function() { return -1; }, + "GetLockTeams": function() {return false; }, + "GetCheatsEnabled": function() { return false; }, + "GetDiplomacy": function() { return [-1, 1]; }, + "IsAlly": function() { return true; }, + "IsMutualAlly": function() {return false; }, + "IsNeutral": function() { return false; }, + "IsEnemy": function() { return false; }, + "GetDisabledTemplates": function() { return {}; }, + "GetDisabledTechnologies": function() { return {}; }, + "GetSpyCostMultiplier": function() { return 1; }, + "HasSharedDropsites": function() { return false; }, + "HasSharedLos": function() { return false; } }); AddMock(101, IID_EntityLimits, { - GetLimits: function() { return {"Bar": 20}; }, - GetCounts: function() { return {"Bar": 0}; }, - GetLimitChangers: function() {return {"Bar": {}}; } + "GetLimits": function() { return { "Bar": 20 }; }, + "GetCounts": function() { return { "Bar": 0 }; }, + "GetLimitChangers": function() {return { "Bar": {} }; } }); AddMock(101, IID_TechnologyManager, { @@ -217,7 +217,7 @@ }); AddMock(101, IID_StatisticsTracker, { - GetBasicStatistics: function() { + "GetBasicStatistics": function() { return { "resourcesGathered": { "food": 100, @@ -229,7 +229,7 @@ "percentMapExplored": 10 }; }, - GetSequences: function() { + "GetSequences": function() { return { "unitsTrained": [0, 10], "unitsLost": [0, 9], @@ -254,119 +254,119 @@ "teamPeakPercentOfMapControlled": [0, 10] }; }, - IncreaseTrainedUnitsCounter: function() { return 1; }, - IncreaseConstructedBuildingsCounter: function() { return 1; }, - IncreaseBuiltCivCentresCounter: function() { return 1; } + "IncreaseTrainedUnitsCounter": function() { return 1; }, + "IncreaseConstructedBuildingsCounter": function() { return 1; }, + "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: [ + "players": [ { - name: "Player 1", - civ: "gaia", - color: { r:1, g:1, b:1, a:1 }, - controlsAll: false, - popCount: 10, - popLimit: 20, - popMax: 200, - panelEntities: [], - resourceCounts: { food: 100 }, - trainingBlocked: false, - state: "active", - team: -1, - teamsLocked: false, - cheatsEnabled: false, - disabledTemplates: {}, - disabledTechnologies: {}, - hasSharedDropsites: false, - hasSharedLos: false, - spyCostMultiplier: 1, - phase: "village", - isAlly: [false, false], - isMutualAlly: [false, false], - isNeutral: [false, false], - isEnemy: [true, true], - entityLimits: {"Foo": 10}, - entityCounts: {"Foo": 5}, - entityLimitChangers: {"Foo": {}}, - researchQueued: new Map(), - researchStarted: new Set(), - researchedTechs: new Set(), - classCounts: {}, - typeCountsByClass: {}, - canBarter: false, - barterPrices: { + "name": "Player 1", + "civ": "gaia", + "color": { "r": 1, "g": 1, "b": 1, "a": 1 }, + "controlsAll": false, + "popCount": 10, + "popLimit": 20, + "popMax": 200, + "panelEntities": [], + "resourceCounts": { "food": 100 }, + "trainingBlocked": false, + "state": "active", + "team": -1, + "teamsLocked": false, + "cheatsEnabled": false, + "disabledTemplates": {}, + "disabledTechnologies": {}, + "hasSharedDropsites": false, + "hasSharedLos": false, + "spyCostMultiplier": 1, + "phase": "village", + "isAlly": [false, false], + "isMutualAlly": [false, false], + "isNeutral": [false, false], + "isEnemy": [true, true], + "entityLimits": { "Foo": 10 }, + "entityCounts": { "Foo": 5 }, + "entityLimitChangers": { "Foo": {} }, + "researchQueued": new Map(), + "researchStarted": new Set(), + "researchedTechs": new Set(), + "classCounts": {}, + "typeCountsByClass": {}, + "canBarter": false, + "barterPrices": { "buy": { "food": 150 }, "sell": { "food": 25 } }, - statistics: { - resourcesGathered: { - food: 100, - wood: 0, - metal: 0, - stone: 0, - vegetarianFood: 0 + "statistics": { + "resourcesGathered": { + "food": 100, + "wood": 0, + "metal": 0, + "stone": 0, + "vegetarianFood": 0 }, - percentMapExplored: 10 + "percentMapExplored": 10 } }, { - name: "Player 2", - civ: "mace", - color: { r:1, g:0, b:0, a:1 }, - controlsAll: true, - popCount: 40, - popLimit: 30, - popMax: 300, - panelEntities: [], - resourceCounts: { food: 200 }, - trainingBlocked: false, - state: "active", - team: -1, - teamsLocked: false, - cheatsEnabled: false, - disabledTemplates: {}, - disabledTechnologies: {}, - hasSharedDropsites: false, - hasSharedLos: false, - spyCostMultiplier: 1, - phase: "village", - isAlly: [true, true], - isMutualAlly: [false, false], - isNeutral: [false, false], - isEnemy: [false, false], - entityLimits: {"Bar": 20}, - entityCounts: {"Bar": 0}, - entityLimitChangers: {"Bar": {}}, - researchQueued: new Map(), - researchStarted: new Set(), - researchedTechs: new Set(), - classCounts: {}, - typeCountsByClass: {}, - canBarter: false, - barterPrices: { + "name": "Player 2", + "civ": "mace", + "color": { "r": 1, "g": 0, "b": 0, "a": 1 }, + "controlsAll": true, + "popCount": 40, + "popLimit": 30, + "popMax": 300, + "panelEntities": [], + "resourceCounts": { "food": 200 }, + "trainingBlocked": false, + "state": "active", + "team": -1, + "teamsLocked": false, + "cheatsEnabled": false, + "disabledTemplates": {}, + "disabledTechnologies": {}, + "hasSharedDropsites": false, + "hasSharedLos": false, + "spyCostMultiplier": 1, + "phase": "village", + "isAlly": [true, true], + "isMutualAlly": [false, false], + "isNeutral": [false, false], + "isEnemy": [false, false], + "entityLimits": { "Bar": 20 }, + "entityCounts": { "Bar": 0 }, + "entityLimitChangers": { "Bar": {} }, + "researchQueued": new Map(), + "researchStarted": new Set(), + "researchedTechs": new Set(), + "classCounts": {}, + "typeCountsByClass": {}, + "canBarter": false, + "barterPrices": { "buy": { "food": 150 }, "sell": { "food": 25 } }, - statistics: { - resourcesGathered: { - food: 100, - wood: 0, - metal: 0, - stone: 0, - vegetarianFood: 0 + "statistics": { + "resourcesGathered": { + "food": 100, + "wood": 0, + "metal": 0, + "stone": 0, + "vegetarianFood": 0 }, - percentMapExplored: 10 + "percentMapExplored": 10 } } ], - circularMap: false, - timeElapsed: 0, + "circularMap": false, + "timeElapsed": 0, "victoryConditions": ["conquest", "wonder"], - alliedVictory: false + "alliedVictory": false }); TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { @@ -374,7 +374,7 @@ { "name": "Player 1", "civ": "gaia", - "color": { "r":1, "g":1, "b":1, "a":1 }, + "color": { "r": 1, "g": 1, "b": 1, "a": 1 }, "controlsAll": false, "popCount": 10, "popLimit": 20, @@ -396,9 +396,9 @@ "isMutualAlly": [false, false], "isNeutral": [false, false], "isEnemy": [true, true], - "entityLimits": {"Foo": 10}, - "entityCounts": {"Foo": 5}, - "entityLimitChangers": {"Foo": {}}, + "entityLimits": { "Foo": 10 }, + "entityCounts": { "Foo": 5 }, + "entityLimitChangers": { "Foo": {} }, "researchQueued": new Map(), "researchStarted": new Set(), "researchedTechs": new Set(), @@ -446,7 +446,7 @@ { "name": "Player 2", "civ": "mace", - "color": { "r":1, "g":0, "b":0, "a":1 }, + "color": { "r": 1, "g": 0, "b": 0, "a": 1 }, "controlsAll": true, "popCount": 40, "popLimit": 30, @@ -468,9 +468,9 @@ "isMutualAlly": [false, false], "isNeutral": [false, false], "isEnemy": [false, false], - "entityLimits": {"Bar": 20}, - "entityCounts": {"Bar": 0}, - "entityLimitChangers": {"Bar": {}}, + "entityLimits": { "Bar": 20 }, + "entityCounts": { "Bar": 0 }, + "entityLimitChangers": { "Bar": {} }, "researchQueued": new Map(), "researchStarted": new Set(), "researchedTechs": new Set(), @@ -524,33 +524,33 @@ AddMock(10, IID_Builder, { - GetEntitiesList: function() { + "GetEntitiesList": function() { return ["test1", "test2"]; }, }); AddMock(10, IID_Health, { - GetHitpoints: function() { return 50; }, - GetMaxHitpoints: function() { return 60; }, - IsRepairable: function() { return false; }, - IsUnhealable: function() { return false; } + "GetHitpoints": function() { return 50; }, + "GetMaxHitpoints": function() { return 60; }, + "IsRepairable": function() { return false; }, + "IsUnhealable": function() { return false; } }); AddMock(10, IID_Identity, { - GetClassesList: function() { return ["class1", "class2"]; }, - GetVisibleClassesList: function() { return ["class3", "class4"]; }, - GetRank: function() { return "foo"; }, - GetSelectionGroupName: function() { return "Selection Group Name"; }, - HasClass: function() { return true; }, - IsUndeletable: function() { return false; } + "GetClassesList": function() { return ["class1", "class2"]; }, + "GetVisibleClassesList": function() { return ["class3", "class4"]; }, + "GetRank": function() { return "foo"; }, + "GetSelectionGroupName": function() { return "Selection Group Name"; }, + "HasClass": function() { return true; }, + "IsUndeletable": function() { return false; } }); AddMock(10, IID_Position, { - GetTurretParent: function() {return INVALID_ENTITY;}, - GetPosition: function() { - return {x:1, y:2, z:3}; + "GetTurretParent": function() {return INVALID_ENTITY;}, + "GetPosition": function() { + return { "x": 1, "y": 2, "z": 3 }; }, - IsInWorld: function() { + "IsInWorld": function() { return true; } }); @@ -574,7 +574,7 @@ "selectionGroupName": "Selection Group Name", "canDelete": true }, - "position": {x:1, y:2, z:3}, + "position": { "x": 1, "y": 2, "z": 3 }, "hitpoints": 50, "maxHitpoints": 60, "needsRepair": false, @@ -582,7 +582,7 @@ "builder": true, "canGarrison": false, "visibility": "visible", - "isBarterMarket":true, + "isBarterMarket": true, "resourceTrickle": { "interval": 1250, "rates": { "food": 2, "wood": 3, "stone": 5, "metal": 9 }