Mercurial > wow > recipeprofit
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 6:afd4f9b9748d | 7:6d25e5522e0f |
|---|---|
| 12 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--)) | 12 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--)) |
| 13 | 13 |
| 14 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") | 14 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit") |
| 15 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") | 15 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") |
| 16 local tabletest = {} | 16 local tabletest = {} |
| 17 local db = {} | 17 db = {} |
| 18 local safeRecipes = {} | 18 local safeRecipes = {} |
| 19 safer = safeRecipes | 19 safer = safeRecipes |
| 20 RecipeProfit.db = db; | 20 RecipeProfit.db = db; |
| 21 | 21 |
| 22 local function deepcopy(object) | |
| 23 local lookup_table = {} | |
| 24 local function _copy(object) | |
| 25 if type(object) ~= "table" then | |
| 26 return object | |
| 27 elseif lookup_table[object] then | |
| 28 return lookup_table[object] | |
| 29 end | |
| 30 local new_table = {} | |
| 31 lookup_table[object] = new_table | |
| 32 for index, value in pairs(object) do | |
| 33 new_table[_copy(index)] = _copy(value) | |
| 34 end | |
| 35 return setmetatable(new_table, getmetatable(object)) | |
| 36 end | |
| 37 return _copy(object) | |
| 38 end | |
| 22 | 39 |
| 23 function debugprint(val, indent) | 40 function debugprint(val, indent) |
| 24 indent = indent or ""; | 41 indent = indent or ""; |
| 25 if not(type(val) == "table") then | 42 if not(type(val) == "table") then |
| 26 print("Not table: " .. val) | 43 print("Not table: " .. val) |
| 41 else | 58 else |
| 42 print(indent .. k .. " = " .. v) | 59 print(indent .. k .. " = " .. v) |
| 43 end | 60 end |
| 44 end | 61 end |
| 45 end | 62 end |
| 63 local defaultProfile = { | |
| 64 ["show"] = { | |
| 65 ["RecipeProfit"] = "always", | |
| 66 ["Herb Gathering"] = "never", | |
| 67 ["Extract Gas"] = "never", | |
| 68 ["Fishing"] = "never", | |
| 69 ["Mining"] = "never", | |
| 70 ["Treasure"] = "never", | |
| 71 }, | |
| 72 ["trackShow"] = "never", | |
| 73 } | |
| 46 | 74 |
| 47 local options = { | 75 local options = { |
| 48 type = "group", | 76 type = "group", |
| 49 name = "RecipeProfit", -- addon name to import from, don't localize | 77 name = "RecipeProfit", -- addon name to import from, don't localize |
| 50 handler = {}, | 78 handler = {}, |
| 74 order = 1, | 102 order = 1, |
| 75 name = "Safe Recipe Buy", | 103 name = "Safe Recipe Buy", |
| 76 desc = "Warn when buying a recipe not on the RecipeProfit list.", | 104 desc = "Warn when buying a recipe not on the RecipeProfit list.", |
| 77 type = "select", | 105 type = "select", |
| 78 values = { | 106 values = { |
| 79 ["on"] = "On", | 107 --["on"] = "On", |
| 80 ["off"]= "Off", | 108 ["off"]= "Off", |
| 81 }, | 109 }, |
| 82 arg = "safebuy", | 110 arg = "safebuy", |
| 83 }, | 111 }, |
| 84 }, | 112 }, |
| 92 type = "execute", | 120 type = "execute", |
| 93 func = function() | 121 func = function() |
| 94 RecipeProfit:DoMerge() | 122 RecipeProfit:DoMerge() |
| 95 end | 123 end |
| 96 }, | 124 }, |
| 125 loadProfile = { | |
| 126 order = 9, | |
| 127 name = "Load RecipeProfit Profile", | |
| 128 desc = "Loads the RecipeProfit Profile into Gathermate for easy recipe tracking.", | |
| 129 type = "execute", | |
| 130 func = function() | |
| 131 GatherMate.db.profiles["RecipeProfit"] = GatherMate.db.profiles["RecipeProfit"] or {} | |
| 132 gmdb = GatherMate.db.profiles["RecipeProfit"] | |
| 133 for k, v in pairs(defaultProfile) do | |
| 134 gmdb[k] = v; | |
| 135 end | |
| 136 GatherMate:SendMessage("OnProfileChanged"); | |
| 137 GatherMate:GetModule("Config"):UpdateConfig() | |
| 138 GatherMate:SendMessage("GatherMateConfigChanged") | |
| 139 GatherMate.db:SetProfile("RecipeProfit") | |
| 140 end | |
| 141 }, | |
| 97 } | 142 } |
| 98 } | 143 } |
| 99 | 144 |
| 100 local defaults = { | 145 local defaults = { |
| 101 faction = "default", | 146 faction = "default", |
| 102 safebuy = "on", | 147 safebuy = "on", |
| 103 } | 148 } |
| 104 | 149 |
| 105 function RecipeProfit:OnInitialize() | 150 function RecipeProfit:OnInitialize() |
| 106 profile = profile or defaults | 151 profile = profile or defaults |
| 152 | |
| 107 for k, v in pairs(defaults) do | 153 for k, v in pairs(defaults) do |
| 108 profile[k] = profile[k] or v; | 154 profile[k] = profile[k] or v; |
| 109 end | 155 end |
| 110 | 156 |
| 111 db.profile = profile | 157 db.profile = profile |
| 163 else | 209 else |
| 164 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor()); | 210 buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor()); |
| 165 end | 211 end |
| 166 end) | 212 end) |
| 167 | 213 |
| 168 RecipeProfit:DoMerge() | 214 |
| 169 end | 215 end |
| 216 | |
| 217 RecipeProfit:DoMerge() | |
| 170 end | 218 end |
| 171 | 219 |
| 172 local ids = {} | 220 local ids = {} |
| 173 function findGoodId(x, y) | 221 function findGoodId(x, y) |
| 174 if ids[x.." "..y] then | 222 if ids[x.." "..y] then |
| 179 return x, y | 227 return x, y |
| 180 end | 228 end |
| 181 | 229 |
| 182 function RecipeProfit:DoMerge() | 230 function RecipeProfit:DoMerge() |
| 183 ids = {} | 231 ids = {} |
| 184 selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or | 232 selectedDB = (db.profile.faction == "Alliance" or |
| 185 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and | 233 db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance") and |
| 186 RECIPEPROFIT_alliance or RECIPEPROFIT_horde | 234 RECIPEPROFIT_alliance or RECIPEPROFIT_horde |
| 187 GatherMate:ClearDB("RecipeProfit") | 235 GatherMate:ClearDB("RecipeProfit") |
| 188 for id, note in pairs(selectedDB) do | 236 for id, note in pairs(selectedDB) do |
| 189 x, y = findGoodId(note.x, note.y) | 237 x, y = findGoodId(note.x, note.y) |
| 190 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", | 238 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", |
| 191 note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")") | 239 note.item.." - ("..note.vendor.." ".. |
| 240 ((db.profile.faction == "Alliance" or db.profile.faction == "default" and | |
| 241 UnitFactionGroup("player") == "Alliance") and "A" or "H") ..")") | |
| 192 end | 242 end |
| 193 | 243 |
| 194 GatherMate:SendMessage("GatherMateDataImport") | 244 GatherMate:SendMessage("GatherMateDataImport") |
| 195 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") | 245 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") |
| 196 end | 246 end |
