Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/RangeVisualization.js
function RangeVisualization() {} | function RangeVisualization() {} | ||||
RangeVisualization.prototype.Schema = "<empty/>"; | RangeVisualization.prototype.Schema = "<empty/>"; | ||||
RangeVisualization.prototype.Init = function() | RangeVisualization.prototype.Init = function() | ||||
{ | { | ||||
this.enabled = false; | this.enabled = false; | ||||
this.enabledRangeTypes = { | this.enabledRangeTypes = { | ||||
"Aura": false | "Aura": false, | ||||
"Heal": false | |||||
}; | }; | ||||
this.rangeVisualizations = new Map(); | this.rangeVisualizations = new Map(); | ||||
for (let type in this.enabledRangeTypes) | for (let type in this.enabledRangeTypes) | ||||
this["GetVisual" + type + "Ranges"](type); | this["GetVisual" + type + "Ranges"](type); | ||||
}; | }; | ||||
// The GUI enables visualizations | // The GUI enables visualizations | ||||
Show All 16 Lines | for (let auraName of cmpAuras.GetVisualAuraRangeNames()) | ||||
this.rangeVisualizations.get(type).push({ | this.rangeVisualizations.get(type).push({ | ||||
"radius": cmpAuras.GetRange(auraName), | "radius": cmpAuras.GetRange(auraName), | ||||
"texture": cmpAuras.GetLineTexture(auraName), | "texture": cmpAuras.GetLineTexture(auraName), | ||||
"textureMask": cmpAuras.GetLineTextureMask(auraName), | "textureMask": cmpAuras.GetLineTextureMask(auraName), | ||||
"thickness": cmpAuras.GetLineThickness(auraName), | "thickness": cmpAuras.GetLineThickness(auraName), | ||||
}); | }); | ||||
}; | }; | ||||
RangeVisualization.prototype.SetEnabled = function(enabled, enabledRangeTypes) | RangeVisualization.prototype.GetVisualHealRanges = function(type) | ||||
{ | |||||
let cmpHeal = Engine.QueryInterface(this.entity, IID_Heal); | |||||
if (!cmpHeal) | |||||
return; | |||||
this.rangeVisualizations.set(type, [{ | |||||
"radius": cmpHeal.GetRange().max, | |||||
"texture": cmpHeal.GetLineTexture(), | |||||
"textureMask": cmpHeal.GetLineTextureMask(), | |||||
"thickness": cmpHeal.GetLineThickness(), | |||||
}]); | |||||
}; | |||||
RangeVisualization.prototype.SetEnabled = function(enabled, enabledRangeTypes, forceUpdate = false) | |||||
elexis: The component should be agnostic of the fact that there is a hotkey.
Why doesn't the range vis… | |||||
elexisUnsubmitted Not Done Inline ActionsBetter avoid defaults, so that callers are required to think about the value they want to pass / enforce people being conscious of the behavior triggered elexis: Better avoid defaults, so that callers are required to think about the value they want to pass… | |||||
{ | { | ||||
this.enabled = enabled; | this.enabled = enabled; | ||||
this.enabledRangeTypes = enabledRangeTypes; | this.enabledRangeTypes = enabledRangeTypes; | ||||
this.RegenerateRangeVisualizations(); | this.RegenerateRangeVisualizations(forceUpdate); | ||||
}; | }; | ||||
RangeVisualization.prototype.RegenerateRangeVisualizations = function() | RangeVisualization.prototype.RegenerateRangeVisualizations = function(forceUpdate = false) | ||||
{ | { | ||||
let cmpSelectable = Engine.QueryInterface(this.entity, IID_Selectable); | let cmpSelectable = Engine.QueryInterface(this.entity, IID_Selectable); | ||||
if (!cmpSelectable) | if (!cmpSelectable) | ||||
return; | return; | ||||
cmpSelectable.ResetRangeOverlays(); | cmpSelectable.ResetRangeOverlays(); | ||||
if (!this.enabled) | if (!this.enabled && !forceUpdate) | ||||
elexisUnsubmitted Not Done Inline ActionsI still have trouble understanding why this line has to be this way and why all of this can't be just more straight forward. But I can confirm that this is the only term of these booleans that works. elexis: I still have trouble understanding why this line has to be this way and why all of this can't… | |||||
return; | return; | ||||
Not Done Inline ActionsThe enabled property has no justification for existence, has it? elexis: The `enabled` property has no justification for existence, has it? | |||||
// Only render individual range types that have been enabled | // Only render individual range types that have been enabled | ||||
for (let rangeOverlayType of this.rangeVisualizations.keys()) | for (let rangeOverlayType of this.rangeVisualizations.keys()) | ||||
if (this.enabledRangeTypes[rangeOverlayType]) | if (this.enabledRangeTypes[rangeOverlayType]) | ||||
for (let rangeOverlay of this.rangeVisualizations.get(rangeOverlayType)) | for (let rangeOverlay of this.rangeVisualizations.get(rangeOverlayType)) | ||||
cmpSelectable.AddRangeOverlay( | cmpSelectable.AddRangeOverlay( | ||||
rangeOverlay.radius, | rangeOverlay.radius, | ||||
rangeOverlay.texture, | rangeOverlay.texture, | ||||
rangeOverlay.textureMask, | rangeOverlay.textureMask, | ||||
rangeOverlay.thickness); | rangeOverlay.thickness); | ||||
}; | }; | ||||
RangeVisualization.prototype.OnOwnershipChanged = function(msg) | RangeVisualization.prototype.OnOwnershipChanged = function(msg) | ||||
{ | { | ||||
if (this.enabled && msg.to != -1) | if (this.enabled && msg.to != -1) | ||||
this.RegenerateRangeVisualizations(); | this.RegenerateRangeVisualizations(); | ||||
elexisUnsubmitted Not Done Inline ActionsAlways pass all arguments seems cleaner elexis: Always pass all arguments seems cleaner | |||||
}; | }; | ||||
RangeVisualization.prototype.OnValueModification = function(msg) | |||||
{ | |||||
if (msg.valueNames.indexOf("Heal/Range") == -1) | |||||
return; | |||||
this["GetVisual" + msg.component + "Ranges"](msg.component); | |||||
Not Done Inline ActionsWhy exactly did we add the argument if the information is already contained in the function name? A getter function should get something, so should be called Refresh, Reload, Update or Regenerate elexis: Why exactly did we add the argument if the information is already contained in the function… | |||||
this.RegenerateRangeVisualizations(); | |||||
}; | |||||
Engine.RegisterComponentType(IID_RangeVisualization, "RangeVisualization", RangeVisualization); | Engine.RegisterComponentType(IID_RangeVisualization, "RangeVisualization", RangeVisualization); |
Wildfire Games · Phabricator
The component should be agnostic of the fact that there is a hotkey.
Why doesn't the range vis renderer ignore the m_AlwaysVisible altogether?