Rename table, organize main file

Scott Yeskie [06-04-14 - 10:27]
Rename table, organize main file
Filename
CyrHUD.lua
diff --git a/CyrHUD.lua b/CyrHUD.lua
index b3634ad..9aaa716 100644
--- a/CyrHUD.lua
+++ b/CyrHUD.lua
@@ -3,75 +3,47 @@
   * Author: Sasky
 ]]--

-zdb = {}
-
-zdb.ui = {}
-zdb.color = "EEEEEE"
-
-zdb.ui.clickHandler = function()
-	d(GuildCharNames:generateLink(data))
-end
-
-zdb.linkHandler = function(rawLink, _, _, _, linkType, varargs)
-    --d("Link type: " .. linkType .. " / Args: " .. varargs)
-    d(rawLink:gsub("|","---"))
-end
+CyrHUD = {}

+----------------------------------------------
+-- Utility
+----------------------------------------------
 function bl(val)
 	if val == nil then return "NIL" elseif val then return "T" else return "F" end
 end

-AllianceColor = {}
-AllianceColor[ALLIANCE_ALDMERI_DOMINION] = "|cB2B222" --AD
-AllianceColor[ALLIANCE_EBONHEART_PACT] = "|cB22222" --EP
-AllianceColor[ALLIANCE_DAGGERFALL_COVENANT] = "|c6666EE" --DC
+function nn(val)
+    if val == nil then return "NIL" end
+    return val
+end

-local function formatTime(delta)
+function CyrHUD.formatTime(delta, inclueSec)
     local sec = delta % 60
     delta = (delta - sec) / 60
     local min = delta % 60
-    local hrs = (delta - min) / 60
+    local out = min .. "m"

-    local out = ""
-    if hrs > 0 then
-        out = out .. hrs .. "h "
+    if inclueSec then
+        out = out .. " " .. sec .. "s"
     end
-    out = out .. min .. "m " .. sec .. "s"
     return out
 end

-function updateUI()
+----------------------------------------------
+-- Score
+----------------------------------------------
+function CyrHUD.updateScore()
     local cID = GetCurrentCampaignId()
-    local time = formatTime(GetSecondsUntilCampaignScoreReevaluation(cID))
+    local time = CyrHUD.formatTime(GetSecondsUntilCampaignScoreReevaluation(cID), true)
     CyrHUD_UI_Time:SetText(time)
     CyrHUD_UI_AD:SetText("+" .. GetCampaignAlliancePotentialScore(cID, ALLIANCE_ALDMERI_DOMINION))
     CyrHUD_UI_DC:SetText("+" .. GetCampaignAlliancePotentialScore(cID, ALLIANCE_DAGGERFALL_COVENANT))
     CyrHUD_UI_EP:SetText("+" ..  GetCampaignAlliancePotentialScore(cID, ALLIANCE_EBONHEART_PACT))
 end

-SLASH_COMMANDS["/zdb"] = function()
-    EVENT_MANAGER:RegisterForUpdate("ZDBUpdateAPCount", 1000, updateUI)
-end
-
-SLASH_COMMANDS["/linkdb"] = function()
-    LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, zdb.linkHandler)
-end
-
-
-function nn(val)
-	if val == nil then return "NIL" end
-	return val
-end
-
-zdb.dumpInfo = function(_, _, _, _, linkType, varargs)
-	if linkType ~= "playerDetail" then return false end
-	d(nn(d1))
-	CyrHUD_UI_Name:SetText(nn(d1))
-	return true
-end
-
-CyrHUD = {}
-
+----------------------------------------------
+-- Data
+----------------------------------------------
 CyrHUD.info = {}
 CyrHUD.info[ALLIANCE_ALDMERI_DOMINION] = {}
 CyrHUD.info[ALLIANCE_ALDMERI_DOMINION].color = { hex = "B2B222", r = .698, g = .698, b = .133 }
@@ -98,8 +70,9 @@ CyrHUD.info[ALLIANCE_EBONHEART_PACT][KEEPTYPE_OUTPOST] = {}
 CyrHUD.info[ALLIANCE_EBONHEART_PACT][KEEPTYPE_OUTPOST].icon = "/esoui/art/mappins/ava_outpost_ebonheart.dds"
 CyrHUD.info[ALLIANCE_EBONHEART_PACT][KEEPTYPE_OUTPOST].iconua = "/esoui/art/mappins/ava_outpost_ebonheart.dds"

-
-
+----------------------------------------------
+-- Notification UI pool
+----------------------------------------------
 CyrHUD.entryCount = 0
 CyrHUD.entries = {}
 CyrHUD.createEntry = function()
@@ -173,6 +146,33 @@ CyrHUD.reset = function()
     CyrHUD.ptr = 0
 end

+CyrHUD.print = function(battle)
+    entry = CyrHUD.getEntry()
+    entry.icon:SetTexture(battle:getIcon())
+    entry.name:SetText(battle.keepName)
+    local color = CyrHUD.info[battle.defender].color
+    entry.name:SetColor(color.r, color.g, color.b)
+    entry.time:SetText(battle:getDuration())
+    local ds, dc = battle:getDefSiege()
+    entry.defSiege:SetText(ds)
+    entry.defSiege:SetColor(dc.r, dc.g, dc.b)
+    local as, ac = battle:getAttSiege()
+    entry.attSiege:SetText(as)
+    entry.attSiege:SetColor(ac.r, ac.g, ac.b)
+    local r,g,b,a = battle:getBGColor()
+    entry.main:SetCenterColor(r,g,b,a)
+end
+
+CyrHUD.printAll = function()
+    CyrHUD.reset()
+    for _,b in pairs(CyrHUD.battles) do
+        CyrHUD.print(b)
+    end
+end
+
+----------------------------------------------
+-- Battle management
+----------------------------------------------
 CyrHUD.battles = {}
 CyrHUD.add = function(keepID)
     if CyrHUD.battles[keepID] == nil then
@@ -197,31 +197,12 @@ CyrHUD.updateAll = function()
     end
 end

-CyrHUD.printAll = function()
-    CyrHUD.reset()
-    for _,b in pairs(CyrHUD.battles) do
-        CyrHUD.print(b)
+CyrHUD.scanKeeps = function()
+    for i=3,20 do
+        CyrHUD.checkAdd(i)
     end
 end

-CyrHUD.print = function(battle)
-    entry = CyrHUD.getEntry()
-    entry.icon:SetTexture(battle:getIcon())
-    entry.name:SetText(battle.keepName)
-    local color = CyrHUD.info[battle.defender].color
-    entry.name:SetColor(color.r, color.g, color.b)
-    entry.time:SetText(battle:getDuration())
-    local ds, dc = battle:getDefSiege()
-    entry.defSiege:SetText(ds)
-    entry.defSiege:SetColor(dc.r, dc.g, dc.b)
-    local as, ac = battle:getAttSiege()
-    entry.attSiege:SetText(as)
-    entry.attSiege:SetColor(ac.r, ac.g, ac.b)
-    local r,g,b,a = battle:getBGColor()
-    entry.main:SetCenterColor(r,g,b,a)
-    --entry.defSiege:SetText()
-end
-
 ------------------------------------------------------------------------
 -- Battle class
 ------------------------------------------------------------------------
@@ -285,16 +266,7 @@ end
 function CyrHUD.Battle:getDuration()
     local time = self.endBattle or GetTimeStamp()
     local delta = GetDiffBetweenTimeStamps(time, self.startBattle)
-    delta = math.floor(delta/60)
-    if delta == 0 then return "" end
-    local min = delta % 60
-    local hrs = (delta - min) / 60
-
-    local out = ""
-    if hrs > 0 then
-        out = out .. hrs .. "h "
-    end
-    out = out .. min .. "m "
+    local out = CyrHUD.formatTime(delta)
     return out
 end

@@ -341,22 +313,9 @@ function CyrHUD.Battle:getIcon()
     end
 end

-function bl(val) if val then return "T" end return "F" end
-
-SLASH_COMMANDS["/zdb2"] = function(i)
-    d("Local campaign: " .. GetCurrentCampaignId())
-    local kid, bc = GetKeepKeysByIndex(i)
-    d(nn(i) .. ":" .. nn(bc) .. "/" .. nn(kid) .. " " .. nn(GetKeepName(kid)))
-    d("Under attack? " .. bl(GetKeepUnderAttack(kid, bc)))
-    d("Siege EP:" .. GetNumSieges(kid, bc, ALLIANCE_EBONHEART_PACT) .. " DC:" .. GetNumSieges(kid, bc, ALLIANCE_DAGGERFALL_COVENANT) .. " AD:" .. GetNumSieges(kid, bc, ALLIANCE_ALDMERI_DOMINION))
-end
-
-CyrHUD.scanKeeps = function()
-    for i=3,20 do
-        CyrHUD.checkAdd(i)
-    end
-end
-
+------------------------------------------------------------------------
+-- Initialization
+------------------------------------------------------------------------
 local function init()
     d("Adding keep info")
     EVENT_MANAGER:RegisterForUpdate("CyrHUBKeepCheck", 5000, function()
@@ -366,7 +325,7 @@ local function init()
         CyrHUD.updateAll()
         CyrHUD.printAll()
     end)
-    EVENT_MANAGER:RegisterForUpdate("ZDBUpdateAPCount", 1000, updateUI)
+    EVENT_MANAGER:RegisterForUpdate("ZDBUpdateAPCount", 1000, CyrHUD.updateScore)
 end

 local showCyrHUD = false