From be06299e28512c01f02ff242f43efbecc1562e3a Mon Sep 17 00:00:00 2001 From: elexis Date: Sun, 10 Dec 2017 03:08:05 +0000 Subject: [PATCH] Use only one getter for range overlays instead of three to four in the Heal and Auras component. Move default Heal range visualization texture properties to the template and only display Heal ranges if the template was given. Differential Revision: https://code.wildfiregames.com/D1128 Refs #3915, #4349, D238, D432, D568 This was SVN commit r20624. --- binaries/data/config/default.cfg | 4 +- .../mods/public/gui/session/hotkeys/misc.xml | 4 +- .../data/mods/public/gui/session/session.js | 4 +- .../public/simulation/components/Auras.js | 54 ++++++++++--------- .../mods/public/simulation/components/Heal.js | 20 ++++--- .../components/RangeVisualization.js | 48 ++++------------- .../simulation/components/tests/test_Heal.js | 11 ++-- .../templates/template_unit_hero_healer.xml | 5 ++ .../template_unit_support_healer.xml | 5 ++ 9 files changed, 70 insertions(+), 85 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 9493d2fca9..2f6b23ed70 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -168,7 +168,7 @@ session.showstatusbars = Tab ; Toggle display of status bars session.highlightguarding = PgDn ; Toggle highlight of guarding units session.highlightguarded = PgUp ; Toggle highlight of guarded units session.toggleattackrange = "Alt+C" ; Toggle display of attack range overlays of selected defensive structures -session.toggleaurarange = "Alt+V" ; Toggle display of aura range overlays of selected units and structures +session.toggleaurasrange = "Alt+V" ; Toggle display of aura range overlays of selected units and structures session.togglehealrange = "Alt+B" ; Toggle display of heal range overlays of selected units ; > HOTKEYS ONLY @@ -348,7 +348,7 @@ camerajump.threshold = 40 ; How close do we have to be to the actual loc timeelapsedcounter = false ; Show the game duration in the top right corner batchtrainingsize = 5 ; Number of units to be trained per batch (when pressing the hotkey) attackrange = true ; Display attack range overlays of selected defensive structures -aurarange = true ; Display aura range overlays of selected units and structures +aurasrange = true ; Display aura range overlays of selected units and structures healrange = true ; Display heal range overlays of selected units [gui.session.minimap] diff --git a/binaries/data/mods/public/gui/session/hotkeys/misc.xml b/binaries/data/mods/public/gui/session/hotkeys/misc.xml index 575837aa48..4ad8d8c592 100644 --- a/binaries/data/mods/public/gui/session/hotkeys/misc.xml +++ b/binaries/data/mods/public/gui/session/hotkeys/misc.xml @@ -101,8 +101,8 @@ toggleRangeOverlay("Attack"); - - toggleRangeOverlay("Aura"); + + toggleRangeOverlay("Auras"); diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 21bc0e4b4c..12b3b661e6 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -797,7 +797,7 @@ function onSimulationUpdate() handleNotifications(); updateGUIObjects(); - for (let type of ["Attack", "Aura", "Heal"]) + for (let type of ["Attack", "Auras", "Heal"]) Engine.GuiInterfaceCall("EnableVisualRangeOverlayType", { "type": type, "enabled": Engine.ConfigDB_GetValue("user", "gui.session." + type.toLowerCase() + "range") == "true" @@ -1280,7 +1280,7 @@ function toggleConfigBool(configName) /** * Toggles the display of range overlays of selected entities for the given range type. - * @param {string} type - for example "Aura" + * @param {string} type - for example "Auras" */ function toggleRangeOverlay(type) { diff --git a/binaries/data/mods/public/simulation/components/Auras.js b/binaries/data/mods/public/simulation/components/Auras.js index 53fe2610dd..b78dd4eb02 100644 --- a/binaries/data/mods/public/simulation/components/Auras.js +++ b/binaries/data/mods/public/simulation/components/Auras.js @@ -66,29 +66,6 @@ Auras.prototype.GetRange = function(name) return undefined; }; -/** - * Return the names of any range auras - used to render their ranges. - */ -Auras.prototype.GetVisualAuraRangeNames = function() -{ - return this.GetAuraNames().filter(auraName => this.IsRangeAura(auraName) && this[auraName].isApplied); -}; - -Auras.prototype.GetLineTexture = function(name) -{ - return this.auras[name].rangeOverlay ? this.auras[name].rangeOverlay.lineTexture : "outline_border.png"; -}; - -Auras.prototype.GetLineTextureMask = function(name) -{ - return this.auras[name].rangeOverlay ? this.auras[name].rangeOverlay.lineTextureMask : "outline_border_mask.png"; -}; - -Auras.prototype.GetLineThickness = function(name) -{ - return this.auras[name].rangeOverlay ? this.auras[name].rangeOverlay.lineThickness : 0.2; -}; - Auras.prototype.GetClasses = function(name) { return this.auras[name].affects; @@ -104,6 +81,35 @@ Auras.prototype.GetAffectedPlayers = function(name) return this.affectedPlayers[name]; }; +Auras.prototype.GetRangeOverlays = function() +{ + let rangeOverlays = []; + + for (let name of this.GetAuraNames()) + { + if (!this.IsRangeAura(name) || !this[name].isApplied) + continue; + + rangeOverlays.push( + this.auras[name].rangeOverlay ? + { + "radius": this.GetRange(name), + "texture": this.auras[name].rangeOverlay.lineTexture, + "textureMask": this.auras[name].rangeOverlay.lineTextureMask, + "thickness": this.auras[name].rangeOverlay.lineThickness + } : + // Specify default in order not to specify it in about 40 auras + { + "radius": this.GetRange(name), + "texture": "outline_border.png", + "textureMask": "outline_border_mask.png", + "thickness": 0.2 + }); + } + + return rangeOverlays; +}; + Auras.prototype.CalculateAffectedPlayers = function(name) { var affectedPlayers = this.auras[name].affectedPlayers || ["Player"]; @@ -278,7 +284,7 @@ Auras.prototype.Clean = function() let cmpRangeVisualization = Engine.QueryInterface(this.entity, IID_RangeVisualization); if (cmpRangeVisualization) { - cmpRangeVisualization.UpdateVisualAuraRanges(); + cmpRangeVisualization.UpdateRangeOverlays("Auras"); cmpRangeVisualization.RegenerateRangeVisualizations(false); } } diff --git a/binaries/data/mods/public/simulation/components/Heal.js b/binaries/data/mods/public/simulation/components/Heal.js index 311d2fa766..ba7ebcd21f 100644 --- a/binaries/data/mods/public/simulation/components/Heal.js +++ b/binaries/data/mods/public/simulation/components/Heal.js @@ -87,19 +87,17 @@ Heal.prototype.GetHealableClasses = function() return this.template.HealableClasses._string || ""; }; -Heal.prototype.GetLineTexture = function() +Heal.prototype.GetRangeOverlays = function() { - return this.template.RangeOverlay ? this.template.RangeOverlay.LineTexture : "heal_overlay_range.png"; -}; + if (!this.template.RangeOverlay) + return []; -Heal.prototype.GetLineTextureMask = function() -{ - return this.template.RangeOverlay ? this.template.RangeOverlay.LineTextureMask : "heal_overlay_range_mask.png"; -}; - -Heal.prototype.GetLineThickness = function() -{ - return this.template.RangeOverlay ? +this.template.RangeOverlay.LineThickness : 0.35; + return [{ + "radius": this.GetRange().max, + "texture": this.template.RangeOverlay.LineTexture, + "textureMask": this.template.RangeOverlay.LineTextureMask, + "thickness": +this.template.RangeOverlay.LineThickness + }] }; /** diff --git a/binaries/data/mods/public/simulation/components/RangeVisualization.js b/binaries/data/mods/public/simulation/components/RangeVisualization.js index 6fa145669f..e6c91a6d86 100644 --- a/binaries/data/mods/public/simulation/components/RangeVisualization.js +++ b/binaries/data/mods/public/simulation/components/RangeVisualization.js @@ -7,7 +7,7 @@ RangeVisualization.prototype.Init = function() this.enabled = false; this.enabledRangeTypes = { "Attack": false, - "Aura": false, + "Auras": false, "Heal": false }; @@ -22,42 +22,11 @@ RangeVisualization.prototype.Deserialize = function(data) this.Init(); }; -RangeVisualization.prototype.UpdateVisualAttackRanges = function() +RangeVisualization.prototype.UpdateRangeOverlays = function(componentName) { - let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); - if (cmpAttack) - this.rangeVisualizations.set("Attack", cmpAttack.GetRangeOverlays()); -}; - -RangeVisualization.prototype.UpdateVisualAuraRanges = function() -{ - let cmpAuras = Engine.QueryInterface(this.entity, IID_Auras); - if (!cmpAuras) - return; - - this.rangeVisualizations.set("Aura", []); - - for (let auraName of cmpAuras.GetVisualAuraRangeNames()) - this.rangeVisualizations.get("Aura").push({ - "radius": cmpAuras.GetRange(auraName), - "texture": cmpAuras.GetLineTexture(auraName), - "textureMask": cmpAuras.GetLineTextureMask(auraName), - "thickness": cmpAuras.GetLineThickness(auraName), - }); -}; - -RangeVisualization.prototype.UpdateVisualHealRanges = function() -{ - let cmpHeal = Engine.QueryInterface(this.entity, IID_Heal); - if (!cmpHeal) - return; - - this.rangeVisualizations.set("Heal", [{ - "radius": cmpHeal.GetRange().max, - "texture": cmpHeal.GetLineTexture(), - "textureMask": cmpHeal.GetLineTextureMask(), - "thickness": cmpHeal.GetLineThickness(), - }]); + let cmp = Engine.QueryInterface(this.entity, global["IID_" + componentName]); + if (cmp) + this.rangeVisualizations.set(componentName, cmp.GetRangeOverlays()); }; RangeVisualization.prototype.SetEnabled = function(enabled, enabledRangeTypes, forceUpdate) @@ -95,7 +64,8 @@ RangeVisualization.prototype.OnOwnershipChanged = function(msg) if (msg.to == -1) return; for (let type in this.enabledRangeTypes) - this["UpdateVisual" + type + "Ranges"](); + this.UpdateRangeOverlays(type); + this.RegenerateRangeVisualizations(false); }; @@ -106,7 +76,7 @@ RangeVisualization.prototype.OnValueModification = function(msg) msg.valueNames.indexOf("Attack/Ranged/MaxRange") == -1) return; - this["UpdateVisual" + msg.component + "Ranges"](); + this.UpdateRangeOverlays(msg.component); this.RegenerateRangeVisualizations(false); }; @@ -116,7 +86,7 @@ RangeVisualization.prototype.OnValueModification = function(msg) RangeVisualization.prototype.OnDeserialized = function(msg) { for (let type in this.enabledRangeTypes) - this["UpdateVisual" + type + "Ranges"](); + this.UpdateRangeOverlays(type); }; Engine.RegisterComponentType(IID_RangeVisualization, "RangeVisualization", RangeVisualization); diff --git a/binaries/data/mods/public/simulation/components/tests/test_Heal.js b/binaries/data/mods/public/simulation/components/tests/test_Heal.js index 5b07b6e487..db34d12902 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Heal.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Heal.js @@ -53,11 +53,12 @@ TS_ASSERT_EQUALS(cmpHeal.GetHealableClasses(), "Support Infantry"); TS_ASSERT_EQUALS(cmpHeal.GetUnhealableClasses(), "Cavalry"); -TS_ASSERT_EQUALS(cmpHeal.GetLineTexture(), "heal_overlay_range.png"); - -TS_ASSERT_EQUALS(cmpHeal.GetLineTextureMask(), "heal_overlay_range_mask.png"); - -TS_ASSERT_EQUALS(cmpHeal.GetLineThickness(), 0.35); +TS_ASSERT_UNEVAL_EQUALS(cmpHeal.GetRangeOverlays(), [{ + "radius": 20 + 300, + "texture": "heal_overlay_range.png", + "textureMask": "heal_overlay_range_mask.png", + "thickness": 0.35 +}]); // Test PerformHeal let target = 70; diff --git a/binaries/data/mods/public/simulation/templates/template_unit_hero_healer.xml b/binaries/data/mods/public/simulation/templates/template_unit_hero_healer.xml index 17581ba52d..76c2524d4b 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_hero_healer.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_hero_healer.xml @@ -19,6 +19,11 @@ 2000 Human + + heal_overlay_range.png + heal_overlay_range_mask.png + 0.35 + 1000 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml b/binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml index 27fa1ba266..ac50459a6d 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml @@ -11,6 +11,11 @@ 2000 Human + + heal_overlay_range.png + heal_overlay_range_mask.png + 0.35 + 85