Mercurial > wow > recipeprofit
comparison core.lua @ 17:22686cb65c51
Cached NPCs functioning. No data submission yet. Own data has been added to Location cache. Major Refactor of Core.lua :)
| author | Aaron@Aaron-PC |
|---|---|
| date | Mon, 16 Aug 2010 23:07:50 -0500 |
| parents | 8a18dd9f2cec |
| children | 1da3cd643786 |
comparison
equal
deleted
inserted
replaced
| 16:8a18dd9f2cec | 17:22686cb65c51 |
|---|---|
| 16 local tabletest = {} | 16 local tabletest = {} |
| 17 local db = {} | 17 local db = {} |
| 18 local safeRecipes = {} | 18 local safeRecipes = {} |
| 19 local ids = {} | 19 local ids = {} |
| 20 | 20 |
| 21 local profile | |
| 22 | |
| 21 RecipeProfit.db = db; | 23 RecipeProfit.db = db; |
| 22 | 24 |
| 23 -- Forward Definitions (for local functions) | 25 --[[ Forward Definitions (for local functions) ]] |
| 24 local get_faction_db, | 26 local get_faction_db, |
| 25 add_note, | 27 add_note, |
| 26 button_update, | 28 button_update, |
| 27 find_good_id, | 29 find_good_id, |
| 28 safe_cache_vendor, | 30 safe_cache_vendor, |
| 29 get_note_title; | 31 get_note_title, |
| 30 | 32 get_next_texture_id, |
| 33 set_node_constants, | |
| 34 inject_options; | |
| 35 | |
| 36 --[[ Deep table inspection for debugging ]] | |
| 31 function debugprint(val, indent) | 37 function debugprint(val, indent) |
| 32 indent = indent or ""; | 38 indent = indent or ""; |
| 33 if not(type(val) == "table") then | 39 if not(type(val) == "table") then |
| 34 print("Not table: " .. val) | 40 print("Not table: " .. val) |
| 35 return | 41 return |
| 146 enable_cache = false, | 152 enable_cache = false, |
| 147 location_cache = {}, | 153 location_cache = {}, |
| 148 } | 154 } |
| 149 | 155 |
| 150 function RecipeProfit:OnInitialize() | 156 function RecipeProfit:OnInitialize() |
| 151 profile = profile or defaults | 157 profile = RECIPEPROFIT_profile or defaults |
| 152 | 158 |
| 153 for k, v in pairs(defaults) do | 159 for k, v in pairs(defaults) do |
| 154 profile[k] = profile[k] or v; | 160 profile[k] = profile[k] or v; |
| 155 end | 161 end |
| 156 | 162 |
| 162 db.storage = {} | 168 db.storage = {} |
| 163 | 169 |
| 164 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) | 170 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options) |
| 165 GatherMate:RegisterDBType("RecipeProfit", db.storage) | 171 GatherMate:RegisterDBType("RecipeProfit", db.storage) |
| 166 GatherMate.db.profile.show["RecipeProfit"] = GatherMate.db.profile.show["RecipeProfit"] or "always" | 172 GatherMate.db.profile.show["RecipeProfit"] = GatherMate.db.profile.show["RecipeProfit"] or "always" |
| 167 GatherMate.nodeIDs["RecipeProfit"] = {} | 173 |
| 168 GatherMate.nodeTextures["RecipeProfit"] = {} | 174 set_node_constants() |
| 169 GatherMate.nodeMinHarvest["RecipeProfit"] = {} | 175 inject_options() |
| 170 local nodes = GatherMate.nodeIDs["RecipeProfit"] | |
| 171 | |
| 172 for id, note in pairs(RECIPEPROFIT_alliance) do | |
| 173 safeRecipes[note.item] = true; | |
| 174 nodes[get_note_title(note, "A")] = id * 2 | |
| 175 GatherMate.nodeTextures["RecipeProfit"][id * 2] = "Interface\\Icons\\INV_Scroll_05" | |
| 176 end | |
| 177 | |
| 178 for id, note in pairs(RECIPEPROFIT_horde) do | |
| 179 safeRecipes[note.item] = true; | |
| 180 nodes[get_note_title(note, "H")] = (id - 1) * 2 + 1 | |
| 181 GatherMate.nodeTextures["RecipeProfit"][(id - 1) * 2 + 1] = "Interface\\Icons\\INV_Scroll_05" | |
| 182 end | |
| 183 | |
| 184 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) | |
| 185 | |
| 186 GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = { | |
| 187 order = 6, | |
| 188 name = "Show RecipeProfit nodes.", | |
| 189 desc = "Toggle showing nodes added by RecipeProfit.", | |
| 190 type = "select", | |
| 191 values = { | |
| 192 ["always"] = "Always show", | |
| 193 ["never"] = "Never show", | |
| 194 }, | |
| 195 arg = "RecipeProfit", | |
| 196 } | |
| 197 | |
| 198 GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = { | |
| 199 order = 6.5, | |
| 200 name = "RecipeProfit", | |
| 201 desc = "Color of the tracking circle.", | |
| 202 type = "color", | |
| 203 hasAlpha = true, | |
| 204 arg = "RecipeProfit", | |
| 205 } | |
| 206 | 176 |
| 207 GatherMate:GetModule("Config"):UpdateConfig() | 177 GatherMate:GetModule("Config"):UpdateConfig() |
| 208 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") | 178 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") |
| 209 end | 179 end |
| 180 | |
| 181 | |
| 182 function RecipeProfit:OnEnable() | |
| 183 | |
| 184 _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons) | |
| 185 _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons) | |
| 186 | |
| 187 self:RegisterEvent("MERCHANT_SHOW", "UpdateButtons") | |
| 188 self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons") | |
| 189 self:RegisterEvent("BAG_UPDATE", "UpdateButtons") | |
| 190 | |
| 191 RecipeProfit:DoMerge() | |
| 192 end | |
| 210 | 193 |
| 211 function RecipeProfit:ShowOptions() | 194 function RecipeProfit:ShowOptions() |
| 212 LibStub("AceConfigDialog-3.0"):Open("GatherMate") | 195 LibStub("AceConfigDialog-3.0"):Open("GatherMate") |
| 213 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate", "RecipeProfit") | 196 LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate", "RecipeProfit") |
| 214 end | 197 end |
| 226 --print(index) | 209 --print(index) |
| 227 if index <= GetMerchantNumItems() then | 210 if index <= GetMerchantNumItems() then |
| 228 button_update(buttonframe) | 211 button_update(buttonframe) |
| 229 end | 212 end |
| 230 end | 213 end |
| 231 end | 214 end |
| 232 | |
| 233 | |
| 234 function RecipeProfit:OnEnable() | |
| 235 | |
| 236 _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons) | |
| 237 _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons) | |
| 238 | |
| 239 self:RegisterEvent("MERCHANT_SHOW", "UpdateButtons") | |
| 240 self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons") | |
| 241 self:RegisterEvent("BAG_UPDATE", "UpdateButtons") | |
| 242 | |
| 243 RecipeProfit:DoMerge() | |
| 244 end | |
| 245 | 215 |
| 246 function RecipeProfit:DoMerge() | 216 function RecipeProfit:DoMerge() |
| 247 ids = {} | 217 ids = {} |
| 248 local selectedDB = get_faction_db(); | 218 local selectedDB = get_faction_db(); |
| 249 | 219 |
| 324 end | 294 end |
| 325 | 295 |
| 326 ids[x.." "..y] = true | 296 ids[x.." "..y] = true |
| 327 return x, y | 297 return x, y |
| 328 end | 298 end |
| 299 | |
| 300 local lastNodeTextureId = 0; | |
| 301 | |
| 302 function get_next_texture_id() | |
| 303 lastNodeTextureId = lastNodeTextureId + 1; | |
| 304 return lastNodeTextureId; | |
| 305 end | |
| 306 | |
| 307 function set_node_constants() | |
| 308 GatherMate.nodeIDs["RecipeProfit"] = {} | |
| 309 GatherMate.nodeTextures["RecipeProfit"] = {} | |
| 310 GatherMate.nodeMinHarvest["RecipeProfit"] = {} | |
| 311 | |
| 312 local nodes = GatherMate.nodeIDs["RecipeProfit"] | |
| 313 for id, note in pairs(RECIPEPROFIT_alliance) do | |
| 314 safeRecipes[note.item] = true; | |
| 315 nodes[get_note_title(note, "A")] = get_next_texture_id() | |
| 316 end | |
| 317 | |
| 318 for id, note in pairs(RECIPEPROFIT_horde) do | |
| 319 safeRecipes[note.item] = true; | |
| 320 nodes[get_note_title(note, "H")] = get_next_texture_id() | |
| 321 end | |
| 322 | |
| 323 for i = 1, lastNodeTextureId, 1 do | |
| 324 GatherMate.nodeTextures["RecipeProfit"][i] = "Interface\\Icons\\INV_Scroll_05" | |
| 325 end | |
| 326 | |
| 327 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) | |
| 328 end | |
| 329 | |
| 330 function inject_options() | |
| 331 GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = { | |
| 332 order = 6, | |
| 333 name = "Show RecipeProfit nodes.", | |
| 334 desc = "Toggle showing nodes added by RecipeProfit.", | |
| 335 type = "select", | |
| 336 values = { | |
| 337 ["always"] = "Always show", | |
| 338 ["never"] = "Never show", | |
| 339 }, | |
| 340 arg = "RecipeProfit", | |
| 341 } | |
| 342 | |
| 343 GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = { | |
| 344 order = 6.5, | |
| 345 name = "RecipeProfit", | |
| 346 desc = "Color of the tracking circle.", | |
| 347 type = "color", | |
| 348 hasAlpha = true, | |
| 349 arg = "RecipeProfit", | |
| 350 } | |
| 351 end |
