Quantcast

New file - Utilities.lua. For now, all it has is ItemLinkToID (now a private method) and AddListEntry (also now a private method instead of an addon method). Various changes here and there.

James D. Callahan III [03-13-11 - 17:43]
New file - Utilities.lua. For now, all it has is ItemLinkToID (now a private method) and AddListEntry (also now a private method instead of an addon method). Various changes here and there.
Filename
AckisRecipeList.toc
Database/Custom.lua
Database/Mob.lua
Database/Quest.lua
Database/Reputation.lua
Database/Seasonal.lua
Database/Trainer.lua
Database/Vendor.lua
Scanner.lua
Utilities.lua
core.lua
diff --git a/AckisRecipeList.toc b/AckisRecipeList.toc
index e46f6d4..cdbb959 100644
--- a/AckisRecipeList.toc
+++ b/AckisRecipeList.toc
@@ -71,6 +71,7 @@ Config.lua
 Waypoint.lua
 Scanner.lua
 Player.lua
+Utilities.lua

 # User Interface files
 interface.xml
diff --git a/Database/Custom.lua b/Database/Custom.lua
index 8ba411b..8734fec 100644
--- a/Database/Custom.lua
+++ b/Database/Custom.lua
@@ -13,14 +13,25 @@ This source code is released under All Rights Reserved.
 ************************************************************************
 ]]--

-local MODNAME		= "Ackis Recipe List"
-local addon		= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L			= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
+local _G = getfenv(0)
+
+-----------------------------------------------------------------------
+-- AddOn namespace.
+-----------------------------------------------------------------------
+local FOLDER_NAME, private	= ...
+
+local LibStub = _G.LibStub
+
+local addon		= LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L			= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BZ		= LibStub("LibBabble-Zone-3.0"):GetLookupTable()

 function addon:InitCustom(DB)
 	local function AddCustom(identifier, location, coord_x, coord_y, faction)
-		addon:AddListEntry(DB, identifier, L[identifier], location, coord_x, coord_y, nil)
+		private:AddListEntry(DB, identifier, L[identifier], location, coord_x, coord_y, nil)
 	end
 	AddCustom("DISCOVERY_ALCH_ELIXIRFLASK")
 	AddCustom("DISCOVERY_ALCH_POTION")
diff --git a/Database/Mob.lua b/Database/Mob.lua
index c7f168a..d7b2589 100644
--- a/Database/Mob.lua
+++ b/Database/Mob.lua
@@ -12,16 +12,16 @@ Please see http://www.wowace.com/addons/arl/ for more information.
 This source code is released under All Rights Reserved.
 ************************************************************************
 ]]--
+local FOLDER_NAME, private = ...

-local MODNAME		= "Ackis Recipe List"
-local addon		= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L			= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+local addon		= LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L			= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BZ		= LibStub("LibBabble-Zone-3.0"):GetLookupTable()
 local BB		= LibStub("LibBabble-Boss-3.0"):GetLookupTable()

 function addon:InitMob(DB)
 	local function AddMob(mob_id, mob_name, zone, coord_x, coord_y)
-		addon:AddListEntry(DB, mob_id, mob_name, zone, coord_x, coord_y, nil)
+		private:AddListEntry(DB, mob_id, mob_name, zone, coord_x, coord_y, nil)
 	end

 	-- Arathi Highlands
diff --git a/Database/Quest.lua b/Database/Quest.lua
index 35a5807..a7ac7b5 100644
--- a/Database/Quest.lua
+++ b/Database/Quest.lua
@@ -13,33 +13,36 @@ This source code is released under All Rights Reserved.
 ************************************************************************
 ]]--

+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
 local _G = getfenv(0)

--------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 -- AddOn namespace.
--------------------------------------------------------------------------------
-local MODNAME	= "Ackis Recipe List"
-local addon	= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L		= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
-local BZ	= LibStub("LibBabble-Zone-3.0"):GetLookupTable()
-
--- Set up the private intra-file namespace.
+-----------------------------------------------------------------------
 local FOLDER_NAME, private	= ...

-------------------------------------------------------------------------------
+local LibStub = _G.LibStub
+
+local addon	= LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L		= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
+local BZ	= LibStub("LibBabble-Zone-3.0"):GetLookupTable()
+
+-----------------------------------------------------------------------
 -- Constants.
-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 local NEUTRAL	= 0
 local ALLIANCE	= 1
 local HORDE	= 2

-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 -- Memoizing table for quest names.
-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 private.quest_names = _G.setmetatable({}, {
 	__index = function(t, id_num)
-			  _G.GameTooltip:SetOwner(UIParent, ANCHOR_NONE)
-			  _G.GameTooltip:SetHyperlink("quest:"..tostring(id_num))
+			  _G.GameTooltip:SetOwner(_G.UIParent, _G.ANCHOR_NONE)
+			  _G.GameTooltip:SetHyperlink(("quest:%s"):format(_G.tostring(id_num)))

 			  local quest_name = _G["GameTooltipTextLeft1"]:GetText()
 			  _G.GameTooltip:Hide()
@@ -54,7 +57,7 @@ private.quest_names = _G.setmetatable({}, {

 function addon:InitQuest(DB)
 	local function AddQuest(quest_id, location, coord_x, coord_y, faction)
-		addon:AddListEntry(DB, quest_id, nil, location, coord_x, coord_y, faction)
+		private:AddListEntry(DB, quest_id, nil, location, coord_x, coord_y, faction)
 	end

 	AddQuest(384,	BZ["Dun Morogh"],		46.8,	52.5,	ALLIANCE)
diff --git a/Database/Reputation.lua b/Database/Reputation.lua
index 78a7b54..ab3a269 100644
--- a/Database/Reputation.lua
+++ b/Database/Reputation.lua
@@ -13,14 +13,25 @@ This source code is released under All Rights Reserved.
 ************************************************************************
 ]]--

-local MODNAME	= "Ackis Recipe List"
-local addon	= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L		= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
+local _G = getfenv(0)
+
+-----------------------------------------------------------------------
+-- AddOn namespace.
+-----------------------------------------------------------------------
+local FOLDER_NAME, private = ...
+
+local LibStub = _G.LibStub
+
+local addon	= LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L		= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BFAC	= LibStub("LibBabble-Faction-3.0"):GetLookupTable()

 function addon:InitReputation(DB)
 	local function AddReputation(rep_id, name)
-		addon:AddListEntry(DB, rep_id, name, nil, nil, nil, nil)
+		private:AddListEntry(DB, rep_id, name, nil, nil, nil, nil)
 	end
 	AddReputation(59, BFAC["Thorium Brotherhood"])
 	AddReputation(270, BFAC["Zandalar Tribe"])
diff --git a/Database/Seasonal.lua b/Database/Seasonal.lua
index 0e867fa..a833221 100644
--- a/Database/Seasonal.lua
+++ b/Database/Seasonal.lua
@@ -13,23 +13,30 @@ License:
 	Please see LICENSE.txt
 This source code is released under All Rights Reserved.
 ************************************************************************
-]]--
+]] --

--------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 -- Upvalued Lua API.
--------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 local _G = getfenv(0)

-local MODNAME		= "Ackis Recipe List"
-local addon		= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L			= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+-----------------------------------------------------------------------
+-- AddOn namespace.
+-----------------------------------------------------------------------
+local FOLDER_NAME, private = ...
+
+local LibStub = _G.LibStub
+
+local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L = LibStub("AceLocale-3.0"):GetLocale(private.addon_name)

 local GetCategoryInfo = _G.GetCategoryInfo

 function addon:InitSeasons(DB)
 	local function AddSeason(identifier, name)
-		addon:AddListEntry(DB, identifier, name, GetCategoryInfo(155))
+		private:AddListEntry(DB, identifier, name, GetCategoryInfo(155))
 	end
+
 	AddSeason("WINTER_VEIL", GetCategoryInfo(156))
 	AddSeason("LUNAR_FESTIVAL", GetCategoryInfo(160))
 	AddSeason("MIDSUMMER", GetCategoryInfo(161))
diff --git a/Database/Trainer.lua b/Database/Trainer.lua
index 0850ec4..85cc2f5 100644
--- a/Database/Trainer.lua
+++ b/Database/Trainer.lua
@@ -13,23 +13,32 @@ This source code is released under All Rights Reserved.
 ************************************************************************
 ]] --

+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
 local _G = getfenv(0)

-local MODNAME = "Ackis Recipe List"
-local addon = LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L = LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+-----------------------------------------------------------------------
+-- AddOn namespace.
+-----------------------------------------------------------------------
+local FOLDER_NAME, private = ...
+
+local LibStub = _G.LibStub
+
+local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L = LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BZ = LibStub("LibBabble-Zone-3.0"):GetLookupTable()

-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 -- Constants.
-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 local NEUTRAL = 0
 local ALLIANCE = 1
 local HORDE = 2

 function addon:InitTrainer(DB)
 	local function AddTrainer(id_num, name, location, coord_x, coord_y, faction)
-		addon:AddListEntry(DB, id_num, name, location, coord_x, coord_y, faction)
+		private:AddListEntry(DB, id_num, name, location, coord_x, coord_y, faction)
 	end

 	AddTrainer(514, L["Smith Argus"], BZ["Elwynn Forest"], 41.7, 65.6, ALLIANCE)
diff --git a/Database/Vendor.lua b/Database/Vendor.lua
index 87f45eb..aa30778 100644
--- a/Database/Vendor.lua
+++ b/Database/Vendor.lua
@@ -13,25 +13,33 @@ This source code is released under All Rights Reserved.
 ************************************************************************
 ]]--

--------------------------------------------------------------------------------
+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
+local _G = getfenv(0)
+
+-----------------------------------------------------------------------
 -- AddOn namespace.
--------------------------------------------------------------------------------
-local MODNAME	= "Ackis Recipe List"
-local addon	= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
-local L		= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+-----------------------------------------------------------------------
+local FOLDER_NAME, private	= ...
+
+local LibStub = _G.LibStub
+
+local addon	= LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local L		= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BZ	= LibStub("LibBabble-Zone-3.0"):GetLookupTable()
 local BB	= LibStub("LibBabble-Boss-3.0"):GetLookupTable()

-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 -- Constants.
-------------------------------------------------------------------------------
+-----------------------------------------------------------------------
 local NEUTRAL	= 0
 local ALLIANCE	= 1
 local HORDE	= 2

 function addon:InitVendor(DB)
 	local function AddVendor(id_num, name, zone, x, y, faction)
-		addon:AddListEntry(DB, id_num, name, zone, x, y, faction)
+		private:AddListEntry(DB, id_num, name, zone, x, y, faction)
 	end

 	AddVendor(66,		L["Tharynn Bouden"],			BZ["Elwynn Forest"],			41.9, 67.1, ALLIANCE)
diff --git a/Scanner.lua b/Scanner.lua
index 63e326c..6bf8e77 100644
--- a/Scanner.lua
+++ b/Scanner.lua
@@ -508,20 +508,6 @@ local NO_ROLE_FLAG = {
 	---------------------------------------------------------------------------------------
 }

-local function ItemLinkToID(item_link)
-	if not item_link then
-		return
-	end
-
-	local id = item_link:match("item:(%d+)")
-
-	if not id then
-		return
-	end
-	return tonumber(id)
-end
-
-
 local function LoadRecipe()
 	local recipe_list = private.recipe_list

@@ -619,7 +605,7 @@ do

 		for index = 1, _G.GetNumTrainerServices(), 1 do
 			local item_name = _G.GetTrainerServiceInfo(index)
-			local item_id = ItemLinkToID(_G.GetTrainerServiceItemLink(index))
+			local item_id = private.ItemLinkToID(_G.GetTrainerServiceItemLink(index))
 			local _, skill_level = _G.GetTrainerServiceSkillReq(index)

 			if not skill_level then
@@ -1091,7 +1077,7 @@ do
 				local match_text = string.match(item_name, "%a+: ")

 				if match_text and RECIPE_TYPES[match_text:lower()] then
-					local item_id = ItemLinkToID(_G.GetMerchantItemLink(index))
+					local item_id = private.ItemLinkToID(_G.GetMerchantItemLink(index))
 					local spell_id = RECIPE_ITEM_TO_SPELL_MAP[item_id]

 					if spell_id then
diff --git a/Utilities.lua b/Utilities.lua
new file mode 100644
index 0000000..4e80573
--- /dev/null
+++ b/Utilities.lua
@@ -0,0 +1,73 @@
+-----------------------------------------------------------------------
+-- Upvalued Lua API.
+-----------------------------------------------------------------------
+local _G = getfenv(0)
+
+local tonumber = _G.tonumber
+
+-----------------------------------------------------------------------
+-- AddOn namespace.
+-----------------------------------------------------------------------
+local FOLDER_NAME, private = ...
+
+local LibStub = _G.LibStub
+
+local addon = LibStub("AceAddon-3.0"):GetAddon(private.addon_name)
+local BFAC = LibStub("LibBabble-Faction-3.0"):GetLookupTable()
+
+-----------------------------------------------------------------------
+-- Methods.
+-----------------------------------------------------------------------
+do
+	local FACTION_NAMES = {
+		[1] = BFAC["Neutral"],
+		[2] = BFAC["Alliance"],
+		[3] = BFAC["Horde"]
+	}
+
+	function private:AddListEntry(lookup_list, identifier, name, location, coord_x, coord_y, faction)
+		if lookup_list[identifier] then
+			addon:Debug("Duplicate lookup: %s - %s.", identifier, name)
+			return
+		end
+
+		local entry = {
+			name = name,
+			location = location,
+		}
+		lookup_list[identifier] = entry
+
+		if faction then
+			entry.faction = FACTION_NAMES[faction + 1]
+		end
+
+		if coord_x and coord_y then
+			lookup_list[identifier].coord_x = coord_x
+			lookup_list[identifier].coord_y = coord_y
+		end
+
+		--@alpha@
+		if not location and lookup_list ~= private.custom_list and lookup_list ~= private.reputation_list then
+			addon:Debug("Lookup ID: %s (%s) has an unknown location.", identifier, lookup_list[identifier].name or _G.UNKNOWN)
+		end
+
+		if faction and lookup_list == private.mob_list then
+			addon:Debug("Mob %d (%s) has been assigned to faction %s.", identifier, name, lookup_list[identifier].faction)
+		end
+	--@end-alpha@
+	end
+end -- do
+
+function private.ItemLinkToID(item_link)
+	if not item_link then
+		return
+	end
+
+	local id = item_link:match("item:(%d+)")
+
+	if not id then
+		return
+	end
+	return tonumber(id)
+end
+
diff --git a/core.lua b/core.lua
index c3828d8..0774586 100644
--- a/core.lua
+++ b/core.lua
@@ -39,22 +39,21 @@ local table = _G.table
 -------------------------------------------------------------------------------
 -- AddOn namespace.
 -------------------------------------------------------------------------------
+local FOLDER_NAME, private = ...
+private.addon_name = "Ackis Recipe List"
+
 local LibStub	= _G.LibStub
-local MODNAME	= "Ackis Recipe List"
-local addon	= LibStub("AceAddon-3.0"):NewAddon(MODNAME, "AceConsole-3.0", "AceEvent-3.0")
+local addon	= LibStub("AceAddon-3.0"):NewAddon(private.addon_name, "AceConsole-3.0", "AceEvent-3.0")
 _G.AckisRecipeList = addon

 --@alpha@
 _G.ARL = addon
 --@end-alpha@

-local L		= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+local L		= LibStub("AceLocale-3.0"):GetLocale(private.addon_name)
 local BFAC 	= LibStub("LibBabble-Faction-3.0"):GetLookupTable()

-local debugger	= _G.tekDebug and _G.tekDebug:GetFrame(MODNAME)
-
--- Set up the private intra-file namespace.
-local private	= select(2, ...)
+local debugger	= _G.tekDebug and _G.tekDebug:GetFrame(private.addon_name)

 private.build_num = select(2, _G.GetBuildInfo())

@@ -844,55 +843,6 @@ do
 	end
 end

-do
-	local FACTION_NAMES = {
-		[1]	= BFAC["Neutral"],
-		[2]	= BFAC["Alliance"],
-		[3]	= BFAC["Horde"]
-	}
-
-	--- Adds an item to a specific database listing (ie: vendor, mob, etc)
-	-- @name AckisRecipeList:AddListEntry
-	-- @usage AckisRecipeList:AddListEntry(DB,NPC ID, NPC Name, NPC Location, X Coord, Y Coord, Faction)
-	-- @param DB Database which the entry will be stored
-	-- @param ID Unique identified for the entry
-	-- @param name Name of the entry
-	-- @param location Location of the entry in the world
-	-- @param coord_x X coordinate of where the entry is found
-	-- @param coord_y Y coordinate of where the entry is found
-	-- @param faction Faction identifier for the entry
-	-- @return None, array is passed as a reference
-	-- For individual database structures, see Documentation.lua
-	function addon:AddListEntry(lookup_list, identifier, name, location, coord_x, coord_y, faction)
-		if lookup_list[identifier] then
-			self:Debug("Duplicate lookup: %s - %s.", identifier, name)
-			return
-		end
-
-		local entry = {
-			["name"]	= name,
-			["location"]	= location,
-			["faction"]	= faction and FACTION_NAMES[faction + 1] or FACTION_NAMES[1]
-		}
-		lookup_list[identifier] = entry
-
-		if coord_x and coord_y then
-			lookup_list[identifier]["coord_x"] = coord_x
-			lookup_list[identifier]["coord_y"] = coord_y
-		end
-
-		--@alpha@
-		if not location and lookup_list ~= private.custom_list and lookup_list ~= private.reputation_list then
-			self:Debug("Lookup ID: %s (%s) has an unknown location.", identifier, lookup_list[identifier].name or _G.UNKNOWN)
-		end
-
-		if faction and lookup_list == private.mob_list then
-			self:Debug("Mob %d (%s) has been assigned to faction %s.", identifier, name, lookup_list[identifier].faction)
-		end
-		--@end-alpha@
-	end
-end	-- do
-
 -------------------------------------------------------------------------------
 -- ARL Logic Functions
 -------------------------------------------------------------------------------