Changeset View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show All 11 Lines | |||||
// TODO: these constants should be defined somewhere else instead, in | // TODO: these constants should be defined somewhere else instead, in | ||||
// case any other code wants to use them too | // case any other code wants to use them too | ||||
const ACTION_NONE = 0; | const ACTION_NONE = 0; | ||||
const ACTION_GARRISON = 1; | const ACTION_GARRISON = 1; | ||||
const ACTION_REPAIR = 2; | const ACTION_REPAIR = 2; | ||||
const ACTION_GUARD = 3; | const ACTION_GUARD = 3; | ||||
const ACTION_PATROL = 4; | const ACTION_PATROL = 4; | ||||
const ACTION_FLARE = 5; | |||||
var preSelectedAction = ACTION_NONE; | var preSelectedAction = ACTION_NONE; | ||||
const INPUT_NORMAL = 0; | const INPUT_NORMAL = 0; | ||||
const INPUT_SELECTING = 1; | const INPUT_SELECTING = 1; | ||||
const INPUT_BANDBOXING = 2; | const INPUT_BANDBOXING = 2; | ||||
const INPUT_BUILDING_PLACEMENT = 3; | const INPUT_BUILDING_PLACEMENT = 3; | ||||
const INPUT_BUILDING_CLICK = 4; | const INPUT_BUILDING_CLICK = 4; | ||||
const INPUT_BUILDING_DRAG = 5; | const INPUT_BUILDING_DRAG = 5; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Store the clicked entity on mousedown or mouseup for single/double/triple clicks to select entities. | * Store the clicked entity on mousedown or mouseup for single/double/triple clicks to select entities. | ||||
* If any mousedown or mouseup of a sequence of clicks lands on a unit, | * If any mousedown or mouseup of a sequence of clicks lands on a unit, | ||||
* that unit will be selected, which makes it easier to click on moving units. | * that unit will be selected, which makes it easier to click on moving units. | ||||
*/ | */ | ||||
var clickedEntity = INVALID_ENTITY; | var clickedEntity = INVALID_ENTITY; | ||||
/** | |||||
* Store the last time the flare functionality was used to prevent overusage. | |||||
*/ | |||||
var g_LastFlareTime; | |||||
vladislavbelov: What's the default value for the variable? | |||||
Done Inline ActionsDefault is undefined. Just like g_DragStartfor example. Imarok: Default is undefined. Just like `g_DragStart`for example.
For how I use this variable look at… | |||||
/** | |||||
* The duration in ms for which we disable flaring after each flare to prevent overusage. | |||||
*/ | |||||
const g_FlareCooldown = 1000; | |||||
// Same double-click behaviour for hotkey presses | // Same double-click behaviour for hotkey presses | ||||
const doublePressTime = 500; | const doublePressTime = 500; | ||||
var doublePressTimer = 0; | var doublePressTimer = 0; | ||||
var prevHotkey = 0; | var prevHotkey = 0; | ||||
function updateCursorAndTooltip() | function updateCursorAndTooltip() | ||||
{ | { | ||||
var cursorSet = false; | var cursorSet = false; | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | function updateBuildingPlacementPreview() | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Determine the context-sensitive action that should be performed when the mouse is at (x,y) | * Determine the context-sensitive action that should be performed when the mouse is at (x,y) | ||||
*/ | */ | ||||
function determineAction(x, y, fromMiniMap) | function determineAction(x, y, fromMiniMap) | ||||
{ | { | ||||
let r = g_MiniMapPanel.preSelectedActionCheck() || g_MiniMapPanel.hotkeyActionCheck(); | |||||
vladislavbelovUnsubmitted Done Inline ActionsWhat does the r mean? vladislavbelov: What does the `r` mean? | |||||
ImarokAuthorUnsubmitted Done Inline ActionsI guess it just means result or return. Imarok: I guess it just means result or return.
It's already used multiple times across `input.js`. | |||||
if (r) | |||||
return r; | |||||
let selection = g_Selection.toList(); | let selection = g_Selection.toList(); | ||||
if (!selection.length) | if (!selection.length) | ||||
{ | { | ||||
preSelectedAction = ACTION_NONE; | preSelectedAction = ACTION_NONE; | ||||
return undefined; | return undefined; | ||||
} | } | ||||
// If the selection doesn't exist, no action. | // If the selection doesn't exist, no action. | ||||
Show All 14 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: JSHintBear It's not necessary to initialize 'actionInfo' to 'undefined'. Lint: JSHintBear: `It's not necessary to initialize 'actionInfo' to 'undefined'.` | |||||
Lint: ESLintBear (no-undef-init) It's not necessary to initialize 'actionInfo' to undefined. Lint: ESLintBear (no-undef-init): `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); | r = g_UnitActions[action].preSelectedActionCheck(target, selection); | ||||
if (r) | if (r) | ||||
return r; | return r; | ||||
} | } | ||||
return { "type": "none", "cursor": "", "target": target }; | return { "type": "none", "cursor": "", "target": target }; | ||||
} | } | ||||
for (let action of g_UnitActionsSortedKeys) | for (let action of g_UnitActionsSortedKeys) | ||||
if (g_UnitActions[action].hotkeyActionCheck) | if (g_UnitActions[action].hotkeyActionCheck) | ||||
{ | { | ||||
let r = g_UnitActions[action].hotkeyActionCheck(target, selection); | let r = g_UnitActions[action].hotkeyActionCheck(target, selection); | ||||
Lint: ESLintBear (no-shadow) 'r' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'r' is already declared in the upper scope.` | |||||
if (r) | if (r) | ||||
return r; | return r; | ||||
} | } | ||||
for (let action of g_UnitActionsSortedKeys) | for (let action of g_UnitActionsSortedKeys) | ||||
if (g_UnitActions[action].actionCheck) | if (g_UnitActions[action].actionCheck) | ||||
{ | { | ||||
let r = g_UnitActions[action].actionCheck(target, selection); | let r = g_UnitActions[action].actionCheck(target, selection); | ||||
Lint: ESLintBear (no-shadow) 'r' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'r' is already declared in the upper scope.` | |||||
if (r) | if (r) | ||||
return r; | return r; | ||||
} | } | ||||
return { "type": "none", "cursor": "", "target": target }; | return { "type": "none", "cursor": "", "target": target }; | ||||
} | } | ||||
function ownsEntity(ent) | function ownsEntity(ent) | ||||
▲ Show 20 Lines • Show All 194 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: JSHintBear 'sptr' is already defined. Lint: JSHintBear: `'sptr' is already defined.` | |||||
Lint: ESLintBear (indent) Expected indentation of 5 tabs but found 6. Lint: ESLintBear (indent): `Expected indentation of 5 tabs but found 6.` | |||||
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 111 Lines • ▼ Show 20 Lines | Engine.GuiInterfaceCall("PlaySound", { | ||||
"entity": selection[0] | "entity": selection[0] | ||||
}); | }); | ||||
return true; | return true; | ||||
} | } | ||||
function handleUnitAction(target, action) | function handleUnitAction(target, action) | ||||
{ | { | ||||
if (action.type == "flare") | |||||
{ | |||||
let now = Date.now(); | |||||
Done Inline Actionsone scope { } per case and let, so that the variable of one case can't be used in the other case, and one is free to use the same variable name in each case without any worries elexis: one scope { } per case and let, so that the variable of one case can't be used in the other… | |||||
if (g_LastFlareTime && now < g_LastFlareTime + g_FlareCooldown) | |||||
return false; | |||||
g_LastFlareTime = now; | |||||
displayFlare(target, Engine.GetPlayerID()); | |||||
Engine.PostNetworkCommand({ | |||||
Done Inline ActionsNo chance to make that a constant you can reuse? Stan: No chance to make that a constant you can reuse? | |||||
Done Inline Actionsgood point. Imarok: good point. | |||||
"type": "map-flare", | |||||
"target": target | |||||
}); | |||||
return true; | |||||
} | |||||
if (!g_UnitActions[action.type] || !g_UnitActions[action.type].execute) | if (!g_UnitActions[action.type] || !g_UnitActions[action.type].execute) | ||||
{ | { | ||||
error("Invalid action.type " + action.type); | error("Invalid action.type " + action.type); | ||||
return false; | return false; | ||||
} | } | ||||
let selection = Engine.HotkeyIsPressed("session.orderone") && | let selection = Engine.HotkeyIsPressed("session.orderone") && | ||||
popOneFromSelection(action) || g_Selection.toList(); | popOneFromSelection(action) || g_Selection.toList(); | ||||
▲ Show 20 Lines • Show All 287 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)) | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
What's the default value for the variable?