Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/selection.js
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | EntityGroups.prototype.reset = function() | ||||
this.groups = {}; | this.groups = {}; | ||||
this.ents = {}; | this.ents = {}; | ||||
}; | }; | ||||
EntityGroups.prototype.add = function(ents) | EntityGroups.prototype.add = function(ents) | ||||
{ | { | ||||
for (let ent of ents) | for (let ent of ents) | ||||
{ | { | ||||
if (!this.ents[ent]) | if (!this.ents[ent]) | ||||
mimo: not necessary for the patch, but as you modify this function, we could have "if (this.ents… | |||||
{ | { | ||||
var entState = GetEntityState(ent); | var entState = GetEntityState(ent); | ||||
// When this function is called during group rebuild, deleted | // When this function is called during group rebuild, deleted | ||||
// entities will not yet have been removed, so entities might | // entities will not yet have been removed, so entities might | ||||
// still be present in the group despite not existing. | // still be present in the group despite not existing. | ||||
if (!entState) | if (!entState) | ||||
continue; | continue; | ||||
var templateName = entState.template; | var templateName = entState.template; | ||||
var key = GetTemplateData(templateName).selectionGroupName || templateName; | var key = GetTemplateData(templateName).selectionGroupName || templateName; | ||||
// TODO ugly hack, just group them by player too. | // Group the ents by player and template | ||||
// Prefix garrisoned unit's selection name with the player they belong to | if (entState.player !== undefined) | ||||
var index = templateName.indexOf("&"); | key = "p" + entState.player + "&" + entState.template; | ||||
mimoUnsubmitted Not Done Inline Actionsshouldn't it be key = "p" + ... + "&" + key; as we want to keep the selectionGroupName if any (so that basic, advanced and elite are grouped together). mimo: shouldn't it be key = "p" + ... + "&" + key; as we want to keep the selectionGroupName if any… | |||||
ImarokAuthorUnsubmitted Not Done Inline ActionsTrue. I wanted to do that, but seems like I didn't ^^ Imarok: True. I wanted to do that, but seems like I didn't ^^ | |||||
if (index != -1 && key.indexOf("&") == -1) | |||||
key = templateName.slice(0, index+1) + key; | |||||
if (this.groups[key]) | if (this.groups[key]) | ||||
this.groups[key] += 1; | this.groups[key] += 1; | ||||
else | else | ||||
this.groups[key] = 1; | this.groups[key] = 1; | ||||
this.ents[ent] = key; | this.ents[ent] = key; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
EntityGroups.prototype.removeEnt = function(ent) | EntityGroups.prototype.removeEnt = function(ent) | ||||
{ | { | ||||
var templateName = this.ents[ent]; | var key = this.ents[ent]; | ||||
// Remove the entity | // Remove the entity | ||||
delete this.ents[ent]; | delete this.ents[ent]; | ||||
--this.groups[templateName]; | --this.groups[key]; | ||||
// Remove the entire group | // Remove the entire group | ||||
if (this.groups[templateName] == 0) | if (this.groups[key] == 0) | ||||
delete this.groups[templateName]; | delete this.groups[key]; | ||||
}; | }; | ||||
EntityGroups.prototype.rebuildGroup = function(renamed) | EntityGroups.prototype.rebuildGroup = function(renamed) | ||||
{ | { | ||||
var oldGroup = this.ents; | var oldGroup = this.ents; | ||||
this.reset(); | this.reset(); | ||||
var toAdd = []; | var toAdd = []; | ||||
for (var ent in oldGroup) | for (var ent in oldGroup) | ||||
toAdd.push(renamed[ent] ? renamed[ent] : +ent); | toAdd.push(renamed[ent] ? renamed[ent] : +ent); | ||||
this.add(toAdd); | this.add(toAdd); | ||||
}; | }; | ||||
EntityGroups.prototype.getCount = function(templateName) | EntityGroups.prototype.getCount = function(key) | ||||
{ | { | ||||
return this.groups[templateName]; | return this.groups[key]; | ||||
}; | }; | ||||
EntityGroups.prototype.getTotalCount = function() | EntityGroups.prototype.getTotalCount = function() | ||||
{ | { | ||||
let totalCount = 0; | let totalCount = 0; | ||||
for (let templateName in this.groups) | for (let key in this.groups) | ||||
totalCount += this.groups[templateName]; | totalCount += this.groups[key]; | ||||
return totalCount; | return totalCount; | ||||
}; | }; | ||||
EntityGroups.prototype.getTemplateNames = function() | EntityGroups.prototype.getKeys = function() | ||||
{ | { | ||||
//Preserve order even when shuffling units around | //Preserve order even when shuffling units around | ||||
//Can be optimized by moving the sorting elsewhere | //Can be optimized by moving the sorting elsewhere | ||||
return Object.keys(this.groups).sort(); | return Object.keys(this.groups).sort(); | ||||
}; | }; | ||||
EntityGroups.prototype.getEntsByName = function(templateName) | EntityGroups.prototype.getEntsByKey = function(key) | ||||
{ | { | ||||
var ents = []; | var ents = []; | ||||
for (var ent in this.ents) | for (var ent in this.ents) | ||||
if (this.ents[ent] == templateName) | if (this.ents[ent] == key) | ||||
ents.push(+ent); | ents.push(+ent); | ||||
return ents; | return ents; | ||||
}; | }; | ||||
/** | /** | ||||
* get a list of entities grouped by templateName | * get a list of entities grouped by a key | ||||
*/ | */ | ||||
EntityGroups.prototype.getEntsGrouped = function() | EntityGroups.prototype.getEntsGrouped = function() | ||||
{ | { | ||||
return this.getTemplateNames().map(template => ({ | return this.getKeys().map(key => ({ | ||||
"ents": this.getEntsByName(template), | "ents": this.getEntsByKey(key), | ||||
"template": template | "key": key | ||||
})); | })); | ||||
}; | }; | ||||
/** | /** | ||||
* Gets all ents in every group except ones of the specified group | * Gets all ents in every group except ones of the specified group | ||||
*/ | */ | ||||
EntityGroups.prototype.getEntsByNameInverse = function(templateName) | EntityGroups.prototype.getEntsByKeyInverse = function(key) | ||||
{ | { | ||||
var ents = []; | var ents = []; | ||||
for (var ent in this.ents) | for (var ent in this.ents) | ||||
if (this.ents[ent] != templateName) | if (this.ents[ent] != key) | ||||
ents.push(+ent); | ents.push(+ent); | ||||
return ents; | return ents; | ||||
}; | }; | ||||
/** | /** | ||||
* EntitySelection class for managing the entity selection list and the primary selection | * EntitySelection class for managing the entity selection list and the primary selection | ||||
*/ | */ | ||||
Show All 9 Lines | function EntitySelection() | ||||
this.motionDebugOverlay = false; | this.motionDebugOverlay = false; | ||||
// Public properties: | // Public properties: | ||||
this.dirty = false; // set whenever the selection has changed | this.dirty = false; // set whenever the selection has changed | ||||
this.groups = new EntityGroups(); | this.groups = new EntityGroups(); | ||||
} | } | ||||
/** | /** | ||||
* Deselect everything but entities of the chosen type if the modifier is true otherwise deselect just the chosen entity | * Deselect everything but entities of the chosen type if inverse is true otherwise deselect just the chosen entity | ||||
*/ | */ | ||||
EntitySelection.prototype.makePrimarySelection = function(templateName, modifierKey) | EntitySelection.prototype.makePrimarySelection = function(key, inverse) | ||||
{ | { | ||||
let ents = modifierKey ? | let ents = inverse ? | ||||
this.groups.getEntsByNameInverse(templateName) : | this.groups.getEntsByKeyInverse(key) : | ||||
this.groups.getEntsByName(templateName); | this.groups.getEntsByKey(key); | ||||
this.reset(); | this.reset(); | ||||
this.addList(ents); | this.addList(ents); | ||||
}; | }; | ||||
/** | /** | ||||
* Get a list of the template names | * Get a list of the template names | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 318 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
not necessary for the patch, but as you modify this function, we could have "if (this.ents[ent]) continue;" here