Changeset View
Changeset View
Standalone 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() | ||||
{ | { | ||||
let cursorSet = false; | let cursorSet = false; | ||||
▲ Show 20 Lines • Show All 108 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(); | |||||
Done Inline ActionsWhat does the r mean? vladislavbelov: What does the `r` mean? | |||||
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; | ||||
} | } | ||||
let entState = GetEntityState(selection[0]); | let entState = GetEntityState(selection[0]); | ||||
Show All 17 Lines | function determineAction(x, y, fromMiniMap) | ||||
// 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. | ||||
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) | ||||
▲ Show 20 Lines • Show All 971 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.PlayUISound("audio/interface/alarm/alarmally_1.ogg", false); | |||||
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. | |||||
Engine.PostNetworkCommand({ | |||||
"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 416 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
What's the default value for the variable?