annotate core.lua @ 7:6d25e5522e0f

Added support for GatherMate profiles, more bugfixes.
author Aaron Bregger
date Thu, 12 Aug 2010 11:58:58 -0500
parents cea137e9e8f0
children 5a0fa30712da
rev   line source
Aaron@4 1 --[[--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 2
Aaron@4 3 RecipeProfit by -[@project-author@]-
Aaron@4 4
Aaron@4 5 Rev: @project-revision@
Aaron@4 6 Updated: @file-date-iso@
Aaron@4 7
Aaron@4 8 --))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 9
Aaron@4 10 http://www.wrathguides.com/
Aaron@4 11
Aaron@4 12 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
Aaron@4 13
Aaron@4 14 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
Aaron@0 15 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
Aaron@0 16 local tabletest = {}
Aaron@7 17 db = {}
Aaron@1 18 local safeRecipes = {}
Aaron@1 19 safer = safeRecipes
Aaron@0 20 RecipeProfit.db = db;
Aaron@0 21
Aaron@7 22 local function deepcopy(object)
Aaron@7 23 local lookup_table = {}
Aaron@7 24 local function _copy(object)
Aaron@7 25 if type(object) ~= "table" then
Aaron@7 26 return object
Aaron@7 27 elseif lookup_table[object] then
Aaron@7 28 return lookup_table[object]
Aaron@7 29 end
Aaron@7 30 local new_table = {}
Aaron@7 31 lookup_table[object] = new_table
Aaron@7 32 for index, value in pairs(object) do
Aaron@7 33 new_table[_copy(index)] = _copy(value)
Aaron@7 34 end
Aaron@7 35 return setmetatable(new_table, getmetatable(object))
Aaron@7 36 end
Aaron@7 37 return _copy(object)
Aaron@7 38 end
Aaron@1 39
Aaron@0 40 function debugprint(val, indent)
Aaron@0 41 indent = indent or "";
Aaron@0 42 if not(type(val) == "table") then
Aaron@0 43 print("Not table: " .. val)
Aaron@0 44 return
Aaron@0 45 end
Aaron@0 46
Aaron@0 47 for k,v in pairs(val) do
Aaron@0 48 if(type(k) == "table" and type(v) == "table") then
Aaron@0 49 print(indent .. "table key: {")
Aaron@0 50 debugprint(k, indent .. " ")
Aaron@0 51 print(indent .. "} = {")
Aaron@0 52 debugprint(v, indent .. " ")
Aaron@0 53 print(indent .. "}")
Aaron@0 54 elseif(type(v) == "table") then
Aaron@0 55 print(indent .. k .. " = {")
Aaron@0 56 debugprint(v, indent .. " ")
Aaron@0 57 print(indent .. "}")
Aaron@0 58 else
Aaron@0 59 print(indent .. k .. " = " .. v)
Aaron@0 60 end
Aaron@0 61 end
Aaron@0 62 end
Aaron@7 63 local defaultProfile = {
Aaron@7 64 ["show"] = {
Aaron@7 65 ["RecipeProfit"] = "always",
Aaron@7 66 ["Herb Gathering"] = "never",
Aaron@7 67 ["Extract Gas"] = "never",
Aaron@7 68 ["Fishing"] = "never",
Aaron@7 69 ["Mining"] = "never",
Aaron@7 70 ["Treasure"] = "never",
Aaron@7 71 },
Aaron@7 72 ["trackShow"] = "never",
Aaron@7 73 }
Aaron@0 74
Aaron@0 75 local options = {
Aaron@0 76 type = "group",
Aaron@0 77 name = "RecipeProfit", -- addon name to import from, don't localize
Aaron@0 78 handler = {},
Aaron@0 79 disabled = false,
Aaron@0 80 args = {
Aaron@1 81 opt = {
Aaron@0 82 order = 1,
Aaron@0 83 name = "Select Database",
Aaron@0 84 desc = "Show a different database",
Aaron@0 85 type = "group",
Aaron@0 86 guiInline = true,
Aaron@0 87 args = {
Aaron@0 88 faction = {
Aaron@0 89 order = 0,
Aaron@0 90 name = "Faction",
Aaron@0 91 desc = "Show a different database.",
Aaron@0 92 type = "select",
Aaron@0 93 values = {
Aaron@0 94 ["Alliance"] = "Alliance",
Aaron@0 95 ["Horde"] = "Horde",
Aaron@1 96 ["default"] = "Default",
Aaron@0 97 },
Aaron@0 98 arg = "faction",
Aaron@0 99 },
Aaron@1 100
Aaron@1 101 safeBuy = {
Aaron@1 102 order = 1,
Aaron@1 103 name = "Safe Recipe Buy",
Aaron@1 104 desc = "Warn when buying a recipe not on the RecipeProfit list.",
Aaron@1 105 type = "select",
Aaron@1 106 values = {
Aaron@7 107 --["on"] = "On",
Aaron@1 108 ["off"]= "Off",
Aaron@1 109 },
Aaron@1 110 arg = "safebuy",
Aaron@1 111 },
Aaron@0 112 },
Aaron@1 113 get = function(k) return db.profile[k.arg]; end,
Aaron@0 114 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end,
Aaron@0 115 },
Aaron@0 116 loadData = {
Aaron@0 117 order = 8,
Aaron@0 118 name = "Import Data",
Aaron@0 119 desc = "Load RecipeProfit and import the data to your database.",
Aaron@0 120 type = "execute",
Aaron@0 121 func = function()
Aaron@0 122 RecipeProfit:DoMerge()
Aaron@0 123 end
Aaron@0 124 },
Aaron@7 125 loadProfile = {
Aaron@7 126 order = 9,
Aaron@7 127 name = "Load RecipeProfit Profile",
Aaron@7 128 desc = "Loads the RecipeProfit Profile into Gathermate for easy recipe tracking.",
Aaron@7 129 type = "execute",
Aaron@7 130 func = function()
Aaron@7 131 GatherMate.db.profiles["RecipeProfit"] = GatherMate.db.profiles["RecipeProfit"] or {}
Aaron@7 132 gmdb = GatherMate.db.profiles["RecipeProfit"]
Aaron@7 133 for k, v in pairs(defaultProfile) do
Aaron@7 134 gmdb[k] = v;
Aaron@7 135 end
Aaron@7 136 GatherMate:SendMessage("OnProfileChanged");
Aaron@7 137 GatherMate:GetModule("Config"):UpdateConfig()
Aaron@7 138 GatherMate:SendMessage("GatherMateConfigChanged")
Aaron@7 139 GatherMate.db:SetProfile("RecipeProfit")
Aaron@7 140 end
Aaron@7 141 },
Aaron@0 142 }
Aaron@0 143 }
Aaron@0 144
Aaron@0 145 local defaults = {
Aaron@1 146 faction = "default",
Aaron@1 147 safebuy = "on",
Aaron@0 148 }
Aaron@0 149
Aaron@0 150 function RecipeProfit:OnInitialize()
Aaron@0 151 profile = profile or defaults
Aaron@7 152
Aaron@1 153 for k, v in pairs(defaults) do
Aaron@1 154 profile[k] = profile[k] or v;
Aaron@1 155 end
Aaron@1 156
Aaron@0 157 db.profile = profile
Aaron@0 158 db.storage = {}
Aaron@0 159
Aaron@0 160 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
Aaron@0 161 GatherMate:RegisterDBType("RecipeProfit", db.storage)
Aaron@0 162 GatherMate.db.profile.show["RecipeProfit"] = "always"
Aaron@0 163 GatherMate.nodeIDs["RecipeProfit"] = {}
Aaron@0 164 GatherMate.nodeTextures["RecipeProfit"] = {}
Aaron@0 165 GatherMate.nodeMinHarvest["RecipeProfit"] = {}
Aaron@0 166 nodes = GatherMate.nodeIDs["RecipeProfit"]
Aaron@0 167
Aaron@0 168 for id, note in pairs(RECIPEPROFIT_alliance) do
Aaron@1 169 safeRecipes[note.item] = true;
Aaron@0 170 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10
Aaron@0 171 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 172 end
Aaron@0 173
Aaron@0 174 for id, note in pairs(RECIPEPROFIT_horde) do
Aaron@1 175 safeRecipes[note.item] = true;
Aaron@0 176 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1
Aaron@0 177 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05"
Aaron@0 178 end
Aaron@0 179
Aaron@0 180 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
Aaron@0 181 GatherMate:GetModule("Config"):UpdateConfig()
Aaron@0 182
Aaron@0 183 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 184 end
Aaron@0 185
Aaron@0 186 function RecipeProfit:OnEnable()
Aaron@1 187 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
Aaron@1 188 local buttonframe = _G["MerchantItem"..i];
Aaron@1 189 buttonframe:HookScript("OnUpdate", function(self)
Aaron@1 190 local buttonName = _G[self:GetName().."Name"];
Aaron@1 191 local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
Aaron@2 192 if(not link) then
Aaron@2 193 return;
Aaron@2 194 end
Aaron@2 195
Aaron@1 196 local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
Aaron@1 197
Aaron@1 198 if(sType == "Recipe" and safeRecipes[sName]) then
Aaron@1 199 SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
Aaron@1 200 SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
Aaron@2 201 buttonName:SetText("* " .. sName)
Aaron@1 202 if(GetItemCount(link, true) == 0) then
Aaron@1 203 buttonName:SetTextColor(0,1,1);
Aaron@1 204 elseif(GetItemCount(link, true) < 5) then
Aaron@1 205 buttonName:SetTextColor(1,0,1);
Aaron@1 206 else
Aaron@1 207 buttonName:SetTextColor(1,0,0);
Aaron@1 208 end
Aaron@1 209 else
Aaron@1 210 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor());
Aaron@1 211 end
Aaron@1 212 end)
Aaron@1 213
Aaron@7 214
Aaron@1 215 end
Aaron@7 216
Aaron@7 217 RecipeProfit:DoMerge()
Aaron@0 218 end
Aaron@0 219
Aaron@0 220 local ids = {}
Aaron@0 221 function findGoodId(x, y)
Aaron@0 222 if ids[x.." "..y] then
Aaron@0 223 return findGoodId(x + .01, y)
Aaron@0 224 end
Aaron@0 225
Aaron@0 226 ids[x.." "..y] = true
Aaron@0 227 return x, y
Aaron@0 228 end
Aaron@0 229
Aaron@0 230 function RecipeProfit:DoMerge()
Aaron@0 231 ids = {}
Aaron@7 232 selectedDB = (db.profile.faction == "Alliance" or
Aaron@7 233 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance") and
Aaron@1 234 RECIPEPROFIT_alliance or RECIPEPROFIT_horde
Aaron@0 235 GatherMate:ClearDB("RecipeProfit")
Aaron@1 236 for id, note in pairs(selectedDB) do
Aaron@0 237 x, y = findGoodId(note.x, note.y)
Aaron@0 238 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit",
Aaron@7 239 note.item.." - ("..note.vendor.." "..
Aaron@7 240 ((db.profile.faction == "Alliance" or db.profile.faction == "default" and
Aaron@7 241 UnitFactionGroup("player") == "Alliance") and "A" or "H") ..")")
Aaron@0 242 end
Aaron@0 243
Aaron@0 244 GatherMate:SendMessage("GatherMateDataImport")
Aaron@0 245 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
Aaron@0 246 end