Changeset View
Standalone View
binaries/data/mods/public/gui/session/selection.js
Show First 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | EntitySelection.prototype.addList = function(ents, quiet, force = false) | ||||
// If someone else's player is the sole selected unit, don't allow adding to the selection | // If someone else's player is the sole selected unit, don't allow adding to the selection | ||||
let firstEntState = selection.length == 1 && GetEntityState(selection[0]); | let firstEntState = selection.length == 1 && GetEntityState(selection[0]); | ||||
if (firstEntState && firstEntState.player != g_ViewedPlayer && !force) | if (firstEntState && firstEntState.player != g_ViewedPlayer && !force) | ||||
return; | return; | ||||
let i = 1; | let i = 1; | ||||
let added = []; | let added = []; | ||||
ents = this.addBattalionMembers(ents); | |||||
Stan: It seems a bit dirty to overwrite the function param. | |||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
if (selection.length + i > g_MaxSelectionSize) | if (selection.length + i > g_MaxSelectionSize) | ||||
break; | break; | ||||
if (this.selected[ent]) | if (this.selected[ent]) | ||||
continue; | continue; | ||||
Show All 26 Lines | EntitySelection.prototype.addList = function(ents, quiet, force = false) | ||||
} | } | ||||
this.groups.add(this.toList()); // Create Selection Groups | this.groups.add(this.toList()); // Create Selection Groups | ||||
this.onChange(); | this.onChange(); | ||||
}; | }; | ||||
EntitySelection.prototype.removeList = function(ents) | EntitySelection.prototype.removeList = function(ents) | ||||
{ | { | ||||
var removed = []; | var removed = []; | ||||
ents = this.addBattalionMembers(ents); | |||||
Done Inline ActionsI'd name the argument 'treatFormationsAsOne' or something like that. You can leave the explanation for the orderOne case. wraitii: I'd name the argument 'treatFormationsAsOne' or something like that. You can leave the… | |||||
Done Inline ActionsYeah I meant to ask for that too, because it might be confused with the orderone feature [ALT] keyword. Stan: Yeah I meant to ask for that too, because it might be confused with the orderone feature [ALT]… | |||||
for (let ent of ents) | for (let ent of ents) | ||||
if (this.selected[ent]) | if (this.selected[ent]) | ||||
{ | { | ||||
this.groups.removeEnt(ent); | this.groups.removeEnt(ent); | ||||
removed.push(ent); | removed.push(ent); | ||||
delete this.selected[ent]; | delete this.selected[ent]; | ||||
} | } | ||||
Show All 39 Lines | EntitySelection.prototype.toList = function() | ||||
let ents = []; | let ents = []; | ||||
for (let ent in this.selected) | for (let ent in this.selected) | ||||
ents.push(+ent); | ents.push(+ent); | ||||
return ents; | return ents; | ||||
}; | }; | ||||
EntitySelection.prototype.setHighlightList = function(ents) | EntitySelection.prototype.setHighlightList = function(ents) | ||||
{ | { | ||||
var highlighted = {}; | var highlighted = {}; | ||||
Done Inline ActionsForgot this one :) Stan: Forgot this one :) | |||||
Done Inline ActionsNot really, ents is used twice here in this function. ;) Freagarach: Not really, `ents` is used twice here in this function. ;) | |||||
ents = this.addBattalionMembers(ents); | |||||
for (let ent of ents) | for (let ent of ents) | ||||
highlighted[ent] = ent; | highlighted[ent] = ent; | ||||
var removed = []; | var removed = []; | ||||
var added = []; | var added = []; | ||||
// Remove highlighting for the old units that are no longer highlighted | // Remove highlighting for the old units that are no longer highlighted | ||||
// (excluding ones that are actively selected too) | // (excluding ones that are actively selected too) | ||||
Show All 25 Lines | |||||
EntitySelection.prototype.onChange = function() | EntitySelection.prototype.onChange = function() | ||||
{ | { | ||||
this.dirty = true; | this.dirty = true; | ||||
if (this.isSelection) | if (this.isSelection) | ||||
onSelectionChange(); | onSelectionChange(); | ||||
}; | }; | ||||
/** | /** | ||||
* Adds the battalion members of a selected entities to the selection. | |||||
* @param {number[]} entities - The entity IDs of selected entities. | |||||
* @return {number[]} - Some more entity IDs if part of a battalion was selected. | |||||
*/ | |||||
EntitySelection.prototype.addBattalionMembers = function(entities) | |||||
{ | |||||
if (entities.length) | |||||
Done Inline ActionsMove below conditions Silier: Move below conditions | |||||
Done Inline ActionsCan entities be null? Should we check for it? Stan: Can entities be null? Should we check for it? | |||||
Done Inline ActionsThe rest doesn't check either, so I don't think we should check for it. (This errors out nicely when called with nullish value.) Freagarach: The rest doesn't check either, so I don't think we should check for it. (This errors out nicely… | |||||
{ | |||||
let battalions = Engine.GuiInterfaceCall("GetBattalions", { "players": undefined }); | |||||
Done Inline ActionsDo you really need that check ? Stan: Do you really need that check ? | |||||
Done Inline ActionsNot sure, I'll test. I thought it might save some performance perhaps, when not selecting a grouped entity. Freagarach: Not sure, I'll test. I thought it might save some performance perhaps, when not selecting a… | |||||
Done Inline ActionsApparently we do, otherwise hovering doesn't work. Freagarach: Apparently we do, otherwise hovering doesn't work. | |||||
Done Inline ActionsYou could inline here Silier: You could inline here | |||||
for (let battalion of battalions) | |||||
Done Inline ActionsI wonder if you couldn't save some cycles by filtering then checking the length and if more than 0 assign ? Would avoid the some. Stan: I wonder if you couldn't save some cycles by filtering then checking the length and if more… | |||||
Done Inline ActionsIt is again hovering that holds this off. Not sure why though,,, Freagarach: It is again hovering that holds this off. Not sure why though,,, | |||||
if (entities.some(entity => battalion.entities.indexOf(entity) != -1)) | |||||
entities = entities.concat(battalion.entities.filter(entity => entities.indexOf(entity) == -1)); | |||||
} | |||||
return entities; | |||||
Done Inline ActionsI measured somewhere that concat was really slow and that it's better to have a for loop with .push, but not sure it's worth the hassle. Stan: I measured somewhere that concat was really slow and that it's better to have a for loop with . | |||||
Done Inline ActionsAh, since this is called often in a large selection, it might indeed be worth the hassle. It may even be worth using a Set. Freagarach: Ah, since this is called often in a large selection, it might indeed be worth the hassle. It… | |||||
}; | |||||
/** | |||||
* Cache some quantities which depends only on selection | * Cache some quantities which depends only on selection | ||||
*/ | */ | ||||
var g_Selection = new EntitySelection(); | var g_Selection = new EntitySelection(); | ||||
g_Selection.isSelection = true; | g_Selection.isSelection = true; | ||||
var g_canMoveIntoFormation = {}; | var g_canMoveIntoFormation = {}; | ||||
var g_allBuildableEntities; | var g_allBuildableEntities; | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
It seems a bit dirty to overwrite the function param.