Quantcast

Set and get variables directly

Adrian L Lange [08-15-09 - 17:50]
Set and get variables directly
Filename
Config.lua
pMinimap.lua
diff --git a/Config.lua b/Config.lua
index 2d018df..f5fc5b2 100644
--- a/Config.lua
+++ b/Config.lua
@@ -3,15 +3,15 @@
 local group, slider, dropdown, checkbox = LibStub('tekKonfig-Group'), LibStub('tekKonfig-Slider'), LibStub('tekKonfig-Dropdown'), LibStub('tekKonfig-Checkbox')

 local function updateStrings()
-	MiniMapMailText:SetFont(SharedMedia:Fetch('font', pMinimap.db.font), pMinimap.db.fontsize, pMinimap.db.fontflag)
-	MinimapZoneText:SetFont(SharedMedia:Fetch('font', pMinimap.db.font), pMinimap.db.fontsize, pMinimap.db.fontflag)
-	MinimapCoordinatesText:SetFont(SharedMedia:Fetch('font', pMinimap.db.font), pMinimap.db.fontsize, pMinimap.db.fontflag)
+	MiniMapMailText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
+	MinimapZoneText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
+	MinimapCoordinatesText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
 end

 local function dropStrata(orig)
 	local info = UIDropDownMenu_CreateInfo()
 	info.func = function(self)
-		pMinimap.db.strata = self.value
+		pMinimapDB.strata = self.value
 		Minimap:SetFrameStrata(self.value)
 		orig.text:SetText(self.value)
 	end
@@ -26,9 +26,9 @@ end
 local function dropZone(orig)
 	local info = UIDropDownMenu_CreateInfo()
 	info.func = function(self)
-		pMinimap.db.zonepoint = self.value
+		pMinimapDB.zonepoint = self.value
 		MinimapZoneTextButton:ClearAllPoints()
-		MinimapZoneTextButton:SetPoint(self.value == 'TOP' and 'BOTTOM' or 'TOP', Minimap, self.value, 0, pMinimap.db.zoneoffset)
+		MinimapZoneTextButton:SetPoint(self.value == 'TOP' and 'BOTTOM' or 'TOP', Minimap, self.value, 0, pMinimapDB.zoneoffset)
 		orig.text:SetText(self.value)
 	end

@@ -42,7 +42,7 @@ end
 local function dropFont(orig)
 	local info = UIDropDownMenu_CreateInfo()
 	info.func = function(self)
-		pMinimap.db.font = self.value
+		pMinimapDB.font = self.value
 		orig.text:SetText(self.value)
 		updateStrings()
 	end
@@ -57,7 +57,7 @@ end
 local function dropFontflag(orig)
 	local info = UIDropDownMenu_CreateInfo()
 	info.func = function(self)
-		pMinimap.db.fontflag = self.value
+		pMinimapDB.fontflag = self.value
 		updateStrings()
 		orig.text:SetText(self.value)
 	end
@@ -83,27 +83,27 @@ minimapgroup.name = 'Minimap'
 minimapgroup.parent = config.name
 minimapgroup.addonname = config.name
 minimapgroup:SetScript('OnShow', function(self)
-	local scale, scaletext = slider.new(self, format('Scale: %.2f', pMinimap.db.scale), 0.5, 2.5, 'TOPLEFT', self, 15, -15)
+	local scale, scaletext = slider.new(self, format('Scale: %.2f', pMinimapDB.scale), 0.5, 2.5, 'TOPLEFT', self, 15, -15)
 	scale:SetValueStep(0.01)
-	scale:SetValue(pMinimap.db.scale)
+	scale:SetValue(pMinimapDB.scale)
 	scale:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.scale = value
+		pMinimapDB.scale = value
 		scaletext:SetFormattedText('Scale: %.2f', value)
 		Minimap:SetScale(value)
 	end)

-	local level, leveltext = slider.new(self, 'Framelevel: '..pMinimap.db.level, 1, 15, 'TOPLEFT', scale, 'BOTTOMLEFT', 0, -30)
+	local level, leveltext = slider.new(self, 'Framelevel: '..pMinimapDB.level, 1, 15, 'TOPLEFT', scale, 'BOTTOMLEFT', 0, -30)
 	level:SetValueStep(1)
-	level:SetValue(pMinimap.db.level)
+	level:SetValue(pMinimapDB.level)
 	level:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.level = value
+		pMinimapDB.level = value
 		leveltext:SetFormattedText('Framelevel: %d', value)
 		pMinimap:SetFrameLevel(value)
 	end)

 	local strata, stratatext = dropdown.new(self, 'Framestrata', 'LEFT', scale, 'RIGHT', 40, 0)
 	strata.text = stratatext
-	strata.text:SetText(pMinimap.db.strata)
+	strata.text:SetText(pMinimapDB.strata)
 	UIDropDownMenu_Initialize(strata, dropStrata)

 	local lock = checkbox.new(self, 22, 'Locked', 'LEFT', level, 'RIGHT', 45, 0)
@@ -114,7 +114,7 @@ minimapgroup:SetScript('OnShow', function(self)
 		if(pMinimap.unlocked) then
 			Minimap:SetBackdropColor(0, 1, 0, 0.5)
 		else
-			Minimap:SetBackdropColor(unpack(pMinimap.db.bordercolors))
+			Minimap:SetBackdropColor(unpack(pMinimapDB.bordercolors))
 		end
 	end)

@@ -127,61 +127,61 @@ modulesgroup.parent = config.name
 modulesgroup.addonname = config.name
 modulesgroup:SetScript('OnShow', function(self)
 	local coordinates = checkbox.new(self, 22, 'Coordinates', 'TOPLEFT', self, 10, -10)
-	coordinates:SetChecked(pMinimap.db.coordinates)
+	coordinates:SetChecked(pMinimapDB.coordinates)
 	coordinates:SetScript('OnClick', function()
-		pMinimap.db.coordinates = not pMinimap.db.coordinates
+		pMinimapDB.coordinates = not pMinimapDB.coordinates

-		if(pMinimap.db.coordinates) then
+		if(pMinimapDB.coordinates) then
 			MinimapCoordinates:Show()
 			MinimapCoordinates:ClearAllPoints()
-			MinimapCoordinates:SetPoint(pMinimap.db.clock and 'BOTTOMRIGHT' or 'BOTTOM')
+			MinimapCoordinates:SetPoint(pMinimapDB.clock and 'BOTTOMRIGHT' or 'BOTTOM')
 		else
 			MinimapCoordinates:Hide()
 		end

-		if(pMinimap.db.clock) then
+		if(pMinimapDB.clock) then
 			TimeManagerClockButton:ClearAllPoints()
-			TimeManagerClockButton:SetPoint(pMinimap.db.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
+			TimeManagerClockButton:SetPoint(pMinimapDB.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
 		end
 	end)

-	local coordinatesdecimals, cdtext = slider.new(self, 'Coord Decimals: '..pMinimap.db.coordinatesdecimals, 0, 3, 'TOPRIGHT', self, -15, -15)
+	local coordinatesdecimals, cdtext = slider.new(self, 'Coord Decimals: '..pMinimapDB.coordinatesdecimals, 0, 3, 'TOPRIGHT', self, -15, -15)
 	coordinatesdecimals:SetValueStep(1)
-	coordinatesdecimals:SetValue(pMinimap.db.coordinatesdecimals)
+	coordinatesdecimals:SetValue(pMinimapDB.coordinatesdecimals)
 	coordinatesdecimals:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.coordinatesdecimals = value
+		pMinimapDB.coordinatesdecimals = value
 		cdtext:SetFormattedText('Coord Decimals: %d', value)
 	end)

 	local clock = checkbox.new(self, 22, 'Clock', 'TOPLEFT', coordinates, 'BOTTOMLEFT', 0, -10)
-	clock:SetChecked(pMinimap.db.clock)
+	clock:SetChecked(pMinimapDB.clock)
 	clock:SetScript('OnClick', function()
-		pMinimap.db.clock = not pMinimap.db.clock
+		pMinimapDB.clock = not pMinimapDB.clock

-		if(pMinimap.db.clock) then
+		if(pMinimapDB.clock) then
 			if(not pMinimap:IsEventRegistered('CALENDAR_UPDATE_PENDING_INVITES')) then
 				pMinimap:Clock()
 			else
 				TimeManagerClockButton:ClearAllPoints()
-				TimeManagerClockButton:SetPoint(pMinimap.db.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
+				TimeManagerClockButton:SetPoint(pMinimapDB.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
 				TimeManagerClockButton:Show()
 			end
 		else
 			TimeManagerClockButton:Hide()
 		end

-		if(pMinimap.db.coordinates) then
+		if(pMinimapDB.coordinates) then
 			MinimapCoordinates:ClearAllPoints()
-			MinimapCoordinates:SetPoint(pMinimap.db.clock and 'BOTTOMRIGHT' or 'BOTTOM')
+			MinimapCoordinates:SetPoint(pMinimapDB.clock and 'BOTTOMRIGHT' or 'BOTTOM')
 		end
 	end)

 	local mail = checkbox.new(self, 22, 'Mail', 'TOPLEFT', clock, 'BOTTOMLEFT', 0, -10)
-	mail:SetChecked(pMinimap.db.mail)
+	mail:SetChecked(pMinimapDB.mail)
 	mail:SetScript('OnClick', function()
-		pMinimap.db.mail = not pMinimap.db.mail
+		pMinimapDB.mail = not pMinimapDB.mail

-		if(pMinimap.db.mail) then
+		if(pMinimapDB.mail) then
 			MiniMapMailIcon:Hide()
 			MiniMapMailText:Show()
 		else
@@ -191,18 +191,18 @@ modulesgroup:SetScript('OnShow', function(self)
 	end)

 	local durability = checkbox.new(self, 22, 'Durability', 'LEFT', mail, 'RIGHT', 110, 0)
-	durability:SetChecked(pMinimap.db.durability)
+	durability:SetChecked(pMinimapDB.durability)
 	durability:SetScript('OnClick', function()
-		pMinimap.db.durability = not pMinimap.db.durability
+		pMinimapDB.durability = not pMinimapDB.durability

-		if(pMinimap.db.durability) then
+		if(pMinimapDB.durability) then
 			DurabilityFrame:SetAlpha(0)
 			pMinimap:RegisterEvent('UPDATE_INVENTORY_ALERTS')
 			pMinimap:UPDATE_INVENTORY_ALERTS()
 		else
 			DurabilityFrame:SetAlpha(1)
 			pMinimap:UnregisterEvent('UPDATE_INVENTORY_ALERTS')
-			Minimap:SetBackdropColor(unpack(pMinimap.db.bordercolors))
+			Minimap:SetBackdropColor(unpack(pMinimapDB.bordercolors))
 		end
 	end)

@@ -214,14 +214,14 @@ backgroundgroup.name = 'Background'
 backgroundgroup.parent = config.name
 backgroundgroup.addonname = config.name
 backgroundgroup:SetScript('OnShow', function(self)
-	local borderoffset, borderoffsettext = slider.new(self, 'Thickness: '..pMinimap.db.borderoffset, 0, 10, 'TOPLEFT', self, 15, -15)
+	local borderoffset, borderoffsettext = slider.new(self, 'Thickness: '..pMinimapDB.borderoffset, 0, 10, 'TOPLEFT', self, 15, -15)
 	borderoffset:SetValueStep(1/2)
-	borderoffset:SetValue(pMinimap.db.borderoffset)
+	borderoffset:SetValue(pMinimapDB.borderoffset)
 	borderoffset:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.borderoffset = value
+		pMinimapDB.borderoffset = value
 		borderoffsettext:SetFormattedText('Thickness: %.1f', value)
 		Minimap:SetBackdrop({bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = -value, bottom = -value, left = -value, right = -value}})
-		Minimap:SetBackdropColor(unpack(pMinimap.db.bordercolors))
+		Minimap:SetBackdropColor(unpack(pMinimapDB.bordercolors))
 	end)

 	-- todo: color palette
@@ -235,11 +235,11 @@ zonegroup.parent = config.name
 zonegroup.addonname = config.name
 zonegroup:SetScript('OnShow', function(self)
 	local zone = checkbox.new(self, 22, 'Zone Toggle', 'TOPLEFT', self, 10, -10)
-	zone:SetChecked(pMinimap.db.zone)
+	zone:SetChecked(pMinimapDB.zone)
 	zone:SetScript('OnClick', function()
-		pMinimap.db.zone = not pMinimap.db.zone
+		pMinimapDB.zone = not pMinimapDB.zone

-		if(pMinimap.db.zone) then
+		if(pMinimapDB.zone) then
 			MinimapZoneTextButton:Show()
 		else
 			MinimapZoneTextButton:Hide()
@@ -248,17 +248,17 @@ zonegroup:SetScript('OnShow', function(self)

 	local zonepoint, zonepointtext = dropdown.new(self, 'Zone Point', 'TOPLEFT', zone, 'BOTTOMLEFT')
 	zonepoint.text = zonepointtext
-	zonepoint.text:SetText(pMinimap.db.zonepoint)
+	zonepoint.text:SetText(pMinimapDB.zonepoint)
 	UIDropDownMenu_Initialize(zonepoint, dropZone)

-	local zoneoffset, zoneoffsettext = slider.new(self, 'Zone Offset: '..pMinimap.db.zoneoffset, -25, 25, 'TOPRIGHT', self, -15, -15)
+	local zoneoffset, zoneoffsettext = slider.new(self, 'Zone Offset: '..pMinimapDB.zoneoffset, -25, 25, 'TOPRIGHT', self, -15, -15)
 	zoneoffset:SetValueStep(1)
-	zoneoffset:SetValue(pMinimap.db.zoneoffset)
+	zoneoffset:SetValue(pMinimapDB.zoneoffset)
 	zoneoffset:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.zoneoffset = value
+		pMinimapDB.zoneoffset = value
 		zoneoffsettext:SetFormattedText('Zone Offset: %d', value)
 		MinimapZoneTextButton:ClearAllPoints()
-		MinimapZoneTextButton:SetPoint(pMinimap.db.zonepoint == 'TOP' and 'BOTTOM' or 'TOP', Minimap, pMinimap.db.zonepoint, 0, value)
+		MinimapZoneTextButton:SetPoint(pMinimapDB.zonepoint == 'TOP' and 'BOTTOM' or 'TOP', Minimap, pMinimapDB.zonepoint, 0, value)
 	end)

 	self:SetScript('OnShow', nil)
@@ -272,20 +272,20 @@ fontsgroup:SetScript('OnShow', function(self)
 	local font, fonttext, fontcontainer = dropdown.new(self, 'Font', 'TOPLEFT', self, 10, -4)
 	font:SetWidth(180)
 	font.text = fonttext
-	font.text:SetText(pMinimap.db.font)
+	font.text:SetText(pMinimapDB.font)
 	UIDropDownMenu_Initialize(font, dropFont)

 	local fontflag, fontflagtext = dropdown.new(self, 'Font Flag', 'BOTTOMLEFT', self, 10, 4)
 	fontflag:SetWidth(180)
 	fontflag.text = fontflagtext
-	fontflag.text:SetText(pMinimap.db.fontflag)
+	fontflag.text:SetText(pMinimapDB.fontflag)
 	UIDropDownMenu_Initialize(fontflag, dropFontflag)

-	local fontsize, fontsizetext = slider.new(self, 'Font Size'..pMinimap.db.fontsize, 5, 18, 'TOPRIGHT', self, -15, -15)
+	local fontsize, fontsizetext = slider.new(self, 'Font Size'..pMinimapDB.fontsize, 5, 18, 'TOPRIGHT', self, -15, -15)
 	fontsize:SetValueStep(1)
-	fontsize:SetValue(pMinimap.db.fontsize)
+	fontsize:SetValue(pMinimapDB.fontsize)
 	fontsize:SetScript('OnValueChanged', function(self, value)
-		pMinimap.db.fontsize = value
+		pMinimapDB.fontsize = value
 		fontsizetext:SetFormattedText('Font Size: %d', value)
 		updateStrings()
 	end)
diff --git a/pMinimap.lua b/pMinimap.lua
index 1f0ed91..00d2b8d 100644
--- a/pMinimap.lua
+++ b/pMinimap.lua
@@ -36,7 +36,7 @@ local defaults = {
 function addon:Clock()
 	TimeManagerClockButton:GetRegions():Hide()
 	TimeManagerClockButton:ClearAllPoints()
-	TimeManagerClockButton:SetPoint(self.db.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
+	TimeManagerClockButton:SetPoint(pMinimapDB.coordinates and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
 	TimeManagerClockButton:SetWidth(40)
 	TimeManagerClockButton:SetHeight(14)
 	TimeManagerClockButton:SetScript('OnShow', nil)
@@ -55,7 +55,7 @@ function addon:Clock()
 	end)

 	TimeManagerClockTicker:SetPoint('CENTER', TimeManagerClockButton)
-	TimeManagerClockTicker:SetFont(SharedMedia:Fetch('font', self.db.font), self.db.fontsize, self.db.fontflag)
+	TimeManagerClockTicker:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
 	TimeManagerClockTicker:SetShadowOffset(0, 0)

 	TimeManagerAlarmFiredTexture.Show = function() TimeManagerClockTicker:SetTextColor(1, 0, 0) end
@@ -127,11 +127,11 @@ function addon:Style()

 	MiniMapMailText = MiniMapMailFrame:CreateFontString(nil, 'OVERLAY')
 	MiniMapMailText:SetPoint('BOTTOM', 0, 2)
-	MiniMapMailText:SetFont(SharedMedia:Fetch('font', self.db.font), self.db.fontsize, self.db.fontflag)
+	MiniMapMailText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
 	MiniMapMailText:SetTextColor(1, 1, 1)
 	MiniMapMailText:SetText('New Mail!')

-	if(self.db.mail) then
+	if(pMinimapDB.mail) then
 		MiniMapMailIcon:Hide()
 	else
 		MiniMapMailText:Hide()
@@ -139,7 +139,7 @@ function addon:Style()

 	-- Coordinates
 	MinimapCoordinates = CreateFrame('Button', nil, Minimap)
-	MinimapCoordinates:SetPoint(self.db.clock and 'BOTTOMRIGHT' or 'BOTTOM')
+	MinimapCoordinates:SetPoint(pMinimapDB.clock and 'BOTTOMRIGHT' or 'BOTTOM')
 	MinimapCoordinates:SetWidth(40)
 	MinimapCoordinates:SetHeight(14)
 	MinimapCoordinates:RegisterForClicks('AnyUp')
@@ -149,24 +149,24 @@ function addon:Style()

 	MinimapCoordinatesText = MinimapCoordinates:CreateFontString(nil, 'OVERLAY')
 	MinimapCoordinatesText:SetPoint('BOTTOMRIGHT', MinimapCoordinates)
-	MinimapCoordinatesText:SetFont(SharedMedia:Fetch('font', self.db.font), self.db.fontsize, self.db.fontflag)
+	MinimapCoordinatesText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
 	MinimapCoordinatesText:SetTextColor(1, 1, 1)

-	if(not self.db.coordinates) then
+	if(not pMinimapDB.coordinates) then
 		MinimapCoordinates:Hide()
 	end

 	-- Zone text
 	MinimapZoneText:SetAllPoints(MinimapZoneTextButton)
-	MinimapZoneText:SetFont(SharedMedia:Fetch('font', self.db.font), self.db.fontsize, self.db.fontflag)
+	MinimapZoneText:SetFont(SharedMedia:Fetch('font', pMinimapDB.font), pMinimapDB.fontsize, pMinimapDB.fontflag)
 	MinimapZoneText:SetShadowOffset(0, 0)

 	MinimapZoneTextButton:ClearAllPoints()
 	MinimapZoneTextButton:SetParent(Minimap)
-	MinimapZoneTextButton:SetPoint(self.db.zonepoint == 'BOTTOM' and 'TOP' or 'BOTTOM', Minimap, self.db.zonepoint, 0, self.db.zoneoffset)
+	MinimapZoneTextButton:SetPoint(pMinimapDB.zonepoint == 'BOTTOM' and 'TOP' or 'BOTTOM', Minimap, pMinimapDB.zonepoint, 0, pMinimapDB.zoneoffset)
 	MinimapZoneTextButton:SetWidth(Minimap:GetWidth() * 1.5)

-	if(not self.db.zone) then
+	if(not pMinimapDB.zone) then
 		MinimapZoneTextButton:Hide()
 	end

@@ -180,12 +180,12 @@ function addon:Style()
 	GameTimeFrame:Hide()

 	-- Inject settings
-	Minimap:SetScale(self.db.scale)
-	Minimap:SetFrameLevel(self.db.level)
-	Minimap:SetFrameStrata(self.db.strata)
+	Minimap:SetScale(pMinimapDB.scale)
+	Minimap:SetFrameLevel(pMinimapDB.level)
+	Minimap:SetFrameStrata(pMinimapDB.strata)
 	Minimap:SetMaskTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
-	Minimap:SetBackdrop({bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = - self.db.borderoffset, bottom = - self.db.borderoffset, left = - self.db.borderoffset, right = - self.db.borderoffset}})
-	Minimap:SetBackdropColor(unpack(self.db.bordercolors))
+	Minimap:SetBackdrop({bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = - pMinimapDB.borderoffset, bottom = - pMinimapDB.borderoffset, left = - pMinimapDB.borderoffset, right = - pMinimapDB.borderoffset}})
+	Minimap:SetBackdropColor(unpack(pMinimapDB.bordercolors))

 	Minimap:RegisterForDrag('LeftButton')
 	Minimap:SetMovable(true)
@@ -194,7 +194,7 @@ function addon:Style()
 	MinimapCluster:EnableMouse(false)

 	-- Modules
-	if(self.db.durability) then
+	if(pMinimapDB.durability) then
 		DurabilityFrame:SetAlpha(0)

 		self:RegisterEvent('UPDATE_INVENTORY_ALERTS')
@@ -220,7 +220,7 @@ function addon:ADDON_LOADED(event, name)
 		SlashCmdList[name] = self.Command

 		self.unlocked = false
-		self.db = setmetatable(pMinimapDB or {}, {__index = defaults})
+		pMinimapDB = setmetatable(pMinimapDB or {}, {__index = defaults})
 		self:RegisterEvent('ZONE_CHANGED_NEW_AREA')
 		self:RegisterEvent('VARIABLES_LOADED')

@@ -229,7 +229,7 @@ function addon:ADDON_LOADED(event, name)
 		TimeManagerClockButton:SetScript('OnShow', function(self) self:Hide() end)
 		TimeManagerClockButton:Hide()

-		if(self.db.clock) then
+		if(pMinimapDB.clock) then
 			self:Clock()
 		end

@@ -262,7 +262,7 @@ function addon:UPDATE_INVENTORY_ALERTS()
 	if(color) then
 		Minimap:SetBackdropColor(color.r, color.g, color.b)
 	else
-		Minimap:SetBackdropColor(unpack(self.db.bordercolors))
+		Minimap:SetBackdropColor(unpack(pMinimapDB.bordercolors))
 	end
 end