From 689df94d5582c5904c385397d6253e5f48c58192 Mon Sep 17 00:00:00 2001 From: Parnic Date: Sun, 15 Jan 2023 12:40:51 -0600 Subject: [PATCH] Refactor repeated code into a function I need this for an upcoming feature, and it turns out that the "new rune just became ready" feature didn't cooperate with width-growing runes anyway, so this is also a bugfix for that (I don't know that we have any width-growing power types in the game today, but still). --- modules/ClassPowerCounter.lua | 46 ++++++++++++++++++----------------- modules/Shards.lua | 2 +- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/modules/ClassPowerCounter.lua b/modules/ClassPowerCounter.lua index 79287c8..ed8d0dc 100644 --- a/modules/ClassPowerCounter.lua +++ b/modules/ClassPowerCounter.lua @@ -20,7 +20,7 @@ IceClassPowerCounter.prototype.unmodifiedMaxPerRune = 10 IceClassPowerCounter.prototype.unit = "player" IceClassPowerCounter.prototype.round = ceil IceClassPowerCounter.prototype.growModes = { width = 1, height = 2 } -IceClassPowerCounter.prototype.currentGrowMode = nil +IceClassPowerCounter.prototype.currentGrowMode = IceClassPowerCounter.prototype.growModes["height"] -- Constructor -- function IceClassPowerCounter.prototype:init(name) @@ -549,33 +549,14 @@ function IceClassPowerCounter.prototype:UpdateRunePower(event, arg1, arg2) end if i > numReady or self.numRunes == 1 then - local left, right, top, bottom = 0, 1, 0, 1 - if self:GetRuneMode() == "Graphical" then - left, right, top, bottom = unpack(self.runeCoords[i]) - end - local currPercent = percentReady - numReady if self.numRunes == 1 then currPercent = numReady / UnitPowerMax("player", self.unitPower) end - if self.currentGrowMode == self.growModes["height"] then - top = bottom - (currPercent * (bottom - top)) - self.frame.graphical[i].rune:SetHeight(currPercent * self.runeHeight) - elseif self.currentGrowMode == self.growModes["width"] then - right = left + (currPercent * (right - left)) - self.frame.graphical[i].rune:SetWidth(currPercent * self.runeWidth) - end - self.frame.graphical[i].rune:SetTexCoord(left, right, top, bottom) + self:SetRuneCoords(i, currPercent) elseif i > self.lastNumReady then - if self.runeCoords ~= nil and #self.runeCoords >= i then - local left, right, top, bottom = 0, 1, 0, 1 - if self:GetRuneMode() == "Graphical" then - left, right, top, bottom = unpack(self.runeCoords[i]) - end - self.frame.graphical[i].rune:SetTexCoord(left, right, top, bottom) - self.frame.graphical[i].rune:SetHeight(self.runeHeight) - end + self:SetRuneCoords(i, 1) if self.moduleSettings.flashWhenBecomingReady then local fadeInfo={ @@ -609,6 +590,27 @@ function IceClassPowerCounter.prototype:UpdateRunePower(event, arg1, arg2) end end +function IceClassPowerCounter.prototype:SetRuneCoords(rune, percent) + if self.runeCoords == nil or #self.runeCoords < rune then + return + end + + local left, right, top, bottom = 0, 1, 0, 1 + if self:GetRuneMode() == "Graphical" then + left, right, top, bottom = unpack(self.runeCoords[rune]) + end + + if self.currentGrowMode == self.growModes["height"] then + top = bottom - (percent * (bottom - top)) + self.frame.graphical[rune].rune:SetHeight(percent * self.runeHeight) + elseif self.currentGrowMode == self.growModes["width"] then + right = left + (percent * (right - left)) + self.frame.graphical[rune].rune:SetWidth(percent * self.runeWidth) + end + + self.frame.graphical[rune].rune:SetTexCoord(left, right, top, bottom) +end + function IceClassPowerCounter.prototype:HideRune(i) if self:GetRuneMode() == "Numeric" then self.frame.graphical[i].Hide() diff --git a/modules/Shards.lua b/modules/Shards.lua index 30c4a4a..4cfd7e2 100644 --- a/modules/Shards.lua +++ b/modules/Shards.lua @@ -131,7 +131,7 @@ function ShardCounter.prototype:UpdatePowerType(event) self.shouldShowUnmodified = false self.requiredSpec = CurrentSpec - self.currentGrowMode = nil + self.currentGrowMode = self.growModes["height"] if CurrentSpec == SPEC_WARLOCK_AFFLICTION then self.runeCoords = AfflictionCoords