Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 1,636 Lines • ▼ Show 20 Lines | case "breakUp": | ||||||||||||
if (action == "save") | if (action == "save") | ||||||||||||
g_Groups.addEntities(groupId, g_Selection.toList()); | g_Groups.addEntities(groupId, g_Selection.toList()); | ||||||||||||
updateGroups(); | updateGroups(); | ||||||||||||
break; | break; | ||||||||||||
} | } | ||||||||||||
} | } | ||||||||||||
var lastIdleUnit = 0; | var lastIdleUnit = INVALID_ENTITY; | ||||||||||||
var currIdleClassIndex = 0; | |||||||||||||
var lastIdleClasses = []; | var lastIdleClasses = []; | ||||||||||||
function resetIdleUnit() | function resetIdleUnit() | ||||||||||||
{ | { | ||||||||||||
lastIdleUnit = 0; | lastIdleUnit = INVALID_ENTITY; | ||||||||||||
currIdleClassIndex = 0; | |||||||||||||
lastIdleClasses = []; | lastIdleClasses = []; | ||||||||||||
} | } | ||||||||||||
function findIdleUnit(classes) | function findIdleUnit(classes) | ||||||||||||
{ | { | ||||||||||||
let append = Engine.HotkeyIsPressed("selection.add"); | let append = Engine.HotkeyIsPressed("selection.add"); | ||||||||||||
let selectall = Engine.HotkeyIsPressed("selection.offscreen"); | let 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])) | ||||||||||||
resetIdleUnit(); | resetIdleUnit(); | ||||||||||||
lastIdleClasses = classes; | lastIdleClasses = classes; | ||||||||||||
let data = { | let idleUnits = Engine.GuiInterfaceCall("IdleUnitsByClass", { | ||||||||||||
Freagarach: Why would one use such a construction? Just the call should return an array? | |||||||||||||
"viewedPlayer": g_ViewedPlayer, | "viewedPlayer": g_ViewedPlayer, | ||||||||||||
"excludeUnits": append ? g_Selection.toList() : [], | "idleClasses": classes | ||||||||||||
// 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)) | if(append) | ||||||||||||
SilierUnsubmitted Not Done Inline Actions
Silier: | |||||||||||||
}; | idleUnits = idleUnits.filter(e => !g_Selection.selected.has(e)); | ||||||||||||
SilierUnsubmitted Not Done Inline Actions
it does not matter, but it reads better Silier: it does not matter, but it reads better | |||||||||||||
if (!selectall) | |||||||||||||
{ | |||||||||||||
data.limit = 1; | |||||||||||||
data.prevUnit = lastIdleUnit; | |||||||||||||
} | |||||||||||||
let idleUnits = Engine.GuiInterfaceCall("FindIdleUnits", data); | |||||||||||||
if (!idleUnits.length) | if (!idleUnits.length) | ||||||||||||
{ | { | ||||||||||||
// TODO: display a message to indicate no more idle units, or something | // TODO: display a message to indicate no more idle units, or something | ||||||||||||
Engine.GuiInterfaceCall("PlaySoundForPlayer", { | Engine.GuiInterfaceCall("PlaySoundForPlayer", { | ||||||||||||
"name": "no_idle_unit" | "name": "no_idle_unit" | ||||||||||||
}); | }); | ||||||||||||
resetIdleUnit(); | resetIdleUnit(); | ||||||||||||
return; | return; | ||||||||||||
} | } | ||||||||||||
if (!append) | if (!append) | ||||||||||||
g_Selection.reset(); | g_Selection.reset(); | ||||||||||||
g_Selection.addList(idleUnits); | |||||||||||||
if (selectall) | if (selectall) | ||||||||||||
{ | |||||||||||||
g_Selection.addList(idleUnits); | |||||||||||||
return; | return; | ||||||||||||
} | |||||||||||||
lastIdleUnit = idleUnits[0]; | const nextIdleUnitIndex = idleUnits.indexOf(lastIdleUnit) + 1; | ||||||||||||
Not Done Inline ActionsOne may want to just check whether we're at the end instead of doing the %, I'm not sure how heavy on the resources that is for many calls. Freagarach: One may want to just check whether we're at the end instead of doing the `%`, I'm not sure how… | |||||||||||||
let entityState = GetEntityState(lastIdleUnit); | const idleUnit = idleUnits[nextIdleUnitIndex == idleUnits.length ? 0 : nextIdleUnitIndex]; | ||||||||||||
g_Selection.addList([idleUnit]); | |||||||||||||
lastIdleUnit = idleUnit; | |||||||||||||
FreagarachUnsubmitted Not Done Inline Actions
? Freagarach: ? | |||||||||||||
const entityState = GetEntityState(idleUnit); | |||||||||||||
if (entityState.position) | if (entityState.position) | ||||||||||||
Engine.CameraMoveTo(entityState.position.x, entityState.position.z); | Engine.CameraMoveTo(entityState.position.x, entityState.position.z); | ||||||||||||
// Move the idle class index to the first class an idle unit was found for. | |||||||||||||
let indexChange = data.idleClasses.findIndex(elem => MatchesClassList(entityState.identity.classes, elem)); | |||||||||||||
currIdleClassIndex = (currIdleClassIndex + indexChange) % classes.length; | |||||||||||||
} | } | ||||||||||||
function clearSelection() | function clearSelection() | ||||||||||||
{ | { | ||||||||||||
if (inputState==INPUT_BUILDING_PLACEMENT || inputState==INPUT_BUILDING_WALL_PATHING) | if (inputState==INPUT_BUILDING_PLACEMENT || inputState==INPUT_BUILDING_WALL_PATHING) | ||||||||||||
{ | { | ||||||||||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||||||||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||||||||||
} | } | ||||||||||||
else | else | ||||||||||||
g_Selection.reset(); | g_Selection.reset(); | ||||||||||||
preSelectedAction = ACTION_NONE; | preSelectedAction = ACTION_NONE; | ||||||||||||
} | } |
Wildfire Games · Phabricator
Why would one use such a construction? Just the call should return an array?