Changeset View
Standalone View
binaries/data/mods/public/simulation/components/RangeVisualization.js
function RangeVisualization() {} | |||||
RangeVisualization.prototype.Schema = "<empty/>"; | |||||
RangeVisualization.prototype.Init = function() | |||||
{ | |||||
Sandarac: This should be removed. | |||||
this.enabled = false; | |||||
// Keep track of the enabled aura types for this entity | |||||
this.enabledRangeTypes = { | |||||
Done Inline Actionsself-explanatory elexis: self-explanatory | |||||
"Aura": false | |||||
}; | |||||
Done Inline Actions// Keep track of the enabled aura types for this entity? (Since it doesn't strictly depend on config options but also on the selection and there might be other GUI checks and hotkeys added later) elexis: `// Keep track of the enabled aura types for this entity`? (Since it doesn't strictly depend on… | |||||
this.rangeVisualizations = new Map(); | |||||
for (let type in this.enabledRangeTypes) | |||||
this["GetVisual" + type + "Ranges"](type); | |||||
}; | |||||
Not Done Inline Actions(Dunno if a Map has an advantage over objects) elexis: (Dunno if a Map has an advantage over objects) | |||||
Not Done Inline ActionsA Map is used in a similar way to this in cmpStatusBars (which is what this new component is based on). Sandarac: A Map is used in a similar way to this in cmpStatusBars (which is what this new component is… | |||||
Done Inline Actionsfor...in elexis: for...in | |||||
// The GUI enables visualizations | |||||
RangeVisualization.prototype.Serialize = null; | |||||
RangeVisualization.prototype.Deserialize = function(data) | |||||
Done Inline ActionsPerhaps we should state that we do not serialize the properties because the GUI and selection enables the visualization elexis: Perhaps we should state that we do not serialize the properties because the GUI and selection… | |||||
{ | |||||
this.Init(); | |||||
}; | |||||
Not Done Inline Actionsiirc, first Init() was called, then Deserialize(), so it may or may not be redundant (depends on other deserialized components?) elexis: iirc, first Init() was called, then Deserialize(), so it may or may not be redundant (depends… | |||||
Not Done Inline ActionsInit() is called in Deserialize() in components like StatusBars and Identity. Sandarac: `Init()` is called in `Deserialize()` in components like StatusBars and Identity. | |||||
RangeVisualization.prototype.GetVisualAuraRanges = function(type) | |||||
{ | |||||
let cmpAuras = Engine.QueryInterface(this.entity, IID_Auras); | |||||
if (!cmpAuras) | |||||
return; | |||||
this.rangeVisualizations.set(type, []); | |||||
for (let auraName of cmpAuras.GetVisualAuraRangeNames()) | |||||
this.rangeVisualizations.get(type).push({ | |||||
"radius": cmpAuras.GetRange(auraName), | |||||
"texture": cmpAuras.GetLineTexture(auraName), | |||||
"textureMask": cmpAuras.GetLineTextureMask(auraName), | |||||
"thickness": cmpAuras.GetLineThickness(auraName), | |||||
}); | |||||
}; | |||||
RangeVisualization.prototype.SetEnabled = function(enabled, enabledRangeTypes) | |||||
{ | |||||
this.enabled = enabled; | |||||
this.enabledRangeTypes = enabledRangeTypes; | |||||
this.RegenerateRangeVisualizations(); | |||||
}; | |||||
RangeVisualization.prototype.RegenerateRangeVisualizations = function() | |||||
{ | |||||
let cmpSelectable = Engine.QueryInterface(this.entity, IID_Selectable); | |||||
if (!cmpSelectable) | |||||
return; | |||||
cmpSelectable.ResetRangeOverlays(); | |||||
if (!this.enabled) | |||||
return; | |||||
// Only render individual range types that have been enabled | |||||
for (let rangeOverlayType of this.rangeVisualizations.keys()) | |||||
if (this.enabledRangeTypes[rangeOverlayType]) | |||||
for (let rangeOverlay of this.rangeVisualizations.get(rangeOverlayType)) | |||||
cmpSelectable.SetRangeOverlay(rangeOverlay.radius, rangeOverlay.texture, | |||||
rangeOverlay.textureMask, rangeOverlay.thickness); | |||||
Done Inline Actionsbetter each argument on a separate line than 2 arguments on one line, 2 on another. Nice side effect of having them aligned elexis: better each argument on a separate line than 2 arguments on one line, 2 on another. Nice side… | |||||
}; | |||||
RangeVisualization.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
Not Done Inline Actionsthickness);, at least the other code does it like this elexis: `thickness);`, at least the other code does it like this | |||||
if (this.enabled && msg.to != -1) | |||||
this.RegenerateRangeVisualizations(); | |||||
}; | |||||
Engine.RegisterComponentType(IID_RangeVisualization, "RangeVisualization", RangeVisualization); |
This should be removed.