Changeset View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 1,124 Lines • ▼ Show 20 Lines | function handleInputAfterGui(ev) | ||||
return false; | return false; | ||||
} | } | ||||
function doAction(action, ev) | function doAction(action, ev) | ||||
{ | { | ||||
if (!controlsPlayer(g_ViewedPlayer)) | if (!controlsPlayer(g_ViewedPlayer)) | ||||
return false; | return false; | ||||
// If shift is down, add the order to the unit's order queue instead | return handleUnitAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y), action); | ||||
Stan: can be inlined :) | |||||
Done Inline Actionsyou mean like... ? < return handleUnitsActions(Engine.GetTerrainAtScreenPoint(ev.x, ev.y), action); --- > const target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); > return handleUnitsActions(target, action); luiko: you mean like... ?
```
< return handleUnitsActions(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)… | |||||
Done Inline ActionsYes :) Stan: Yes :) | |||||
// of running it immediately | |||||
var orderone = Engine.HotkeyIsPressed("session.orderone"); | |||||
var queued = Engine.HotkeyIsPressed("session.queue"); | |||||
var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | |||||
if (g_UnitActions[action.type] && g_UnitActions[action.type].execute) | |||||
{ | |||||
let selection = g_Selection.toList(); | |||||
if (orderone) | |||||
{ | |||||
// pick the first unit that can do this order. | |||||
let unit = selection.find(entity => | |||||
["preSelectedActionCheck", "hotkeyActionCheck", "actionCheck"].some(method => | |||||
g_UnitActions[action.type][method] && | |||||
g_UnitActions[action.type][method](action.target || undefined, [entity]) | |||||
)); | |||||
if (unit) | |||||
{ | |||||
selection = [unit]; | |||||
g_Selection.removeList(selection); | |||||
} | |||||
} | |||||
return g_UnitActions[action.type].execute(target, action, selection, queued); | |||||
} | } | ||||
error("Invalid action.type " + action.type); | |||||
return false; | |||||
} | |||||
function positionUnitsFreehandSelectionMouseMove(ev) | function positionUnitsFreehandSelectionMouseMove(ev) | ||||
{ | { | ||||
// Converting the input line into a List of points. | // Converting the input line into a List of points. | ||||
// For better performance the points must have a minimum distance to each other. | // For better performance the points must have a minimum distance to each other. | ||||
let target = Vector2D.from3D(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | let target = Vector2D.from3D(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | ||||
if (!g_FreehandSelection_InputLine.length || | if (!g_FreehandSelection_InputLine.length || | ||||
target.distanceToSquared(g_FreehandSelection_InputLine[g_FreehandSelection_InputLine.length - 1]) >= | target.distanceToSquared(g_FreehandSelection_InputLine[g_FreehandSelection_InputLine.length - 1]) >= | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
function handleMinimapEvent(target) | function handleMinimapEvent(target) | ||||
{ | { | ||||
// Partly duplicated from handleInputAfterGui(), but with the input being | // Partly duplicated from handleInputAfterGui(), but with the input being | ||||
// world coordinates instead of screen coordinates. | // world coordinates instead of screen coordinates. | ||||
if (inputState != INPUT_NORMAL) | if (inputState != INPUT_NORMAL) | ||||
return false; | return false; | ||||
var fromMinimap = true; | let action = determineAction(undefined, undefined, true); | ||||
Done Inline Actionsthis can go inline Silier: this can go inline | |||||
Done Inline Actionsuse let here please Silier: use let here please | |||||
var action = determineAction(undefined, undefined, fromMinimap); | |||||
if (!action) | if (!action) | ||||
return false; | return false; | ||||
var selection = g_Selection.toList(); | return handleUnitAction(target, action); | ||||
} | |||||
var queued = Engine.HotkeyIsPressed("session.queue"); | function handleUnitAction(target, action) | ||||
if (g_UnitActions[action.type] && g_UnitActions[action.type].execute) | { | ||||
return g_UnitActions[action.type].execute(target, action, selection, queued); | // If shift is down, add the order to the unit's order queue instead | ||||
Not Done Inline ActionsI'm not sure that comment is still accurate since now the order one can be any key you want. Also I think it's ALT but I'm not sure one would have to check the wiki Hotkeys patch. Stan: I'm not sure that comment is still accurate since now the order one can be any key you want. | |||||
Not Done Inline Actionsit is shift to queue orderds :) Silier: it is shift to queue orderds :) | |||||
// of running it immediately | |||||
const orderone = Engine.HotkeyIsPressed("session.orderone"); | |||||
Not Done Inline ActionsI don't recall any convention on consts inside function. We seem to be using let everywhere however bb: I don't recall any convention on consts inside function. We seem to be using let everywhere… | |||||
Not Done Inline ActionsIt should, I prefer to use 'const' to specify that this identifier won't be reassigned I think is a plus to keep things simple. luiko: It should, I prefer to use 'const' to specify that this identifier won't be reassigned I think… | |||||
let queued = Engine.HotkeyIsPressed("session.queue"); | |||||
if (!g_UnitActions[action.type] || !g_UnitActions[action.type].execute) | |||||
Done Inline Actions(!(a && b) ) <==> (!a || !b) Not sure which one is more readable. @elexis, shouldn't we check for g_UnitActions && g_UnitActions.length ? Stan: (!(a && b) ) <==> (!a || !b) Not sure which one is more readable.
@elexis, shouldn't we check… | |||||
Done Inline Actionsg_UnitActions is initialised non empty in unit_actions.js so thiese checks would be redundant I think ! a || !b is easier to read Silier: g_UnitActions is initialised non empty in unit_actions.js so thiese checks would be redundant… | |||||
{ | |||||
error("Invalid action.type " + action.type); | error("Invalid action.type " + action.type); | ||||
return false; | return false; | ||||
} | } | ||||
let selection = g_Selection.toList(); | |||||
if (orderone) | |||||
{ | |||||
// Pick the first unit that can do this order. | |||||
const unit = selection.find(entity => | |||||
["preSelectedActionCheck", "hotkeyActionCheck", "actionCheck"].some(method => | |||||
g_UnitActions[action.type][method] && | |||||
g_UnitActions[action.type][method](action.target || undefined, [entity]) | |||||
)); | |||||
if (unit) | |||||
{ | |||||
selection = [unit]; | |||||
g_Selection.removeList(selection); | |||||
} | |||||
} | |||||
return g_UnitActions[action.type].execute(target, action, selection, queued); | |||||
Done Inline ActionsInvert the condition and make this an early return. Stan: Invert the condition and make this an early return. | |||||
Done Inline Actionswe only handle 1 action at at a time and we have g_UnitActions so I propose handleUnitAction bb: we only handle 1 action at at a time and we have `g_UnitActions` so I propose `handleUnitAction` | |||||
} | |||||
Done Inline ActionsCan the code be turned into a function so that comment can be nuked ? Stan: Can the code be turned into a function so that comment can be nuked ? | |||||
Done Inline ActionsI thought about that, but I want to show this simpler, I would like do that too. luiko: I thought about that, but I want to show this simpler, I would like do that too. | |||||
function getEntityLimitAndCount(playerState, entType) | function getEntityLimitAndCount(playerState, entType) | ||||
{ | { | ||||
let ret = { | let ret = { | ||||
Done Inline ActionsComment start with caps :) Stan: Comment start with caps :) | |||||
"entLimit": undefined, | "entLimit": undefined, | ||||
"entCount": undefined, | "entCount": undefined, | ||||
"entLimitChangers": undefined, | "entLimitChangers": undefined, | ||||
"canBeAddedCount": undefined | "canBeAddedCount": undefined | ||||
}; | }; | ||||
if (!playerState.entityLimits) | if (!playerState.entityLimits) | ||||
return ret; | return ret; | ||||
let template = GetTemplateData(entType); | let template = GetTemplateData(entType); | ||||
▲ Show 20 Lines • Show All 371 Lines • Show Last 20 Lines |
can be inlined :)