Changeset View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | if (!fromMiniMap) | ||||
if (ent != INVALID_ENTITY) | if (ent != INVALID_ENTITY) | ||||
target = ent; | target = ent; | ||||
} | } | ||||
// Decide between the following ordered actions, | // Decide between the following ordered actions, | ||||
// if two actions are possible, the first one is taken | // if two actions are possible, the first one is taken | ||||
// thus the most specific should appear first. | // thus the most specific should appear first. | ||||
let actionInfo = undefined; | let actionInfo = undefined; | ||||
Lint: ESLintBear (no-undef-init): `It's not necessary to initialize 'actionInfo' to undefined.` | |||||
Lint: JSHintBear It's not necessary to initialize 'actionInfo' to 'undefined'. Lint: JSHintBear: `It's not necessary to initialize 'actionInfo' to 'undefined'.` | |||||
if (preSelectedAction != ACTION_NONE) | if (preSelectedAction != ACTION_NONE) | ||||
{ | { | ||||
for (let action of g_UnitActionsSortedKeys) | for (let action of g_UnitActionsSortedKeys) | ||||
if (g_UnitActions[action].preSelectedActionCheck) | if (g_UnitActions[action].preSelectedActionCheck) | ||||
{ | { | ||||
let r = g_UnitActions[action].preSelectedActionCheck(target, selection); | let r = g_UnitActions[action].preSelectedActionCheck(target, selection); | ||||
if (r) | if (r) | ||||
return r; | return r; | ||||
▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | |||||
function handleInputBeforeGui(ev, hoveredObject) | function handleInputBeforeGui(ev, hoveredObject) | ||||
{ | { | ||||
if (GetSimState().cinemaPlaying) | if (GetSimState().cinemaPlaying) | ||||
return false; | return false; | ||||
// Capture mouse position so we can use it for displaying cursors, | // Capture mouse position so we can use it for displaying cursors, | ||||
// and key states | // and key states | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
case "mousebuttondown": | case "mousebuttondown": | ||||
case "mousemotion": | case "mousemotion": | ||||
mouseX = ev.x; | mouseX = ev.x; | ||||
mouseY = ev.y; | mouseY = ev.y; | ||||
break; | break; | ||||
} | } | ||||
// Remember whether the mouse is over a GUI object or not | // Remember whether the mouse is over a GUI object or not | ||||
mouseIsOverObject = (hoveredObject != null); | mouseIsOverObject = (hoveredObject != null); | ||||
// Close the menu when interacting with the game world | // Close the menu when interacting with the game world | ||||
if (!mouseIsOverObject && (ev.type =="mousebuttonup" || ev.type == "mousebuttondown") | if (!mouseIsOverObject && (ev.type =="mousebuttonup" || ev.type == "mousebuttondown") | ||||
&& (ev.button == SDL_BUTTON_LEFT || ev.button == SDL_BUTTON_RIGHT)) | && (ev.button == SDL_BUTTON_LEFT || ev.button == SDL_BUTTON_RIGHT)) | ||||
Lint: JSHintBear Misleading line break before '&&'; readers may interpret this as an expression boundary. Lint: JSHintBear: `Misleading line break before '&&'; readers may interpret this as an expression boundary.` | |||||
Lint: ESLintBear (operator-linebreak) '&&' should be placed at the end of the line. Lint: ESLintBear (operator-linebreak): `'&&' should be placed at the end of the line.` | |||||
g_Menu.close(); | g_Menu.close(); | ||||
// State-machine processing: | // State-machine processing: | ||||
// | // | ||||
// (This is for states which should override the normal GUI processing - events will | // (This is for states which should override the normal GUI processing - events will | ||||
// be processed here before being passed on, and propagation will stop if this function | // be processed here before being passed on, and propagation will stop if this function | ||||
// returns true) | // returns true) | ||||
// | // | ||||
// TODO: it'd probably be nice to have a better state-machine system, with guaranteed | // TODO: it'd probably be nice to have a better state-machine system, with guaranteed | ||||
// entry/exit functions, since this is a bit broken now | // entry/exit functions, since this is a bit broken now | ||||
switch (inputState) | switch (inputState) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case INPUT_BANDBOXING: | case INPUT_BANDBOXING: | ||||
var bandbox = Engine.GetGUIObjectByName("bandbox"); | var bandbox = Engine.GetGUIObjectByName("bandbox"); | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
var rect = updateBandbox(bandbox, ev, false); | var rect = updateBandbox(bandbox, ev, false); | ||||
var ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_ViewedPlayer); | var ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_ViewedPlayer); | ||||
var preferredEntities = getPreferredEntities(ents); | var preferredEntities = getPreferredEntities(ents); | ||||
g_Selection.setHighlightList(preferredEntities); | g_Selection.setHighlightList(preferredEntities); | ||||
return false; | return false; | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
{ | { | ||||
var rect = updateBandbox(bandbox, ev, true); | var rect = updateBandbox(bandbox, ev, true); | ||||
Lint: JSHintBear 'rect' is already defined. Lint: JSHintBear: `'rect' is already defined.` | |||||
// Get list of entities limited to preferred entities | // Get list of entities limited to preferred entities | ||||
var ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_ViewedPlayer)); | var ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], g_ViewedPlayer)); | ||||
Lint: JSHintBear 'ents' is already defined. Lint: JSHintBear: `'ents' is already defined.` | |||||
// Remove the bandbox hover highlighting | // Remove the bandbox hover highlighting | ||||
g_Selection.setHighlightList([]); | g_Selection.setHighlightList([]); | ||||
// Update the list of selected units | // Update the list of selected units | ||||
if (Engine.HotkeyIsPressed("selection.add")) | if (Engine.HotkeyIsPressed("selection.add")) | ||||
{ | { | ||||
g_Selection.addList(ents); | g_Selection.addList(ents); | ||||
Show All 21 Lines | case "mousebuttonup": | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case INPUT_UNIT_POSITION: | case INPUT_UNIT_POSITION: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
return positionUnitsFreehandSelectionMouseMove(ev); | return positionUnitsFreehandSelectionMouseMove(ev); | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
return positionUnitsFreehandSelectionMouseUp(ev); | return positionUnitsFreehandSelectionMouseUp(ev); | ||||
} | } | ||||
break; | break; | ||||
case INPUT_BUILDING_CLICK: | case INPUT_BUILDING_CLICK: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
// If the mouse moved far enough from the original click location, | // If the mouse moved far enough from the original click location, | ||||
// then switch to drag-orientation mode | // then switch to drag-orientation mode | ||||
let maxDragDelta = 16; | let maxDragDelta = 16; | ||||
if (g_DragStart.distanceTo(ev) >= maxDragDelta) | if (g_DragStart.distanceTo(ev) >= maxDragDelta) | ||||
{ | { | ||||
inputState = INPUT_BUILDING_DRAG; | inputState = INPUT_BUILDING_DRAG; | ||||
Show All 31 Lines | case "mousebuttondown": | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case INPUT_BUILDING_WALL_CLICK: | 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 | // User is mid-click in choosing a starting point for building a wall. The build process can still be cancelled at this point | ||||
// by right-clicking; releasing the left mouse button will 'register' the starting point and commence endpoint choosing mode. | // by right-clicking; releasing the left mouse button will 'register' the starting point and commence endpoint choosing mode. | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
if (ev.button === SDL_BUTTON_LEFT) | if (ev.button === SDL_BUTTON_LEFT) | ||||
{ | { | ||||
inputState = INPUT_BUILDING_WALL_PATHING; | inputState = INPUT_BUILDING_WALL_PATHING; | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
Show All 12 Lines | case INPUT_BUILDING_WALL_CLICK: | ||||
} | } | ||||
break; | break; | ||||
case INPUT_BUILDING_WALL_PATHING: | case INPUT_BUILDING_WALL_PATHING: | ||||
// User has chosen a starting point for constructing the wall, and is now looking to set the endpoint. | // User has chosen a starting point for constructing the wall, and is now looking to set the endpoint. | ||||
// Right-clicking cancels wall building mode, left-clicking sets the endpoint and builds the wall and returns to | // Right-clicking cancels wall building mode, left-clicking sets the endpoint and builds the wall and returns to | ||||
// normal input mode. Optionally, shift + left-clicking does not return to normal input, and instead allows the | // normal input mode. Optionally, shift + left-clicking does not return to normal input, and instead allows the | ||||
// user to continue building walls. | // user to continue building walls. | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
Lint: ESLintBear (indent) Expected indentation of 2 tabs but found 3. Lint: ESLintBear (indent): `Expected indentation of 2 tabs but found 3.` | |||||
placementSupport.wallEndPosition = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | placementSupport.wallEndPosition = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// Update the structure placement preview, and by extension, the list of snapping candidate entities for both (!) | // Update the structure placement preview, and by extension, the list of snapping candidate entities for both (!) | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// the ending point and the starting point to snap to. | // the ending point and the starting point to snap to. | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// | // | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// TODO: Note that here, we need to fetch all similar entities, including any offscreen ones, to support the case | // TODO: Note that here, we need to fetch all similar entities, including any offscreen ones, to support the case | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// where the snap entity for the starting point has moved offscreen, or has been deleted/destroyed, or was a | // where the snap entity for the starting point has moved offscreen, or has been deleted/destroyed, or was a | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// foundation and has been replaced with a completed entity since the user first chose it. Fetching all towers on | // foundation and has been replaced with a completed entity since the user first chose it. Fetching all towers on | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// the entire map instead of only the current screen might get expensive fast since walls all have a ton of towers | // the entire map instead of only the current screen might get expensive fast since walls all have a ton of towers | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// in them. Might be useful to query only for entities within a certain range around the starting point and ending | // in them. Might be useful to query only for entities within a certain range around the starting point and ending | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// points. | // points. | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
placementSupport.wallSnapEntitiesIncludeOffscreen = true; | placementSupport.wallSnapEntitiesIncludeOffscreen = true; | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
var result = updateBuildingPlacementPreview(); // includes an update of the snap entity candidates | var result = updateBuildingPlacementPreview(); // includes an update of the snap entity candidates | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
if (result && result.cost) | if (result && result.cost) | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
var neededResources = Engine.GuiInterfaceCall("GetNeededResources", { "cost": result.cost }); | var neededResources = Engine.GuiInterfaceCall("GetNeededResources", { "cost": result.cost }); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
placementSupport.tooltipMessage = [ | placementSupport.tooltipMessage = [ | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
getEntityCostTooltip(result), | getEntityCostTooltip(result), | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
getNeededResourcesTooltip(neededResources) | getNeededResourcesTooltip(neededResources) | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
].filter(tip => tip).join("\n"); | ].filter(tip => tip).join("\n"); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
break; | break; | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
case "mousebuttondown": | case "mousebuttondown": | ||||
Lint: ESLintBear (indent) Expected indentation of 2 tabs but found 3. Lint: ESLintBear (indent): `Expected indentation of 2 tabs but found 3.` | |||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
var queued = Engine.HotkeyIsPressed("session.queue"); | var queued = Engine.HotkeyIsPressed("session.queue"); | ||||
Lint: JSHintBear 'queued' is already defined. Lint: JSHintBear: `'queued' is already defined.` | |||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
if (tryPlaceWall(queued)) | if (tryPlaceWall(queued)) | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
if (queued) | if (queued) | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
// continue building, just set a new starting position where we left off | // continue building, just set a new starting position where we left off | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
placementSupport.position = placementSupport.wallEndPosition; | placementSupport.position = placementSupport.wallEndPosition; | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
placementSupport.wallEndPosition = undefined; | placementSupport.wallEndPosition = undefined; | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
inputState = INPUT_BUILDING_WALL_CLICK; | inputState = INPUT_BUILDING_WALL_CLICK; | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
else | else | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
else | else | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
placementSupport.tooltipMessage = translate("Cannot build wall here!"); | placementSupport.tooltipMessage = translate("Cannot build wall here!"); | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
return true; | return true; | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
else if (ev.button == SDL_BUTTON_RIGHT) | else if (ev.button == SDL_BUTTON_RIGHT) | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
// reset to normal input mode | // reset to normal input mode | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
return true; | return true; | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
break; | break; | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
} | } | ||||
break; | break; | ||||
case INPUT_BUILDING_DRAG: | case INPUT_BUILDING_DRAG: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
let maxDragDelta = 16; | let maxDragDelta = 16; | ||||
if (g_DragStart.distanceTo(ev) >= maxDragDelta) | if (g_DragStart.distanceTo(ev) >= maxDragDelta) | ||||
{ | { | ||||
// Rotate in the direction of the mouse | // Rotate in the direction of the mouse | ||||
placementSupport.angle = placementSupport.position.horizAngleTo(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | placementSupport.angle = placementSupport.position.horizAngleTo(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// If the mouse is near the center, snap back to the default orientation | // If the mouse is near the center, snap back to the default orientation | ||||
placementSupport.SetDefaultAngle(); | placementSupport.SetDefaultAngle(); | ||||
} | } | ||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"angle": placementSupport.angle, | "angle": placementSupport.angle, | ||||
"snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | "snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | ||||
placementSupport.position.x, placementSupport.position.z) | placementSupport.position.x, placementSupport.position.z) | ||||
}); | }); | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
if (snapData) | if (snapData) | ||||
{ | { | ||||
placementSupport.angle = snapData.angle; | placementSupport.angle = snapData.angle; | ||||
placementSupport.position.x = snapData.x; | placementSupport.position.x = snapData.x; | ||||
placementSupport.position.z = snapData.z; | placementSupport.position.z = snapData.z; | ||||
} | } | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
break; | break; | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
{ | { | ||||
// If shift is down, let the player continue placing another of the same structure. | // If shift is down, let the player continue placing another of the same structure. | ||||
var queued = Engine.HotkeyIsPressed("session.queue"); | var queued = Engine.HotkeyIsPressed("session.queue"); | ||||
Lint: JSHintBear 'queued' is already defined. Lint: JSHintBear: `'queued' is already defined.` | |||||
if (tryPlaceBuilding(queued)) | if (tryPlaceBuilding(queued)) | ||||
{ | { | ||||
if (queued && g_Selection.toList().length) | if (queued && g_Selection.toList().length) | ||||
inputState = INPUT_BUILDING_PLACEMENT; | inputState = INPUT_BUILDING_PLACEMENT; | ||||
else | else | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
} | } | ||||
else | else | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | else if (ev.hotkey == "session.highlightguarded") | ||||
updateAdditionalHighlight(); | updateAdditionalHighlight(); | ||||
} | } | ||||
if (inputState != INPUT_NORMAL && inputState != INPUT_SELECTING) | if (inputState != INPUT_NORMAL && inputState != INPUT_SELECTING) | ||||
clickedEntity = INVALID_ENTITY; | clickedEntity = INVALID_ENTITY; | ||||
// State-machine processing: | // State-machine processing: | ||||
switch (inputState) | switch (inputState) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case INPUT_NORMAL: | case INPUT_NORMAL: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
// Highlight the first hovered entity (if any) | // Highlight the first hovered entity (if any) | ||||
var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | ||||
if (ent != INVALID_ENTITY) | if (ent != INVALID_ENTITY) | ||||
g_Selection.setHighlightList([ent]); | g_Selection.setHighlightList([ent]); | ||||
else | else | ||||
g_Selection.setHighlightList([]); | g_Selection.setHighlightList([]); | ||||
Show All 16 Lines | case "mousebuttondown": | ||||
if (!controlsPlayer(g_ViewedPlayer)) | if (!controlsPlayer(g_ViewedPlayer)) | ||||
break; | break; | ||||
g_DragStart = new Vector2D(ev.x, ev.y); | g_DragStart = new Vector2D(ev.x, ev.y); | ||||
inputState = INPUT_UNIT_POSITION_START; | inputState = INPUT_UNIT_POSITION_START; | ||||
} | } | ||||
break; | break; | ||||
case "hotkeydown": | case "hotkeydown": | ||||
if (ev.hotkey.indexOf("selection.group.") == 0) | if (ev.hotkey.indexOf("selection.group.") == 0) | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
let now = Date.now(); | let now = Date.now(); | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
if (now - doublePressTimer < doublePressTime && ev.hotkey == prevHotkey) | if (now - doublePressTimer < doublePressTime && ev.hotkey == prevHotkey) | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
if (ev.hotkey.indexOf("selection.group.select.") == 0) | if (ev.hotkey.indexOf("selection.group.select.") == 0) | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
var sptr = ev.hotkey.split("."); | var sptr = ev.hotkey.split("."); | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
performGroup("snap", sptr[3]); | performGroup("snap", sptr[3]); | ||||
Lint: ESLintBear (indent) Expected indentation of 6 tabs but found 7. Lint: ESLintBear (indent): `Expected indentation of 6 tabs but found 7.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
else | else | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
{ | { | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
var sptr = ev.hotkey.split("."); | var sptr = ev.hotkey.split("."); | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
Lint: JSHintBear 'sptr' is already defined. Lint: JSHintBear: `'sptr' is already defined.` | |||||
performGroup(sptr[2], sptr[3]); | performGroup(sptr[2], sptr[3]); | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
doublePressTimer = now; | doublePressTimer = now; | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
prevHotkey = ev.hotkey; | prevHotkey = ev.hotkey; | ||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 4 tabs but found 5. Lint: ESLintBear (indent): `Expected indentation of 4 tabs but found 5.` | |||||
} | } | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
break; | break; | ||||
Lint: ESLintBear (indent) Expected indentation of 3 tabs but found 4. Lint: ESLintBear (indent): `Expected indentation of 3 tabs but found 4.` | |||||
} | } | ||||
break; | break; | ||||
case INPUT_PRESELECTEDACTION: | case INPUT_PRESELECTEDACTION: | ||||
switch (ev.type) | switch (ev.type) | ||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
// Highlight the first hovered entity (if any) | // Highlight the first hovered entity (if any) | ||||
var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | ||||
Lint: JSHintBear 'ent' is already defined. Lint: JSHintBear: `'ent' is already defined.` | |||||
if (ent != INVALID_ENTITY) | if (ent != INVALID_ENTITY) | ||||
g_Selection.setHighlightList([ent]); | g_Selection.setHighlightList([ent]); | ||||
else | else | ||||
g_Selection.setHighlightList([]); | g_Selection.setHighlightList([]); | ||||
return false; | return false; | ||||
case "mousebuttondown": | case "mousebuttondown": | ||||
Show All 9 Lines | case "mousebuttondown": | ||||
} | } | ||||
return doAction(action, ev); | return doAction(action, ev); | ||||
} | } | ||||
else if (ev.button == SDL_BUTTON_RIGHT && preSelectedAction != ACTION_NONE) | else if (ev.button == SDL_BUTTON_RIGHT && preSelectedAction != ACTION_NONE) | ||||
{ | { | ||||
preSelectedAction = ACTION_NONE; | preSelectedAction = ACTION_NONE; | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
break; | break; | ||||
} | } | ||||
Lint: JSHintBear Expected a 'break' statement before 'default'. Lint: JSHintBear: `Expected a 'break' statement before 'default'.` | |||||
// else | // else | ||||
default: | default: | ||||
// Slight hack: If selection is empty, reset the input state | // Slight hack: If selection is empty, reset the input state | ||||
if (g_Selection.toList().length == 0) | if (g_Selection.toList().length == 0) | ||||
{ | { | ||||
preSelectedAction = ACTION_NONE; | preSelectedAction = ACTION_NONE; | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case INPUT_SELECTING: | case INPUT_SELECTING: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
// If the mouse moved further than a limit, switch to bandbox mode | // If the mouse moved further than a limit, switch to bandbox mode | ||||
if (g_DragStart.distanceTo(ev) >= g_MaxDragDelta) | if (g_DragStart.distanceTo(ev) >= g_MaxDragDelta) | ||||
{ | { | ||||
inputState = INPUT_BANDBOXING; | inputState = INPUT_BANDBOXING; | ||||
return false; | return false; | ||||
} | } | ||||
var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | var ent = Engine.PickEntityAtPoint(ev.x, ev.y); | ||||
Lint: JSHintBear 'ent' is already defined. Lint: JSHintBear: `'ent' is already defined.` | |||||
if (ent != INVALID_ENTITY) | if (ent != INVALID_ENTITY) | ||||
g_Selection.setHighlightList([ent]); | g_Selection.setHighlightList([ent]); | ||||
else | else | ||||
g_Selection.setHighlightList([]); | g_Selection.setHighlightList([]); | ||||
return false; | return false; | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | case "mousebuttonup": | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case INPUT_UNIT_POSITION_START: | case INPUT_UNIT_POSITION_START: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
// If the mouse moved further than a limit, switch to unit position mode | // If the mouse moved further than a limit, switch to unit position mode | ||||
if (g_DragStart.distanceToSquared(ev) >= Math.square(g_MaxDragDelta)) | if (g_DragStart.distanceToSquared(ev) >= Math.square(g_MaxDragDelta)) | ||||
{ | { | ||||
inputState = INPUT_UNIT_POSITION; | inputState = INPUT_UNIT_POSITION; | ||||
return false; | return false; | ||||
} | } | ||||
break; | break; | ||||
case "mousebuttonup": | case "mousebuttonup": | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
if (ev.button == SDL_BUTTON_RIGHT) | if (ev.button == SDL_BUTTON_RIGHT) | ||||
{ | { | ||||
let action = determineAction(ev.x, ev.y); | let action = determineAction(ev.x, ev.y); | ||||
Lint: ESLintBear (no-shadow) 'action' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'action' is already declared in the upper scope.` | |||||
if (action) | if (action) | ||||
return doAction(action, ev); | return doAction(action, ev); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case INPUT_BUILDING_PLACEMENT: | case INPUT_BUILDING_PLACEMENT: | ||||
switch (ev.type) | switch (ev.type) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "mousemotion": | case "mousemotion": | ||||
placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | ||||
if (placementSupport.mode === "wall") | if (placementSupport.mode === "wall") | ||||
{ | { | ||||
// Including only the on-screen towers in the next snap candidate list is sufficient here, since the user is | // 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 | // 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). | // itself happens in the call to updateBuildingPlacementPreview below). | ||||
placementSupport.wallSnapEntitiesIncludeOffscreen = false; | placementSupport.wallSnapEntitiesIncludeOffscreen = false; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// cancel if not enough resources | // cancel if not enough resources | ||||
if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) | if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) | ||||
{ | { | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
"snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | "snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | ||||
placementSupport.position.x, placementSupport.position.z) | placementSupport.position.x, placementSupport.position.z) | ||||
}); | }); | ||||
Lint: ESLintBear (no-mixed-spaces-and-tabs) Mixed spaces and tabs. Lint: ESLintBear (no-mixed-spaces-and-tabs): `Mixed spaces and tabs.` | |||||
if (snapData) | if (snapData) | ||||
{ | { | ||||
placementSupport.angle = snapData.angle; | placementSupport.angle = snapData.angle; | ||||
placementSupport.position.x = snapData.x; | placementSupport.position.x = snapData.x; | ||||
placementSupport.position.z = snapData.z; | placementSupport.position.z = snapData.z; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | case "mousebuttondown": | ||||
return true; | return true; | ||||
} | } | ||||
break; | break; | ||||
case "hotkeydown": | case "hotkeydown": | ||||
var rotation_step = Math.PI / 12; // 24 clicks make a full rotation | var rotation_step = Math.PI / 12; // 24 clicks make a full rotation | ||||
switch (ev.hotkey) | switch (ev.hotkey) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "session.rotate.cw": | case "session.rotate.cw": | ||||
placementSupport.angle += rotation_step; | placementSupport.angle += rotation_step; | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
break; | break; | ||||
case "session.rotate.ccw": | case "session.rotate.ccw": | ||||
placementSupport.angle -= rotation_step; | placementSupport.angle -= rotation_step; | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
▲ Show 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | Engine.PostNetworkCommand({ | ||||
"entities": appropriateBuildings, | "entities": appropriateBuildings, | ||||
"template": g_BatchTrainingType, | "template": g_BatchTrainingType, | ||||
"count": batchedSize | "count": batchedSize | ||||
}); | }); | ||||
} | } | ||||
function performGroup(action, groupId) | function performGroup(action, groupId) | ||||
{ | { | ||||
switch (action) | switch (action) | ||||
Lint: ESLintBear (default-case) Expected a default case. Lint: ESLintBear (default-case): `Expected a default case.` | |||||
{ | { | ||||
case "snap": | case "snap": | ||||
case "select": | case "select": | ||||
case "add": | case "add": | ||||
var toSelect = []; | var toSelect = []; | ||||
g_Groups.update(); | g_Groups.update(); | ||||
for (var ent in g_Groups.groups[groupId].ents) | for (var ent in g_Groups.groups[groupId].ents) | ||||
toSelect.push(+ent); | toSelect.push(+ent); | ||||
Show All 35 Lines | |||||
} | } | ||||
function findIdleUnit(classes) | function findIdleUnit(classes) | ||||
{ | { | ||||
var append = Engine.HotkeyIsPressed("selection.add"); | var append = Engine.HotkeyIsPressed("selection.add"); | ||||
var selectall = Engine.HotkeyIsPressed("selection.offscreen"); | var selectall = Engine.HotkeyIsPressed("selection.offscreen"); | ||||
// Reset the last idle unit, etc., if the selection type has changed. | // 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])) | if (selectall || classes.length != lastIdleClasses.length || !classes.every((v,i) => v === lastIdleClasses[i])) | ||||
Lint: ESLintBear (comma-spacing) A space is required after ','. Lint: ESLintBear (comma-spacing): `A space is required after ','.` | |||||
resetIdleUnit(); | resetIdleUnit(); | ||||
lastIdleClasses = classes; | lastIdleClasses = classes; | ||||
var data = { | var data = { | ||||
"viewedPlayer": g_ViewedPlayer, | "viewedPlayer": g_ViewedPlayer, | ||||
"excludeUnits": append ? g_Selection.toList() : [], | "excludeUnits": append ? g_Selection.toList() : [], | ||||
// If the current idle class index is not 0, put the class at that index first. | // If the current idle class index is not 0, put the class at that index first. | ||||
"idleClasses": classes.slice(currIdleClassIndex, classes.length).concat(classes.slice(0, currIdleClassIndex)) | "idleClasses": classes.slice(currIdleClassIndex, classes.length).concat(classes.slice(0, currIdleClassIndex)) | ||||
}; | }; | ||||
if (!selectall) | if (!selectall) | ||||
{ | { | ||||
data.limit = 1; | data.limit = 1; | ||||
data.prevUnit = lastIdleUnit; | data.prevUnit = lastIdleUnit; | ||||
} | } | ||||
var idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", data); | var idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", data); | ||||
if (!idleUnits.length) | if (!idleUnits.length) | ||||
{ | { | ||||
// TODO: display a message or play a sound to indicate no more idle units, or something | // TODO: display a message to indicate no more idle units, or something | ||||
// Reset for next cycle | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "no_idle_unit", | |||||
"entity": g_ViewedPlayer | |||||
}); | |||||
resetIdleUnit(); | resetIdleUnit(); | ||||
return; | return; | ||||
} | } | ||||
if (!append) | if (!append) | ||||
g_Selection.reset(); | g_Selection.reset(); | ||||
g_Selection.addList(idleUnits); | g_Selection.addList(idleUnits); | ||||
Show All 25 Lines |
It's not necessary to initialize 'actionInfo' to undefined.