Quantcast

Revert a bit

Scott Sibley [08-07-10 - 18:04]
Revert a bit
Filename
Modules/Text.lua
StarTip.lua
diff --git a/Modules/Text.lua b/Modules/Text.lua
index 685f5de..6b0f011 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -1,5 +1,6 @@
 local mod = StarTip:NewModule("Text", "AceTimer-3.0", "AceEvent-3.0")
 mod.name = "Text"
+mod.toggled = true
 local _G = _G
 local GameTooltip = _G.GameTooltip
 local StarTip = _G.StarTip
@@ -11,28 +12,31 @@ local select = _G.select
 local format = _G.format
 local floor = _G.floor
 local tostring = _G.tostring
-local UnitExists = _G.UnitExists
-local UnitIsPlayer = _G.UnitIsPlayer
-local UnitBuff = _G.UnitBuff
-local GetSpellInfo = _G.GetSpellInfo
-local UnitIsConnected = _G.UnitIsConnected
-local UnitIsFeignDeath = _G.UnitIsFeignDeath
-local UnitIsGhost = _G.UnitIsGhost
-local UnitIsDead = _G.UnitIsDead
-local UnitLevel = _G.UnitLevel
-local UnitClassification = _G.UnitClassification
-local UnitSelectionColor = _G.UnitSelectionColor
-local UnitRace = _G.UnitRace
-local GetGuildInfo = _G.GetGuildInfo
-local UnitName = _G.UnitName
-local UnitClass = _G.UnitClass
-local UnitMana = _G.UnitMana
-local UnitManaMax = _G.UnitManaMax
-local UnitFactionGroup = _G.UnitFactionGroup
-local UnitCreatureFamily = _G.UnitCreatureFamily
-local UnitCreatureType = _G.UnitCreatureType
-local UnitIsUnit = _G.UnitIsUnit
-local RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
+mod._G = _G
+mod.UnitExists = _G.UnitExists
+mod.UnitIsPlayer = _G.UnitIsPlayer
+mod.UnitBuff = _G.UnitBuff
+mod.GetSpellInfo = _G.GetSpellInfo
+mod.UnitIsConnected = _G.UnitIsConnected
+mod.UnitIsFeignDeath = _G.UnitIsFeignDeath
+mod.UnitIsGhost = _G.UnitIsGhost
+mod.UnitIsDead = _G.UnitIsDead
+mod.UnitLevel = _G.UnitLevel
+mod.UnitClassification = _G.UnitClassification
+mod.UnitSelectionColor = _G.UnitSelectionColor
+mod.UnitRace = _G.UnitRace
+mod.GetGuildInfo = _G.GetGuildInfo
+mod.UnitName = _G.UnitName
+mod.UnitClass = _G.UnitClass
+mod.UnitHealth = _G.UnitHealth
+mod.UnitHealthMax = _G.UnitHealthMax
+mod.UnitMana = _G.UnitMana
+mod.UnitManaMax = _G.UnitManaMax
+mod.UnitFactionGroup = _G.UnitFactionGroup
+mod.UnitCreatureFamily = _G.UnitCreatureFamily
+mod.UnitCreatureType = _G.UnitCreatureType
+mod.UnitIsUnit = _G.UnitIsUnit
+mod.RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
 local LSM = _G.LibStub("LibSharedMedia-3.0")
 local timer
 local factionList = {}
@@ -50,10 +54,11 @@ local function errorhandler(err)
     return geterrorhandler()(err)
 end

+--[[
 local executeCode
 do
 	local pool = setmetatable({},{__mode='v'})
-	executeCode = function(tag, code)
+	executeCode = function(tag, code, data)
 		if not code then return end

 		local runnable = pool[code]
@@ -74,6 +79,8 @@ do
 		return runnable(xpcall, errorhandler)
 	end
 end
+]]
+

 -- Thanks to ckknight for this
 mod.short = function(value)
@@ -115,8 +122,8 @@ local function updateLines()
     end
     for _, v in ipairs(lines) do
         if v.updating and v.right and self.db.profile[v.db] then
-            local left = executeCode(v.name, v.left)
-            local right, c = executeCode(v.name, v.right)
+            local left = StarTip.executeCode(v.name, v.left)
+            local right, c = StarTip.executeCode(v.name, v.right)
 			StarTip:del(c)
             if left and right then
                 for i = 1, self.NUM_LINES do
@@ -157,65 +164,68 @@ local defaultLines={
     [1] = {
         name = "UnitName",
         left = [[
-local text = StarTip:GetModule("Text")
 local c
-if UnitIsPlayer("mouseover") then
-    c = RAID_CLASS_COLORS[select(2, UnitClass("mouseover"))]
+if self.UnitIsPlayer("mouseover") then
+    c = self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseover"))]
 else
     c = StarTip:new()
-    c.r, c.g, c.b = UnitSelectionColor("mouseover")
+    c.r, c.g, c.b = self.UnitSelectionColor("mouseover")
 end
-return text.unitName, c
+return self.unitName, c
 ]],
         right = nil,
         updating = false,
-		bold = true
+		bold = true,
+		enabled = true
     },
     [2] = {
         name = "Target",
         left = 'return "Target:"',
         right = [[
-if UnitExists("mouseovertarget") then
+if self.UnitExists("mouseovertarget") then
     local c
-    if UnitIsPlayer("mouseovertarget") then
-        c = RAID_CLASS_COLORS[select(2, UnitClass("mouseovertarget"))]
+    if self.UnitIsPlayer("mouseovertarget") then
+        c = self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseovertarget"))]
     else
         c = StarTip:new()
-        c.r, c.g, c.b = UnitSelectionColor("mouseovertarget")
+        c.r, c.g, c.b = self.UnitSelectionColor("mouseovertarget")
     end
-    local name = UnitName("mouseovertarget")
+    local name = self.UnitName("mouseovertarget")
     return name, c
 else
     return "None", StarTip:newDict("r", 1, "g", 1, "b", 1)
 end
 ]],
         updating = true,
+		enabled = true
     },
     [3] = {
         name = "Guild",
         left = 'return "Guild:"',
         right = [[
-local guild = GetGuildInfo("mouseover")
-local text = StarTip:GetModule("Text")
-if guild then return "<" .. guild .. ">" else return text.unitGuild end
+local guild = self.GetGuildInfo("mouseover")
+if guild then return "<" .. guild .. ">" else return self.unitGuild end
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [4] = {
         name = "Rank",
         left = 'return "Rank:"',
         right = [[
-return select(2, GetGuildInfo("mouseover"))
+return select(2, self.GetGuildInfo("mouseover"))
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [5] = {
         name = "Realm",
         left = 'return "Realm:"',
         right = [[
-return select(2, UnitName("mouseover"))
+return select(2, self.UnitName("mouseover"))
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [6] = {
         name = "Level",
@@ -227,8 +237,8 @@ local classifications = StarTip.newDict(
     "elite", "+",
     "rare", "Rare")

-local lvl = UnitLevel("mouseover")
-local class = UnitClassification("mouseover")
+local lvl = self.UnitLevel("mouseover")
+local class = self.UnitClassification("mouseover")

 if lvl <= 0 then
     lvl = ''
@@ -242,111 +252,114 @@ StarTip:del(classifications)

 return lvl
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [7] = {
         name = "Race",
         left = 'return "Race:"',
         right = [[
 local race
-if UnitIsPlayer("mouseover") then
-    race = UnitRace("mouseover");
+if self.UnitIsPlayer("mouseover") then
+    race = self.UnitRace("mouseover");
 else
-    race = UnitCreatureFamily("mouseover") or UnitCreatureType("mouseover")
+    race = self.UnitCreatureFamily("mouseover") or self.UnitCreatureType("mouseover")
 end
 return race
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [8] = {
         name = "Class",
         left = 'return "Class:"',
         right = [[
-local class = UnitClass("mouseover")
-if class == UnitName("mouseover") then return end
-local c = UnitIsPlayer("mouseover") and RAID_CLASS_COLORS[select(2, UnitClass("mouseover"))]
+local class = self.UnitClass("mouseover")
+if class == self.UnitName("mouseover") then return end
+local c = self.UnitIsPlayer("mouseover") and self.RAID_CLASS_COLORS[select(2, self.UnitClass("mouseover"))]
 return class, c
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [9] = {
         name = "Faction",
         left = 'return "Faction:"',
         right = [[
-return UnitFactionGroup("mouseover")
+return self.UnitFactionGroup("mouseover")
 ]],
-        updating = false
+        updating = false,
+		enabled = true
     },
     [10] = {
         name = "Status",
         left = 'return "Status:"',
         right = [[
-local text = StarTip:GetModule("Text")
-if not UnitIsConnected("mouseover") then
+if not self.UnitIsConnected("mouseover") then
     return "Offline"
-elseif text.unitHasAura(GetSpellInfo(19752)) then
+elseif self.unitHasAura(self.GetSpellInfo(19752)) then
     return "Divine Intervention"
-elseif UnitIsFeignDeath("mouseover") then
+elseif self.UnitIsFeignDeath("mouseover") then
     return "Feigned Death"
-elseif UnitIsGhost("mouseover") then
+elseif self.UnitIsGhost("mouseover") then
     return "Ghost"
-elseif UnitIsDead("mouseover") and  text.unitHasAura(GetSpellInfo(20707)) then
+elseif self.UnitIsDead("mouseover") and  text.unitHasAura(self.GetSpellInfo(20707)) then
     return "Soulstoned"
-elseif UnitIsDead("mouseover") then
+elseif self.UnitIsDead("mouseover") then
     return "Dead"
 end
 ]],
-        updating = true
+        updating = true,
+		enabled = true
     },
     [11] = {
         name = "Health",
         left = 'return "Health:"',
         right = [[
-local text = StarTip:GetModule("Text")
-local health, maxHealth = UnitHealth("mouseover"), UnitHealthMax("mouseover")
+local health, maxHealth = self.UnitHealth("mouseover"), self.UnitHealthMax("mouseover")
 local value
 if maxHealth == 100 then
     value = health .. "%"
 elseif maxHealth ~= 0 then
-    value = format("%s/%s (%d%%)", text.short(health), text.short(maxHealth), health/maxHealth*100)
+    value = format("%s/%s (%d%%)", self.short(health), self.short(maxHealth), health/maxHealth*100)
 end
 return value
 ]],
-        updating = true
+        updating = true,
+		enabled = true
     },
     [12] = {
         name = "Mana",
         left = [[
-local text = StarTip:GetModule("Text")

-local class = select(2, UnitClass("mouseover"))
-if not UnitIsPlayer("mouseover") then
+local class = select(2, self.UnitClass("mouseover"))
+if not self.UnitIsPlayer("mouseover") then
 	class = "MAGE"
 end

-return text.powers[class] or "Mana:"
+return self.powers[class] or "Mana:"
 ]],
         right = [[
-local text = StarTip:GetModule("Text")
-local mana = UnitMana("mouseover")
-local maxMana = UnitManaMax("mouseover")
+local mana = self.UnitMana("mouseover")
+local maxMana = self.UnitManaMax("mouseover")
 if maxMana == 100 then
     value = mana
 elseif maxMana ~= 0 then
-    value = format("%s/%s (%d%%)", text.short(mana), text.short(maxMana), mana/maxMana*100)
+    value = format("%s/%s (%d%%)", self.short(mana), self.short(maxMana), mana/maxMana*100)
 end
 return value
 ]],
-        updating = true
+        updating = true,
+		enabled = true
     },
     [13] = {
         name = "Location",
         left = 'return "Location:"',
         right = [[
-local text = StarTip:GetModule("Text")
-return text.unitLocation
+return self.unitLocation
 ]],
-        updating = true
+        updating = true,
+		enabled = true
     },
 }

@@ -366,6 +379,7 @@ function mod:OnInitialize()
 					vv.right = v.right
 					v.rightDirty = nil
 				end
+				v.tagged = true
 			end
 		end
 	end
@@ -375,7 +389,13 @@ function mod:OnInitialize()
 			tinsert(self.db.profile.lines, v)
 		end
 	end
-
+
+	if self.db.profile.empty then
+		for i, v in ipairs(defaultLines) do
+			tinsert(self.db.profile.lines, v)
+		end
+		self.db.profile.empty = false
+	end
     self.leftLines = StarTip.leftLines
     self.rightLines = StarTip.rightLines
     self:RegisterEvent("UPDATE_FACTION")
@@ -417,13 +437,13 @@ function mod:CreateLines()
         for i, v in ipairs(self) do
                 local left, right, c
                 if v.right then
-                    right, c = executeCode(v.name, v.right)
-                    left = executeCode(v.name, v.left)
+                    right, c = StarTip.executeCode(v.name, v.right)
+                    left = StarTip.executeCode(v.name, v.left)
                 else
                     right = ''
-                    left, c = executeCode(v.name, v.left)
+                    left, c = StarTip.executeCode(v.name, v.left)
                 end
-                if left and right and v.enabled then
+                if left and right then
                     lineNum = lineNum + 1
                     if v.right then
 						GameTooltip:AddDoubleLine(' ', ' ', 1, 1, 1, 1, 1, 1)
@@ -594,14 +614,6 @@ function mod:RebuildOpts()
 					end,
 					order = 6
 				},
-				enabled = {
-					name = "Enabled",
-					desc = "Whether this line is enabled or not",
-					type = "toggle",
-					get = function() return self.db.profile.lines[i].enabled end,
-					set = function(info, v) self.db.profile.lines[i].enabled = v end,
-					order = 7
-				},
 				delete = {
 					name = "Delete",
 					desc = "Delete this line",
@@ -612,7 +624,7 @@ function mod:RebuildOpts()
 						StarTip:RebuildOpts()
 						self:CreateLines()
 					end,
-					order = 8
+					order = 7
 				},
             },
             order = i + 5
diff --git a/StarTip.lua b/StarTip.lua
index 038e004..61c1037 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -162,6 +162,18 @@ local function errorhandler(err)
     return geterrorhandler()(err)
 end

+local function copy(tbl)
+	local localCopy = {}
+	for k, v in pairs(tbl) do
+		if type(v) == "table" then
+			localCopy[k] = copy(v)
+		elseif type(v) ~= "function" then
+			localCopy[k] = v
+		end
+	end
+	return localCopy
+end
+
 do
 	local pool = setmetatable({},{__mode='v'})
 	StarTip.executeCode = function(tag, code, data)
@@ -183,7 +195,6 @@ do
 		end

 		local table = {self = StarTip:GetModule("Text"), _G = _G, StarTip = StarTip, select = select, format = format}
-		_G.self = table.self

 		setfenv(runnable, table)