Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: binaries/data/mods/public/gui/session/input.js
- ===================================================================
- --- binaries/data/mods/public/gui/session/input.js (revision 18212)
- +++ binaries/data/mods/public/gui/session/input.js (working copy)
- @@ -38,6 +38,9 @@
- var mouseY = 0;
- var mouseIsOverObject = false;
- + // used for remembering mouse coordinates at start of drag operations
- +var dragStart;
- +
- // Number of pixels the mouse can move before the action is considered a drag
- var maxDragDelta = 4;
- @@ -53,36 +56,48 @@
- var doublePressTimer = 0;
- var prevHotkey = 0;
- +// Camera jumping: when the user presses a hotkey the current camera location is marked.
- +// When they press another hotkey the camera jumps back to that position. If the camera is already roughly at that location,
- +// jump back to where it was previously.
- +var jumpCameraPositions = [];
- +var jumpCameraLast;
- +var jumpCameraDistanceThreshold = Engine.ConfigDB_GetValue("user", "gui.session.camerajump.threshold");
- +
- +// Batch training:
- +// When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING
- +// When the user releases shift, or clicks on a different training button, we create the batched units
- +var batchTrainingEntities;
- +var batchTrainingType;
- +var batchTrainingCount;
- +var batchTrainingEntityAllowedCount;
- +const batchIncrementSize = 5;
- +
- +var lastIdleUnit = 0;
- +var currIdleClass = 0;
- +var lastIdleType = undefined;
- +
- function updateCursorAndTooltip()
- {
- - var cursorSet = false;
- - var tooltipSet = false;
- - var informationTooltip = Engine.GetGUIObjectByName("informationTooltip");
- - if (!mouseIsOverObject && (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION))
- +
- + let informationTooltip = Engine.GetGUIObjectByName("informationTooltip");
- +
- + let action = determineAction(mouseX, mouseY);
- + if (action && action.cursor && !mouseIsOverObject &&
- + (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION))
- + Engine.SetCursor(action.cursor);
- + else
- + Engine.SetCursor("arrow-default");
- +
- + if (action && action.tooltip && !mouseIsOverObject &&
- + (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION))
- {
- - let action = determineAction(mouseX, mouseY);
- - if (action)
- - {
- - if (action.cursor)
- - {
- - Engine.SetCursor(action.cursor);
- - cursorSet = true;
- - }
- - if (action.tooltip)
- - {
- - tooltipSet = true;
- - informationTooltip.caption = action.tooltip;
- - informationTooltip.hidden = false;
- - }
- - }
- + informationTooltip.caption = action.tooltip;
- + informationTooltip.hidden = false;
- }
- -
- - if (!cursorSet)
- - Engine.SetCursor("arrow-default");
- - if (!tooltipSet)
- + else
- informationTooltip.hidden = true;
- - var placementTooltip = Engine.GetGUIObjectByName("placementTooltip");
- + let placementTooltip = Engine.GetGUIObjectByName("placementTooltip");
- if (placementSupport.tooltipMessage)
- placementTooltip.sprite = placementSupport.tooltipError ? "BackgroundErrorTooltip" : "BackgroundInformationTooltip";
- @@ -100,7 +115,7 @@
- {
- if (placementSupport.template && placementSupport.position)
- {
- - var result = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {
- + let result = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", {
- "template": placementSupport.template,
- "x": placementSupport.position.x,
- "z": placementSupport.position.z,
- @@ -116,13 +131,13 @@
- {
- if (result.message && result.parameters)
- {
- - var message = result.message;
- + let message = result.message;
- if (result.translateMessage)
- if (result.pluralMessage)
- - message = translatePlural(result.message, result.pluralMessage, result.pluralCount);
- + message = translatePlural(message, result.pluralMessage, result.pluralCount);
- else
- message = translate(message);
- - var parameters = result.parameters;
- + let parameters = result.parameters;
- if (result.translateParameters)
- translateObjectKeys(parameters, result.translateParameters);
- placementSupport.tooltipMessage = sprintf(message, parameters);
- @@ -134,14 +149,14 @@
- {
- // building can be placed here, and has an attack
- // show the range advantage in the tooltip
- - var cmd = {
- + let cmd = {
- "x": placementSupport.position.x,
- "z": placementSupport.position.z,
- "range": placementSupport.attack.Ranged.maxRange,
- "elevationBonus": placementSupport.attack.Ranged.elevationBonus,
- };
- - var averageRange = Math.round(Engine.GuiInterfaceCall("GetAverageRangeForBuildings", cmd) - cmd.range);
- - var range = Math.round(cmd.range);
- + let averageRange = Math.round(Engine.GuiInterfaceCall("GetAverageRangeForBuildings", cmd) - cmd.range);
- + let range = Math.round(cmd.range);
- placementSupport.tooltipMessage = sprintf(translatePlural("Basic range: %(range)s meter", "Basic range: %(range)s meters", range), { "range": range }) + "\n" +
- sprintf(translatePlural("Average bonus range: %(range)s meter", "Average bonus range: %(range)s meters", averageRange), { "range": averageRange });
- }
- @@ -156,8 +171,8 @@
- placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities(
- placementSupport.wallSet.templates.tower,
- placementSupport.wallSnapEntitiesIncludeOffscreen,
- - true, // require exact template match
- - true // include foundations
- + true, // require exact template match
- + true // include foundations
- );
- return Engine.GuiInterfaceCall("SetWallPlacementPreview", {
- @@ -174,7 +189,7 @@
- function findGatherType(gatherer, supply)
- {
- - if (!("resourceGatherRates" in gatherer) || !gatherer.resourceGatherRates || !supply)
- + if (!gatherer.resourceGatherRates || !supply)
- return undefined;
- if (gatherer.resourceGatherRates[supply.type.generic+"."+supply.type.specific])
- return supply.type.specific;
- @@ -185,11 +200,11 @@
- function getActionInfo(action, target)
- {
- - var simState = GetSimState();
- - var selection = g_Selection.toList();
- + let simState = GetSimState();
- + let selection = g_Selection.toList();
- // If the selection doesn't exist, no action
- - var entState = GetEntityState(selection[0]);
- + let entState = GetEntityState(selection[0]);
- if (!entState)
- return { "possible": false };
- @@ -197,8 +212,8 @@
- {
- if (action == "set-rallypoint")
- {
- - var cursor = "";
- - var data = { "command": "walk" };
- + let cursor = "";
- + let data = { "command": "walk" };
- if (Engine.HotkeyIsPressed("session.attackmove"))
- {
- data.command = "attack-walk";
- @@ -214,21 +229,21 @@
- // Look at the first targeted entity
- // (TODO: maybe we eventually want to look at more, and be more context-sensitive?
- // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
- - var targetState = GetExtendedEntityState(target);
- + let targetState = GetExtendedEntityState(target);
- // Check if the target entity is a resource, dropsite, foundation, or enemy unit.
- // Check if any entities in the selection can gather the requested resource,
- // can return to the dropsite, can build the foundation, or can attack the enemy
- - for each (var entityID in selection)
- + for (let entityID of selection)
- {
- - var entState = GetExtendedEntityState(entityID);
- + let entState = GetExtendedEntityState(entityID);
- if (!entState)
- continue;
- if (unitActions[action] && unitActions[action].getActionInfo)
- {
- - var r = unitActions[action].getActionInfo(entState, targetState, simState);
- - if (r) // return true if it's possible for one of the entities
- + let r = unitActions[action].getActionInfo(entState, targetState, simState);
- + if (r && r.possible) // return true if it's possible for one of the entities
- return r;
- }
- }
- @@ -240,7 +255,7 @@
- */
- function determineAction(x, y, fromMinimap)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- // No action if there's no selection
- if (!selection.length)
- @@ -250,13 +265,13 @@
- }
- // If the selection doesn't exist, no action
- - var entState = GetEntityState(selection[0]);
- + let entState = GetEntityState(selection[0]);
- if (!entState)
- return undefined;
- // If the selection isn't friendly units, no action
- - var allOwnedByPlayer = selection.every(function(ent) {
- - var entState = GetEntityState(ent);
- + let allOwnedByPlayer = selection.every(function(ent) {
- + let entState = GetEntityState(ent);
- return entState && entState.player == g_ViewedPlayer;
- });
- @@ -263,10 +278,10 @@
- if (!g_DevSettings.controlAll && !allOwnedByPlayer)
- return undefined;
- - var target = undefined;
- + let target = undefined;
- if (!fromMinimap)
- {
- - var ent = Engine.PickEntityAtPoint(x, y);
- + let ent = Engine.PickEntityAtPoint(x, y);
- if (ent != INVALID_ENTITY)
- target = ent;
- }
- @@ -274,17 +289,17 @@
- // decide between the following ordered actions
- // if two actions are possible, the first one is taken
- // so the most specific should appear first
- - var actions = Object.keys(unitActions).slice();
- + let actions = Object.keys(unitActions).slice();
- actions.sort((a, b) => unitActions[a].specificness - unitActions[b].specificness);
- - var actionInfo = undefined;
- + let actionInfo = undefined;
- if (preSelectedAction != ACTION_NONE)
- {
- - for (var action of actions)
- + for (let action of actions)
- {
- if (unitActions[action].preSelectedActionCheck)
- {
- - var r = unitActions[action].preSelectedActionCheck(target, selection);
- + let r = unitActions[action].preSelectedActionCheck(target, selection);
- if (r)
- return r;
- }
- @@ -292,21 +307,21 @@
- return { "type": "none", "cursor": "", "target": target };
- }
- - for (var action of actions)
- + for (let action of actions)
- {
- if (unitActions[action].hotkeyActionCheck)
- {
- - var r = unitActions[action].hotkeyActionCheck(target, selection);
- + let r = unitActions[action].hotkeyActionCheck(target, selection);
- if (r)
- return r;
- }
- }
- - for (var action of actions)
- + for (let action of actions)
- {
- if (unitActions[action].actionCheck)
- {
- - var r = unitActions[action].actionCheck(target, selection);
- + let r = unitActions[action].actionCheck(target, selection);
- if (r)
- return r;
- }
- @@ -315,9 +330,6 @@
- return { "type": "none", "cursor": "", "target": target };
- }
- -
- -var dragStart; // used for remembering mouse coordinates at start of drag operations
- -
- function tryPlaceBuilding(queued)
- {
- if (placementSupport.mode !== "building")
- @@ -337,7 +349,7 @@
- return false;
- }
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- // Start the construction
- Engine.PostNetworkCommand({
- @@ -373,7 +385,7 @@
- return false;
- }
- - var wallPlacementInfo = updateBuildingPlacementPreview(); // entities making up the wall (wall segments, towers, ...)
- + let wallPlacementInfo = updateBuildingPlacementPreview(); // entities making up the wall (wall segments, towers, ...)
- if (!(wallPlacementInfo === false || typeof(wallPlacementInfo) === "object"))
- {
- error(sprintf("[%(functionName)s] Unexpected return value from %(function2Name)s: '%(value)s'; expected either 'false' or 'object'", {
- @@ -387,8 +399,8 @@
- if (!wallPlacementInfo)
- return false;
- - var selection = g_Selection.toList();
- - var cmd = {
- + let selection = g_Selection.toList();
- + let cmd = {
- "type": "construct-wall",
- "autorepair": true,
- "autocontinue": true,
- @@ -403,22 +415,15 @@
- // make sure that there's at least one non-tower entity getting built, to prevent silly edge cases where the start and end
- // point are too close together for the algorithm to place a wall segment inbetween, and only the towers are being previewed
- // (this is somewhat non-ideal and hardcode-ish)
- - var hasWallSegment = false;
- for (let piece of cmd.pieces)
- {
- if (piece.template != cmd.wallSet.templates.tower) // TODO: hardcode-ish :(
- {
- - hasWallSegment = true;
- - break;
- + Engine.PostNetworkCommand(cmd);
- + Engine.GuiInterfaceCall("PlaySound", { "name": "order_repair", "entity": selection[0] });
- + return true;
- }
- }
- -
- - if (hasWallSegment)
- - {
- - Engine.PostNetworkCommand(cmd);
- - Engine.GuiInterfaceCall("PlaySound", { "name": "order_repair", "entity": selection[0] });
- - }
- -
- return true;
- }
- @@ -426,13 +431,10 @@
- // The coordinates [x0, y0, x1, y1] are returned for further use.
- function updateBandbox(bandbox, ev, hidden)
- {
- - var x0 = dragStart[0];
- - var y0 = dragStart[1];
- - var x1 = ev.x;
- - var y1 = ev.y;
- - // normalize the orientation of the rectangle
- - if (x0 > x1) { let t = x0; x0 = x1; x1 = t; }
- - if (y0 > y1) { let t = y0; y0 = y1; y1 = t; }
- + let x0 = Math.min(dragStart[0], ev.x);
- + let y0 = Math.min(dragStart[1], ev.y);
- + let x1 = Math.max(dragStart[0], ev.x);
- + let y1 = Math.max(dragStart[1], ev.y);
- bandbox.size = [x0, y0, x1, y1].join(" ");
- bandbox.hidden = hidden;
- @@ -443,25 +445,25 @@
- // Define some useful unit filters for getPreferredEntities
- var unitFilters = {
- "isUnit": function (entity) {
- - var entState = GetEntityState(entity);
- + let entState = GetEntityState(entity);
- if (!entState)
- return false;
- return hasClass(entState, "Unit");
- },
- "isDefensive": function (entity) {
- - var entState = GetEntityState(entity);
- + let entState = GetEntityState(entity);
- if (!entState)
- return false;
- return hasClass(entState, "Defensive");
- },
- "isNotSupport": function (entity) {
- - var entState = GetEntityState(entity);
- + let entState = GetEntityState(entity);
- if (!entState)
- return false;
- return hasClass(entState, "Unit") && !hasClass(entState, "Support") && !hasClass(entState, "Domestic");
- },
- "isIdle": function (entity) {
- - var entState = GetEntityState(entity);
- + let entState = GetEntityState(entity);
- if (!entState)
- return false;
- return hasClass(entState, "Unit") && entState.unitAI && entState.unitAI.isIdle;
- @@ -476,7 +478,7 @@
- function getPreferredEntities(ents)
- {
- // Default filters
- - var filters = [unitFilters.isUnit, unitFilters.isDefensive, unitFilters.isAnything];
- + let filters = [unitFilters.isUnit, unitFilters.isDefensive, unitFilters.isAnything];
- // Handle hotkeys
- if (Engine.HotkeyIsPressed("selection.milonly"))
- @@ -484,8 +486,8 @@
- if (Engine.HotkeyIsPressed("selection.idleonly"))
- filters = [unitFilters.isIdle];
- - var preferredEnts = [];
- - for (var i = 0; i < filters.length; ++i)
- + let preferredEnts = [];
- + for (let i = 0; i < filters.length; ++i)
- {
- preferredEnts = ents.filter(filters[i]);
- if (preferredEnts.length > 0)
- @@ -528,14 +530,14 @@
- switch (inputState)
- {
- case INPUT_BANDBOXING:
- - var bandbox = Engine.GetGUIObjectByName("bandbox");
- + let bandbox = Engine.GetGUIObjectByName("bandbox");
- switch (ev.type)
- {
- case "mousemotion":
- - var rect = updateBandbox(bandbox, ev, false);
- + let rect = updateBandbox(bandbox, ev, false);
- - var ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_IsObserver ? -1 : Engine.GetPlayerID());
- - var preferredEntities = getPreferredEntities(ents);
- + let ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_IsObserver ? -1 : Engine.GetPlayerID());
- + let preferredEntities = getPreferredEntities(ents);
- g_Selection.setHighlightList(preferredEntities);
- return false;
- @@ -543,10 +545,10 @@
- case "mousebuttonup":
- if (ev.button == SDL_BUTTON_LEFT)
- {
- - var rect = updateBandbox(bandbox, ev, true);
- + let rect = updateBandbox(bandbox, ev, true);
- // Get list of entities limited to preferred entities
- - var ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_IsObserver ? -1 : Engine.GetPlayerID()));
- + let ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_IsObserver ? -1 : Engine.GetPlayerID()));
- // Remove the bandbox hover highlighting
- g_Selection.setHighlightList([]);
- @@ -553,13 +555,9 @@
- // Update the list of selected units
- if (Engine.HotkeyIsPressed("selection.add"))
- - {
- g_Selection.addList(ents);
- - }
- else if (Engine.HotkeyIsPressed("selection.remove"))
- - {
- g_Selection.removeList(ents);
- - }
- else
- {
- g_Selection.reset();
- @@ -579,9 +577,9 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- case INPUT_BUILDING_CLICK:
- switch (ev.type)
- @@ -589,21 +587,18 @@
- case "mousemotion":
- // If the mouse moved far enough from the original click location,
- // then switch to drag-orientation mode
- - var dragDeltaX = ev.x - dragStart[0];
- - var dragDeltaY = ev.y - dragStart[1];
- - var maxDragDelta = 16;
- + let dragDeltaX = ev.x - dragStart[0];
- + let dragDeltaY = ev.y - dragStart[1];
- + let maxDragDelta = 16;
- if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta)
- - {
- inputState = INPUT_BUILDING_DRAG;
- - return false;
- - }
- - break;
- + return false;
- case "mousebuttonup":
- if (ev.button == SDL_BUTTON_LEFT)
- {
- // If shift is down, let the player continue placing another of the same building
- - var queued = Engine.HotkeyIsPressed("session.queue");
- + let queued = Engine.HotkeyIsPressed("session.queue");
- if (tryPlaceBuilding(queued))
- {
- if (queued)
- @@ -612,12 +607,10 @@
- inputState = INPUT_NORMAL;
- }
- else
- - {
- inputState = INPUT_BUILDING_PLACEMENT;
- - }
- return true;
- }
- - break;
- + return false;
- case "mousebuttondown":
- if (ev.button == SDL_BUTTON_RIGHT)
- @@ -627,9 +620,9 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- case INPUT_BUILDING_WALL_CLICK:
- // User is mid-click in choosing a starting point for building a wall. The build process can still be cancelled at this point
- @@ -642,7 +635,7 @@
- inputState = INPUT_BUILDING_WALL_PATHING;
- return true;
- }
- - break;
- + return false;
- case "mousebuttondown":
- if (ev.button == SDL_BUTTON_RIGHT)
- @@ -654,9 +647,9 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- case INPUT_BUILDING_WALL_PATHING:
- // User has chosen a starting point for constructing the wall, and is now looking to set the endpoint.
- @@ -665,97 +658,93 @@
- // user to continue building walls.
- switch (ev.type)
- {
- - case "mousemotion":
- - placementSupport.wallEndPosition = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- + case "mousemotion":
- + placementSupport.wallEndPosition = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- - // Update the building placement preview, and by extension, the list of snapping candidate entities for both (!)
- - // the ending point and the starting point to snap to.
- - //
- - // TODO: Note that here, we need to fetch all similar entities, including any offscreen ones, to support the case
- - // where the snap entity for the starting point has moved offscreen, or has been deleted/destroyed, or was a
- - // foundation and has been replaced with a completed entity since the user first chose it. Fetching all towers on
- - // the entire map instead of only the current screen might get expensive fast since walls all have a ton of towers
- - // in them. Might be useful to query only for entities within a certain range around the starting point and ending
- - // points.
- + // Update the building placement preview, and by extension, the list of snapping candidate entities for both (!)
- + // the ending point and the starting point to snap to.
- + //
- + // TODO: Note that here, we need to fetch all similar entities, including any offscreen ones, to support the case
- + // where the snap entity for the starting point has moved offscreen, or has been deleted/destroyed, or was a
- + // foundation and has been replaced with a completed entity since the user first chose it. Fetching all towers on
- + // the entire map instead of only the current screen might get expensive fast since walls all have a ton of towers
- + // in them. Might be useful to query only for entities within a certain range around the starting point and ending
- + // points.
- - placementSupport.wallSnapEntitiesIncludeOffscreen = true;
- - var result = updateBuildingPlacementPreview(); // includes an update of the snap entity candidates
- + placementSupport.wallSnapEntitiesIncludeOffscreen = true;
- + let result = updateBuildingPlacementPreview(); // includes an update of the snap entity candidates
- + if (result && result.cost)
- + {
- + placementSupport.tooltipMessage = getEntityCostTooltip(result);
- + let neededResources = Engine.GuiInterfaceCall("GetNeededResources", { "cost": result.cost });
- + if (neededResources)
- + placementSupport.tooltipMessage += getNeededResourcesTooltip(neededResources);
- + }
- - if (result && result.cost)
- - {
- - placementSupport.tooltipMessage = getEntityCostTooltip(result);
- - var neededResources = Engine.GuiInterfaceCall("GetNeededResources", { "cost": result.cost });
- - if (neededResources)
- - placementSupport.tooltipMessage += getNeededResourcesTooltip(neededResources);
- - }
- + return false;
- - break;
- -
- - case "mousebuttondown":
- - if (ev.button == SDL_BUTTON_LEFT)
- + case "mousebuttondown":
- + if (ev.button == SDL_BUTTON_LEFT)
- + {
- + let queued = Engine.HotkeyIsPressed("session.queue");
- + if (tryPlaceWall(queued))
- {
- - var queued = Engine.HotkeyIsPressed("session.queue");
- - if (tryPlaceWall(queued))
- + if (queued)
- {
- - if (queued)
- - {
- - // continue building, just set a new starting position where we left off
- - placementSupport.position = placementSupport.wallEndPosition;
- - placementSupport.wallEndPosition = undefined;
- + // continue building, just set a new starting position where we left off
- + placementSupport.position = placementSupport.wallEndPosition;
- + placementSupport.wallEndPosition = undefined;
- - inputState = INPUT_BUILDING_WALL_CLICK;
- - }
- - else
- - {
- - placementSupport.Reset();
- - inputState = INPUT_NORMAL;
- - }
- + inputState = INPUT_BUILDING_WALL_CLICK;
- }
- else
- {
- - placementSupport.tooltipMessage = translate("Cannot build wall here!");
- + placementSupport.Reset();
- + inputState = INPUT_NORMAL;
- }
- -
- - updateBuildingPlacementPreview();
- - return true;
- }
- - else if (ev.button == SDL_BUTTON_RIGHT)
- - {
- - // reset to normal input mode
- - placementSupport.Reset();
- - updateBuildingPlacementPreview();
- + else
- + placementSupport.tooltipMessage = translate("Cannot build wall here!");
- - inputState = INPUT_NORMAL;
- - return true;
- - }
- - break;
- + updateBuildingPlacementPreview();
- + return true;
- + }
- + else if (ev.button == SDL_BUTTON_RIGHT)
- + {
- + // reset to normal input mode
- + placementSupport.Reset();
- + updateBuildingPlacementPreview();
- +
- + inputState = INPUT_NORMAL;
- + return true;
- + }
- + return false;
- }
- - break;
- + return false;
- case INPUT_BUILDING_DRAG:
- switch (ev.type)
- {
- case "mousemotion":
- - var dragDeltaX = ev.x - dragStart[0];
- - var dragDeltaY = ev.y - dragStart[1];
- - var maxDragDelta = 16;
- + let dragDeltaX = ev.x - dragStart[0];
- + let dragDeltaY = ev.y - dragStart[1];
- + let maxDragDelta = 16;
- if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta)
- {
- // Rotate in the direction of the mouse
- - var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- + let target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- placementSupport.angle = Math.atan2(target.x - placementSupport.position.x, target.z - placementSupport.position.z);
- }
- + // If the mouse is near the center, snap back to the default orientation
- else
- - {
- - // If the mouse is near the center, snap back to the default orientation
- placementSupport.SetDefaultAngle();
- - }
- - var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", {
- + let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", {
- "template": placementSupport.template,
- "x": placementSupport.position.x,
- "z": placementSupport.position.z
- });
- +
- if (snapData)
- {
- placementSupport.angle = snapData.angle;
- @@ -764,13 +753,13 @@
- }
- updateBuildingPlacementPreview();
- - break;
- + return false;
- case "mousebuttonup":
- if (ev.button == SDL_BUTTON_LEFT)
- {
- // If shift is down, let the player continue placing another of the same building
- - var queued = Engine.HotkeyIsPressed("session.queue");
- + let queued = Engine.HotkeyIsPressed("session.queue");
- if (tryPlaceBuilding(queued))
- {
- if (queued)
- @@ -779,12 +768,10 @@
- inputState = INPUT_NORMAL;
- }
- else
- - {
- inputState = INPUT_BUILDING_PLACEMENT;
- - }
- return true;
- }
- - break;
- + return false;
- case "mousebuttondown":
- if (ev.button == SDL_BUTTON_RIGHT)
- @@ -794,9 +781,9 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- case INPUT_MASSTRIBUTING:
- if (ev.type == "hotkeyup" && ev.hotkey == "session.masstribute")
- @@ -804,7 +791,7 @@
- g_FlushTributing();
- inputState = INPUT_NORMAL;
- }
- - break;
- + return false;
- case INPUT_BATCHTRAINING:
- if (ev.type == "hotkeyup" && ev.hotkey == "session.batchtrain")
- @@ -812,7 +799,7 @@
- flushTrainingBatch();
- inputState = INPUT_NORMAL;
- }
- - break;
- + return false;
- }
- return false;
- @@ -859,7 +846,7 @@
- {
- case "mousemotion":
- // Highlight the first hovered entity (if any)
- - var ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- + let ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- if (ent != INVALID_ENTITY)
- g_Selection.setHighlightList([ent]);
- else
- @@ -876,37 +863,37 @@
- }
- else if (ev.button == SDL_BUTTON_RIGHT)
- {
- - var action = determineAction(ev.x, ev.y);
- + let action = determineAction(ev.x, ev.y);
- if (!action)
- - break;
- + return false;
- return doAction(action, ev);
- }
- - break;
- + return false;
- case "hotkeydown":
- - if (ev.hotkey.indexOf("selection.group.") == 0)
- + if (ev.hotkey.indexOf("selection.group.") == 0)
- + {
- + let now = new Date();
- + if ((now.getTime() - doublePressTimer < doublePressTime) && (ev.hotkey == prevHotkey))
- {
- - var now = new Date();
- - if ((now.getTime() - doublePressTimer < doublePressTime) && (ev.hotkey == prevHotkey))
- + if (ev.hotkey.indexOf("selection.group.select.") == 0)
- {
- - if (ev.hotkey.indexOf("selection.group.select.") == 0)
- - {
- - var sptr = ev.hotkey.split(".");
- - performGroup("snap", sptr[3]);
- - }
- + let sptr = ev.hotkey.split(".");
- + performGroup("snap", sptr[3]);
- }
- - else
- - {
- - var sptr = ev.hotkey.split(".");
- - performGroup(sptr[2], sptr[3]);
- + }
- + else
- + {
- + let sptr = ev.hotkey.split(".");
- + performGroup(sptr[2], sptr[3]);
- - doublePressTimer = now.getTime();
- - prevHotkey = ev.hotkey;
- - }
- + doublePressTimer = now.getTime();
- + prevHotkey = ev.hotkey;
- }
- - break;
- + }
- + return false;
- }
- - break;
- + return false;
- case INPUT_PRESELECTEDACTION:
- switch (ev.type)
- @@ -913,7 +900,7 @@
- {
- case "mousemotion":
- // Highlight the first hovered entity (if any)
- - var ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- + let ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- if (ent != INVALID_ENTITY)
- g_Selection.setHighlightList([ent]);
- else
- @@ -924,9 +911,9 @@
- case "mousebuttondown":
- if (ev.button == SDL_BUTTON_LEFT && preSelectedAction != ACTION_NONE)
- {
- - var action = determineAction(ev.x, ev.y);
- + let action = determineAction(ev.x, ev.y);
- if (!action)
- - break;
- + return false;
- preSelectedAction = ACTION_NONE;
- inputState = INPUT_NORMAL;
- return doAction(action, ev);
- @@ -935,7 +922,7 @@
- {
- preSelectedAction = ACTION_NONE;
- inputState = INPUT_NORMAL;
- - break;
- + return false;
- }
- // else
- default:
- @@ -944,10 +931,10 @@
- {
- preSelectedAction = ACTION_NONE;
- inputState = INPUT_NORMAL;
- - break;
- + return false;
- }
- }
- - break;
- + return false;
- case INPUT_SELECTING:
- switch (ev.type)
- @@ -954,8 +941,8 @@
- {
- case "mousemotion":
- // If the mouse moved further than a limit, switch to bandbox mode
- - var dragDeltaX = ev.x - dragStart[0];
- - var dragDeltaY = ev.y - dragStart[1];
- + let dragDeltaX = ev.x - dragStart[0];
- + let dragDeltaY = ev.y - dragStart[1];
- if (Math.abs(dragDeltaX) >= maxDragDelta || Math.abs(dragDeltaY) >= maxDragDelta)
- {
- @@ -963,7 +950,7 @@
- return false;
- }
- - var ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- + let ent = Engine.PickEntityAtPoint(ev.x, ev.y);
- if (ent != INVALID_ENTITY)
- g_Selection.setHighlightList([ent]);
- else
- @@ -973,8 +960,8 @@
- case "mousebuttonup":
- if (ev.button == SDL_BUTTON_LEFT)
- {
- - var ents = [];
- - var selectedEntity = Engine.PickEntityAtPoint(ev.x, ev.y);
- + let ents = [];
- + let selectedEntity = Engine.PickEntityAtPoint(ev.x, ev.y);
- if (selectedEntity == INVALID_ENTITY)
- {
- if (!Engine.HotkeyIsPressed("selection.add") && !Engine.HotkeyIsPressed("selection.remove"))
- @@ -986,20 +973,18 @@
- return true;
- }
- - var now = new Date();
- + let now = new Date();
- // If camera following and we select different unit, stop
- if (Engine.GetFollowedEntity() != selectedEntity)
- - {
- Engine.CameraFollow(0);
- - }
- if ((now.getTime() - doubleClickTimer < doubleClickTime) && (selectedEntity == prevClickedEntity))
- {
- // Double click or triple click has occurred
- - var showOffscreen = Engine.HotkeyIsPressed("selection.offscreen");
- - var matchRank = true;
- - var templateToMatch;
- + let showOffscreen = Engine.HotkeyIsPressed("selection.offscreen");
- + let matchRank = true;
- + let templateToMatch;
- // Check for double click or triple click
- if (!doubleClicked)
- @@ -1008,24 +993,19 @@
- // Select similar units regardless of rank
- templateToMatch = GetEntityState(selectedEntity).identity.selectionGroupName;
- if (templateToMatch)
- - {
- matchRank = false;
- - }
- + // No selection group name defined, so fall back to exact match
- else
- - { // No selection group name defined, so fall back to exact match
- templateToMatch = GetEntityState(selectedEntity).template;
- - }
- doubleClicked = true;
- // Reset the timer so the user has an extra period 'doubleClickTimer' to do a triple-click
- doubleClickTimer = now.getTime();
- }
- + // Double click has already occurred, so this is a triple click.
- + // Select units matching exact template name (same rank)
- else
- - {
- - // Double click has already occurred, so this is a triple click.
- - // Select units matching exact template name (same rank)
- templateToMatch = GetEntityState(selectedEntity).template;
- - }
- // TODO: Should we handle "control all units" here as well?
- ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false);
- @@ -1043,13 +1023,9 @@
- // Update the list of selected units
- if (Engine.HotkeyIsPressed("selection.add"))
- - {
- g_Selection.addList(ents);
- - }
- else if (Engine.HotkeyIsPressed("selection.remove"))
- - {
- g_Selection.removeList(ents);
- - }
- else
- {
- g_Selection.reset();
- @@ -1059,9 +1035,9 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- case INPUT_BUILDING_PLACEMENT:
- switch (ev.type)
- @@ -1070,13 +1046,11 @@
- placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- + // Including only the on-screen towers in the next snap candidate list is sufficient here, since the user is
- + // still selecting a starting point (which must necessarily be on-screen). (The update of the snap entities
- + // itself happens in the call to updateBuildingPlacementPreview below).
- if (placementSupport.mode === "wall")
- - {
- - // Including only the on-screen towers in the next snap candidate list is sufficient here, since the user is
- - // still selecting a starting point (which must necessarily be on-screen). (The update of the snap entities
- - // itself happens in the call to updateBuildingPlacementPreview below).
- placementSupport.wallSnapEntitiesIncludeOffscreen = false;
- - }
- else
- {
- // cancel if not enough resources
- @@ -1087,11 +1061,12 @@
- return true;
- }
- - var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", {
- + let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", {
- "template": placementSupport.template,
- "x": placementSupport.position.x,
- "z": placementSupport.position.z,
- });
- +
- if (snapData)
- {
- placementSupport.angle = snapData.angle;
- @@ -1108,7 +1083,7 @@
- {
- if (placementSupport.mode === "wall")
- {
- - var validPlacement = updateBuildingPlacementPreview();
- + let validPlacement = updateBuildingPlacementPreview();
- if (validPlacement !== false)
- inputState = INPUT_BUILDING_WALL_CLICK;
- }
- @@ -1127,11 +1102,11 @@
- inputState = INPUT_NORMAL;
- return true;
- }
- - break;
- + return false;
- case "hotkeydown":
- - var rotation_step = Math.PI / 12; // 24 clicks make a full rotation
- + let rotation_step = Math.PI / 12; // 24 clicks make a full rotation
- switch (ev.hotkey)
- {
- @@ -1138,16 +1113,16 @@
- case "session.rotate.cw":
- placementSupport.angle += rotation_step;
- updateBuildingPlacementPreview();
- - break;
- + return false;
- case "session.rotate.ccw":
- placementSupport.angle -= rotation_step;
- updateBuildingPlacementPreview();
- - break;
- + return false;
- }
- - break;
- + return false;
- }
- - break;
- + return false;
- }
- return false;
- }
- @@ -1154,12 +1129,12 @@
- function doAction(action, ev)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- // If shift is down, add the order to the unit's order queue instead
- // of running it immediately
- - var queued = Engine.HotkeyIsPressed("session.queue");
- - var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- + let queued = Engine.HotkeyIsPressed("session.queue");
- + let target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
- if (unitActions[action.type] && unitActions[action.type].execute)
- return unitActions[action.type].execute(target, action, selection, queued);
- @@ -1175,14 +1150,14 @@
- if (inputState != INPUT_NORMAL)
- return false;
- - var fromMinimap = true;
- - var action = determineAction(undefined, undefined, fromMinimap);
- + let fromMinimap = true;
- + let action = determineAction(undefined, undefined, fromMinimap);
- if (!action)
- return false;
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- - var queued = Engine.HotkeyIsPressed("session.queue");
- + let queued = Engine.HotkeyIsPressed("session.queue");
- if (unitActions[action.type] && unitActions[action.type].execute)
- return unitActions[action.type].execute(target, action, selection, queued);
- error("Invalid action.type "+action.type);
- @@ -1193,7 +1168,7 @@
- // @param buildTemplate Template name of the entity the user wants to build
- function startBuildingPlacement(buildTemplate, playerState)
- {
- - if(getEntityLimitAndCount(playerState, buildTemplate).canBeAddedCount == 0)
- + if (getEntityLimitAndCount(playerState, buildTemplate).canBeAddedCount == 0)
- return;
- // TODO: we should clear any highlight selection rings here. If the mouse was over an entity before going onto the GUI
- @@ -1203,7 +1178,7 @@
- placementSupport.Reset();
- // find out if we're building a wall, and change the entity appropriately if so
- - var templateData = GetTemplateData(buildTemplate);
- + let templateData = GetTemplateData(buildTemplate);
- if (templateData.wallSet)
- {
- placementSupport.mode = "wall";
- @@ -1217,13 +1192,9 @@
- inputState = INPUT_BUILDING_PLACEMENT;
- }
- - if (templateData.attack &&
- - templateData.attack.Ranged &&
- - templateData.attack.Ranged.maxRange)
- - {
- - // add attack information to display a good tooltip
- + // add attack information to display a good tooltip
- + if (templateData.attack && templateData.attack.Ranged && templateData.attack.Ranged.maxRange)
- placementSupport.attack = templateData.attack;
- - }
- }
- // Called by GUI when user changes required trading goods
- @@ -1238,25 +1209,17 @@
- Engine.PostNetworkCommand({ "type": "barter", "sell": command.sell, "buy": command.buy, "amount": command.amount });
- }
- -// Camera jumping: when the user presses a hotkey the current camera location is marked.
- -// When they press another hotkey the camera jumps back to that position. If the camera is already roughly at that location,
- -// jump back to where it was previously.
- -var jumpCameraPositions = [];
- -var jumpCameraLast;
- -var jumpCameraDistanceThreshold = Engine.ConfigDB_GetValue("user", "gui.session.camerajump.threshold");
- -
- function jumpCamera(index)
- {
- - var position = jumpCameraPositions[index];
- + let position = jumpCameraPositions[index];
- if (position)
- {
- - if (jumpCameraLast &&
- - Math.abs(Engine.CameraGetX() - position.x) < jumpCameraDistanceThreshold &&
- - Math.abs(Engine.CameraGetZ() - position.z) < jumpCameraDistanceThreshold)
- + if (jumpCameraLast && Math.abs(Engine.CameraGetX() - position.x) < jumpCameraDistanceThreshold &&
- + Math.abs(Engine.CameraGetZ() - position.z) < jumpCameraDistanceThreshold)
- Engine.CameraMoveTo(jumpCameraLast.x, jumpCameraLast.z);
- else
- {
- - jumpCameraLast = {x: Engine.CameraGetX(), z: Engine.CameraGetZ()};
- + jumpCameraLast = { x: Engine.CameraGetX(), z: Engine.CameraGetZ()};
- Engine.CameraMoveTo(position.x, position.z);
- }
- }
- @@ -1264,28 +1227,19 @@
- function setJumpCamera(index)
- {
- - jumpCameraPositions[index] = {x: Engine.CameraGetX(), z: Engine.CameraGetZ()};
- + jumpCameraPositions[index] = { x: Engine.CameraGetX(), z: Engine.CameraGetZ() };
- }
- -// Batch training:
- -// When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING
- -// When the user releases shift, or clicks on a different training button, we create the batched units
- -var batchTrainingEntities;
- -var batchTrainingType;
- -var batchTrainingCount;
- -var batchTrainingEntityAllowedCount;
- -const batchIncrementSize = 5;
- -
- function flushTrainingBatch()
- {
- - var appropriateBuildings = getBuildingsWhichCanTrainEntity(batchTrainingEntities, batchTrainingType);
- + let appropriateBuildings = getBuildingsWhichCanTrainEntity(batchTrainingEntities, batchTrainingType);
- // If training limits don't allow us to train batchTrainingCount in each appropriate building
- if (batchTrainingEntityAllowedCount !== undefined &&
- batchTrainingEntityAllowedCount < batchTrainingCount * appropriateBuildings.length)
- {
- // Train as many full batches as we can
- - var buildingsCountToTrainFullBatch = Math.floor(batchTrainingEntityAllowedCount / batchTrainingCount);
- - var buildingsToTrainFullBatch = appropriateBuildings.slice(0, buildingsCountToTrainFullBatch);
- + let buildingsCountToTrainFullBatch = Math.floor(batchTrainingEntityAllowedCount / batchTrainingCount);
- + let buildingsToTrainFullBatch = appropriateBuildings.slice(0, buildingsCountToTrainFullBatch);
- Engine.PostNetworkCommand({
- "type": "train",
- "entities": buildingsToTrainFullBatch,
- @@ -1313,8 +1267,8 @@
- function getBuildingsWhichCanTrainEntity(entitiesToCheck, trainEntType)
- {
- return entitiesToCheck.filter(function(entity) {
- - var state = GetEntityState(entity);
- - var canTrain = state && state.production && state.production.entities.length &&
- + let state = GetEntityState(entity);
- + let canTrain = state && state.production && state.production.entities.length &&
- state.production.entities.indexOf(trainEntType) != -1;
- return canTrain;
- });
- @@ -1322,7 +1276,7 @@
- function getEntityLimitAndCount(playerState, entType)
- {
- - var r = {
- + let r = {
- "entLimit": undefined,
- "entCount": undefined,
- "entLimitChangers": undefined,
- @@ -1330,8 +1284,9 @@
- };
- if (!playerState.entityLimits)
- return r;
- - var template = GetTemplateData(entType);
- - var entCategory = null;
- +
- + let template = GetTemplateData(entType);
- + let entCategory = null;
- if (template.trainingRestrictions)
- entCategory = template.trainingRestrictions.category;
- else if (template.buildRestrictions)
- @@ -1349,20 +1304,20 @@
- // Add the unit shown at position to the training queue for all entities in the selection
- function addTrainingByPosition(position)
- {
- - var simState = GetSimState();
- - var playerState = simState.players[Engine.GetPlayerID()];
- - var selection = g_Selection.toList();
- + let simState = GetSimState();
- + let playerState = simState.players[Engine.GetPlayerID()];
- + let selection = g_Selection.toList();
- if (!playerState || !selection.length)
- return;
- - var trainableEnts = getAllTrainableEntitiesFromSelection();
- + let trainableEnts = getAllTrainableEntitiesFromSelection();
- // Check if the position is valid
- if (!trainableEnts.length || trainableEnts.length <= position)
- return;
- - var entToTrain = trainableEnts[position];
- + let entToTrain = trainableEnts[position];
- addTrainingToQueue(selection, entToTrain, playerState);
- return;
- @@ -1372,17 +1327,18 @@
- function addTrainingToQueue(selection, trainEntType, playerState)
- {
- // Create list of buildings which can train trainEntType
- - var appropriateBuildings = getBuildingsWhichCanTrainEntity(selection, trainEntType);
- + let appropriateBuildings = getBuildingsWhichCanTrainEntity(selection, trainEntType);
- // Check trainEntType entity limit and count
- - var limits = getEntityLimitAndCount(playerState, trainEntType);
- + let limits = getEntityLimitAndCount(playerState, trainEntType);
- // Batch training possible if we can train at least 2 units
- - var batchTrainingPossible = limits.canBeAddedCount == undefined || limits.canBeAddedCount > 1;
- + let batchTrainingPossible = limits.canBeAddedCount == undefined || limits.canBeAddedCount > 1;
- - var decrement = Engine.HotkeyIsPressed("selection.remove");
- + let decrement = Engine.HotkeyIsPressed("selection.remove");
- + let template;
- if (!decrement)
- - var template = GetTemplateData(trainEntType);
- + template = GetTemplateData(trainEntType);
- if (Engine.HotkeyIsPressed("session.batchtrain") && batchTrainingPossible)
- {
- @@ -1389,16 +1345,14 @@
- if (inputState == INPUT_BATCHTRAINING)
- {
- // Check if we are training in the same building(s) as the last batch
- - var sameEnts = false;
- + let sameEnts = false;
- if (batchTrainingEntities.length == selection.length)
- {
- // NOTE: We just check if the arrays are the same and if the order is the same
- // If the order changed, we have a new selection and we should create a new batch.
- - for (var i = 0; i < batchTrainingEntities.length; ++i)
- - {
- + for (let i = 0; i < batchTrainingEntities.length; ++i)
- if (!(sameEnts = batchTrainingEntities[i] == selection[i]))
- break;
- - }
- }
- // If we're already creating a batch of this unit (in the same building(s)), then just extend it
- // (if training limits allow)
- @@ -1424,10 +1378,8 @@
- }
- // Otherwise start a new one
- else if (!decrement)
- - {
- flushTrainingBatch();
- - // fall through to create the new batch
- - }
- + // fall through to create the new batch
- }
- // Don't start a new batch if decrementing or unable to afford it.
- @@ -1445,7 +1397,7 @@
- {
- // Non-batched - just create a single entity in each building
- // (but no more than entity limit allows)
- - var buildingsForTraining = appropriateBuildings;
- + let buildingsForTraining = appropriateBuildings;
- if (limits.entLimit)
- buildingsForTraining = buildingsForTraining.slice(0, limits.canBeAddedCount);
- Engine.PostNetworkCommand({
- @@ -1467,25 +1419,23 @@
- // the training button with shift down
- function getTrainingBatchStatus(playerState, entity, trainEntType, selection)
- {
- - var appropriateBuildings = [entity];
- + let appropriateBuildings = [entity];
- if (selection && selection.indexOf(entity) != -1)
- appropriateBuildings = getBuildingsWhichCanTrainEntity(selection, trainEntType);
- - var nextBatchTrainingCount = 0;
- - var currentBatchTrainingCount = 0;
- + let nextBatchTrainingCount = 0;
- + let currentBatchTrainingCount = 0;
- + let limits;
- if (inputState == INPUT_BATCHTRAINING && batchTrainingEntities.indexOf(entity) != -1 &&
- batchTrainingType == trainEntType)
- {
- nextBatchTrainingCount = batchTrainingCount;
- currentBatchTrainingCount = batchTrainingCount;
- - var limits = {
- - "canBeAddedCount": batchTrainingEntityAllowedCount
- - };
- + limits = { "canBeAddedCount": batchTrainingEntityAllowedCount };
- }
- else
- - {
- - var limits = getEntityLimitAndCount(playerState, trainEntType);
- - }
- + limits = getEntityLimitAndCount(playerState, trainEntType);
- +
- // We need to calculate count after the next increment if it's possible
- if (limits.canBeAddedCount == undefined ||
- limits.canBeAddedCount > nextBatchTrainingCount * appropriateBuildings.length)
- @@ -1492,8 +1442,8 @@
- nextBatchTrainingCount += batchIncrementSize;
- // If training limits don't allow us to train batchTrainingCount in each appropriate building
- // train as many full batches as we can and remainer in one more building.
- - var buildingsCountToTrainFullBatch = appropriateBuildings.length;
- - var remainderToTrain = 0;
- + let buildingsCountToTrainFullBatch = appropriateBuildings.length;
- + let remainderToTrain = 0;
- if (limits.canBeAddedCount !== undefined &&
- limits.canBeAddedCount < nextBatchTrainingCount * appropriateBuildings.length)
- {
- @@ -1520,7 +1470,7 @@
- {
- if (!entity)
- return;
- - var entState = GetExtendedEntityState(entity);
- + let entState = GetExtendedEntityState(entity);
- if (!controlsPlayer(entState.player))
- return;
- @@ -1534,9 +1484,9 @@
- {
- if (!entity)
- return;
- - var entState = GetExtendedEntityState(entity);
- + let entState = GetExtendedEntityState(entity);
- - var playerState = GetSimState().players[Engine.GetPlayerID()];
- + let playerState = GetSimState().players[Engine.GetPlayerID()];
- if (!playerState.isMutualAlly[entState.player] || g_IsObserver)
- return;
- @@ -1563,9 +1513,9 @@
- case "snap":
- case "select":
- case "add":
- - var toSelect = [];
- + let toSelect = [];
- g_Groups.update();
- - for (var ent in g_Groups.groups[groupId].ents)
- + for (let ent in g_Groups.groups[groupId].ents)
- toSelect.push(+ent);
- if (action != "add")
- @@ -1580,7 +1530,7 @@
- if (position && entState.visibility != "hidden")
- Engine.CameraMoveTo(position.x, position.z);
- }
- - break;
- + return;
- case "save":
- case "breakUp":
- g_Groups.groups[groupId].reset();
- @@ -1589,7 +1539,7 @@
- g_Groups.addEntities(groupId, g_Selection.toList());
- updateGroups();
- - break;
- + return;
- }
- }
- // Performs the specified stance
- @@ -1597,7 +1547,7 @@
- {
- if (entity)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- Engine.PostNetworkCommand({
- "type": "stance",
- "entities": selection,
- @@ -1609,7 +1559,7 @@
- // Lock / Unlock the gate
- function lockGate(lock)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- Engine.PostNetworkCommand({
- "type": "lock-gate",
- "entities": selection,
- @@ -1620,7 +1570,7 @@
- // Pack / unpack unit(s)
- function packUnit(pack)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- Engine.PostNetworkCommand({
- "type": "pack",
- "entities": selection,
- @@ -1632,7 +1582,7 @@
- // Cancel un/packing unit(s)
- function cancelPackUnit(pack)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- Engine.PostNetworkCommand({
- "type": "cancel-pack",
- "entities": selection,
- @@ -1644,7 +1594,7 @@
- // Transform a wall to a gate
- function transformWallToGate(template)
- {
- - var selection = g_Selection.toList();
- + let selection = g_Selection.toList();
- Engine.PostNetworkCommand({
- "type": "wall-to-gate",
- "entities": selection.filter( function(e) { return getWallGateTemplate(e) == template; } ),
- @@ -1656,8 +1606,8 @@
- function getWallGateTemplate(entity)
- {
- // TODO: find the gate template name in a better way
- - var entState = GetEntityState(entity);
- - var index;
- + let entState = GetEntityState(entity);
- + let index;
- if (entState && !entState.foundation && hasClass(entState, "LongWall") && (index = entState.template.indexOf("long")) >= 0)
- return entState.template.substr(0, index) + "gate";
- @@ -1670,7 +1620,7 @@
- // Follow the given entity if it's a unit
- if (entity)
- {
- - var entState = GetEntityState(entity);
- + let entState = GetEntityState(entity);
- if (entState && hasClass(entState, "Unit"))
- {
- Engine.CameraFollow(entity);
- @@ -1682,10 +1632,6 @@
- Engine.CameraFollow(0);
- }
- -var lastIdleUnit = 0;
- -var currIdleClassIndex = 0;
- -var lastIdleClasses = [];
- -
- function resetIdleUnit()
- {
- lastIdleUnit = 0;
- @@ -1695,8 +1641,8 @@
- function findIdleUnit(classes)
- {
- - var append = Engine.HotkeyIsPressed("selection.add");
- - var selectall = Engine.HotkeyIsPressed("selection.offscreen");
- + let append = Engine.HotkeyIsPressed("selection.add");
- + let selectall = Engine.HotkeyIsPressed("selection.offscreen");
- // Reset the last idle unit, etc., if the selection type has changed.
- if (selectall || classes.length != lastIdleClasses.length || !classes.every((v,i) => v === lastIdleClasses[i]))
- @@ -1703,7 +1649,7 @@
- resetIdleUnit();
- lastIdleClasses = classes;
- - var data = {
- + let data = {
- "viewedPlayer": g_ViewedPlayer,
- "excludeUnits": append ? g_Selection.toList() : [],
- // If the current idle class index is not 0, put the class at that index first.
- @@ -1715,7 +1661,7 @@
- data.prevUnit = lastIdleUnit;
- }
- - var idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", data);
- + let idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", data);
- if (!idleUnits.length)
- {
- // TODO: display a message or play a sound to indicate no more idle units, or something
- @@ -1732,12 +1678,12 @@
- return;
- lastIdleUnit = idleUnits[0];
- - var entityState = GetEntityState(lastIdleUnit);
- - var position = entityState.position;
- + let entityState = GetEntityState(lastIdleUnit);
- + let position = entityState.position;
- if (position)
- Engine.CameraMoveTo(position.x, position.z);
- // Move the idle class index to the first class an idle unit was found for.
- - var indexChange = data.idleClasses.findIndex(elem => hasClass(entityState, elem));
- + let indexChange = data.idleClasses.findIndex(elem => hasClass(entityState, elem));
- currIdleClassIndex = (currIdleClassIndex + indexChange) % classes.length;
- }
- @@ -1757,8 +1703,8 @@
- function unloadTemplate(template)
- {
- // Filter out all entities that aren't garrisonable.
- - var garrisonHolders = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let garrisonHolders = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- if (state && state.garrisonHolder)
- return true;
- return false;
- @@ -1774,11 +1720,11 @@
- function unloadSelection()
- {
- - var parent = 0;
- - var ents = [];
- - for each (var ent in g_Selection.selected)
- + let parent = 0;
- + let ents = [];
- + for (let ent of g_Selection.selected)
- {
- - var state = GetExtendedEntityState(ent);
- + let state = GetExtendedEntityState(ent);
- if (!state || !state.turretParent)
- continue;
- if (!parent)
- @@ -1795,8 +1741,8 @@
- function unloadAllByOwner()
- {
- - var garrisonHolders = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let garrisonHolders = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- return state && state.garrisonHolder;
- });
- Engine.PostNetworkCommand({ "type": "unload-all-by-owner", "garrisonHolders": garrisonHolders });
- @@ -1805,8 +1751,8 @@
- function unloadAll()
- {
- // Filter out all entities that aren't garrisonable.
- - var garrisonHolders = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let garrisonHolders = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- if (state && state.garrisonHolder)
- return true;
- return false;
- @@ -1818,8 +1764,8 @@
- function backToWork()
- {
- // Filter out all entities that can't go back to work.
- - var workers = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let workers = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- return (state && state.unitAI && state.unitAI.hasWorkOrders);
- });
- @@ -1829,8 +1775,8 @@
- function removeGuard()
- {
- // Filter out all entities that are currently guarding/escorting.
- - var entities = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let entities = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- return (state && state.unitAI && state.unitAI.isGuarding);
- });
- @@ -1839,8 +1785,8 @@
- function increaseAlertLevel()
- {
- - var entities = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let entities = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- return (state && state.alertRaiser && state.alertRaiser.canIncreaseLevel);
- });
- @@ -1849,8 +1795,8 @@
- function endOfAlert()
- {
- - var entities = g_Selection.toList().filter(function(e) {
- - var state = GetEntityState(e);
- + let entities = g_Selection.toList().filter(function(e) {
- + let state = GetEntityState(e);
- return (state && state.alertRaiser && state.alertRaiser.hasRaisedAlert);
- });
- @@ -1875,28 +1821,29 @@
- */
- function getTrainingQueueItems(selection)
- {
- - var entStates = [];
- - for (var ent of selection)
- + let entStates = [];
- + for (let ent of selection)
- {
- - var entState = GetEntityState(ent);
- + let entState = GetEntityState(ent);
- if (entState.production)
- entStates.push(entState);
- }
- - var queue = [];
- - var i = 0;
- + let queue = [];
- + let i = 0;
- + let foundNewItems;
- do
- {
- - var foundNewItems = false;
- - for (entState of entStates)
- + foundNewItems = false;
- + for (let entState of entStates)
- {
- if (!entState.production.queue[i])
- continue;
- - var item = entState.production.queue[i];
- + let item = entState.production.queue[i];
- item.producingEnt = entState.id;
- queue.push(item);
- foundNewItems = true;
- }
- - i++;
- + ++i;
- }
- while (foundNewItems);
- return queue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement