Mercurial > wow > recipeprofit
diff core.lua @ 16:8a18dd9f2cec
Caching support...
| author | Aaron@Aaron-PC |
|---|---|
| date | Sun, 15 Aug 2010 17:59:03 -0500 |
| parents | 38822958c28a |
| children | 22686cb65c51 |
line wrap: on
line diff
--- a/core.lua Fri Aug 13 14:39:36 2010 -0500 +++ b/core.lua Sun Aug 15 17:59:03 2010 -0500 @@ -14,11 +14,20 @@ local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit", "AceEvent-3.0", "AceConsole-3.0") local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate") local tabletest = {} - db = {} +local db = {} local safeRecipes = {} -safer = safeRecipes +local ids = {} + RecipeProfit.db = db; +-- Forward Definitions (for local functions) +local get_faction_db, + add_note, + button_update, + find_good_id, + safe_cache_vendor, + get_note_title; + function debugprint(val, indent) indent = indent or ""; if not(type(val) == "table") then @@ -132,6 +141,10 @@ local defaults = { faction = "default", safebuy = "on", + + --submitting cached data not yet implemented + enable_cache = false, + location_cache = {}, } function RecipeProfit:OnInitialize() @@ -154,18 +167,18 @@ GatherMate.nodeIDs["RecipeProfit"] = {} GatherMate.nodeTextures["RecipeProfit"] = {} GatherMate.nodeMinHarvest["RecipeProfit"] = {} - nodes = GatherMate.nodeIDs["RecipeProfit"] + local nodes = GatherMate.nodeIDs["RecipeProfit"] for id, note in pairs(RECIPEPROFIT_alliance) do safeRecipes[note.item] = true; - nodes[note.item.." - ("..note.vendor.." A)"] = id * 10 - GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05" + nodes[get_note_title(note, "A")] = id * 2 + GatherMate.nodeTextures["RecipeProfit"][id * 2] = "Interface\\Icons\\INV_Scroll_05" end for id, note in pairs(RECIPEPROFIT_horde) do safeRecipes[note.item] = true; - nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1 - GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05" + nodes[get_note_title(note, "H")] = (id - 1) * 2 + 1 + GatherMate.nodeTextures["RecipeProfit"][(id - 1) * 2 + 1] = "Interface\\Icons\\INV_Scroll_05" end GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes) @@ -200,6 +213,84 @@ LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate", "RecipeProfit") end +function RecipeProfit:UpdateButtons(event, ...) + --print("UpdateButtons", event) + if(not MerchantFrame:IsVisible()) then + --print("UpdateButtons - (Event: ", event, ") - MerchantFrame not visible."); + return; + end + + for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do + local buttonframe = _G["MerchantItem"..i]; + local index = (((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i); + --print(index) + if index <= GetMerchantNumItems() then + button_update(buttonframe) + end + end +end + + +function RecipeProfit:OnEnable() + + _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons) + _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons) + + self:RegisterEvent("MERCHANT_SHOW", "UpdateButtons") + self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons") + self:RegisterEvent("BAG_UPDATE", "UpdateButtons") + + RecipeProfit:DoMerge() +end + +function RecipeProfit:DoMerge() + ids = {} + local selectedDB = get_faction_db(); + + GatherMate:ClearDB("RecipeProfit") + for id, note in pairs(selectedDB) do + x, y = find_good_id(note.x, note.y) + add_note(x, y, note) + end + + GatherMate:SendMessage("GatherMateDataImport") + GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") +end + +function get_note_title(note, factionTag) + if(not factionTag) then + _, factionTag = get_faction_db(); + end + + return note.item.." - ("..note.vendor.." ".. factionTag ..")"; +end + +function add_note(x, y, note) + GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", get_note_title(note)); +end + +function get_faction_db() + local factionAlliance = db.profile.faction == "Alliance" or + db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance"; + if(factionAlliance) then + return RECIPEPROFIT_alliance, "A"; + else + return RECIPEPROFIT_horde, "H"; + end +end + +function safe_cache_vendor() + if(not profile.enable_cache) then + return + end + + if(not profile.location_cache[UnitName("NPC")]) then + SetMapToCurrentZone() + local pos = {} + pos.x, pos.y = GetPlayerMapPosition("player") + profile.location_cache[UnitName("NPC")] = pos + end +end function button_update(self) local buttonName = _G[self:GetName().."Name"]; @@ -210,7 +301,8 @@ local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link) - if(sType == "Recipe" and safeRecipes[sName]) then + if(sType == "Recipe" and safeRecipes[sName]) then + safe_cache_vendor(); SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0); SetItemButtonSlotVertexColor(self, 0, 0, 0.5); buttonName:SetText("* " .. sName) @@ -226,73 +318,11 @@ end end -function RecipeProfit:UpdateButtons(event) - --print("UpdateButtons", event) - if(not MerchantFrame:IsVisible()) then - --print("UpdateButtons - (Event: ", event, ") - MerchantFrame not visible."); - return; - end - - for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do - local buttonframe = _G["MerchantItem"..i]; - local index = (((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i); - --print(index) - if index <= GetMerchantNumItems() then - button_update(buttonframe) - --[[else - --print(i, index, GetMerchantNumItems()) - local itemButton = _G["MerchantItem"..i.."ItemButton"]; - local merchantButton = _G["MerchantItem"..i]; - itemButton.price = nil; - itemButton.hasItem = nil; - itemButton:Hide(); - SetItemButtonNameFrameVertexColor(merchantButton, 0.5, 0.5, 0.5); - SetItemButtonSlotVertexColor(merchantButton,0.4, 0.4, 0.4); - _G["MerchantItem"..i.."Name"]:SetText(""); - _G["MerchantItem"..i.."MoneyFrame"]:Hide(); - _G["MerchantItem"..i.."AltCurrencyFrame"]:Hide(); - ]] - end - end -end - - -function RecipeProfit:OnEnable() - - _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons) - _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons) - - self:RegisterEvent("MERCHANT_SHOW", "UpdateButtons") - self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons") - self:RegisterEvent("BAG_UPDATE", "UpdateButtons") - - RecipeProfit:DoMerge() -end - -local ids = {} -function findGoodId(x, y) +function find_good_id(x, y) if ids[x.." "..y] then - return findGoodId(x + .01, y) + return find_good_id(x + .01, y) end ids[x.." "..y] = true return x, y -end - -function RecipeProfit:DoMerge() - ids = {} - selectedDB = (db.profile.faction == "Alliance" or - db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance") and - RECIPEPROFIT_alliance or RECIPEPROFIT_horde - GatherMate:ClearDB("RecipeProfit") - for id, note in pairs(selectedDB) do - x, y = findGoodId(note.x, note.y) - GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit", - note.item.." - ("..note.vendor.." ".. - ((db.profile.faction == "Alliance" or db.profile.faction == "default" and - UnitFactionGroup("player") == "Alliance") and "A" or "H") ..")") - end - - GatherMate:SendMessage("GatherMateDataImport") - GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged") -end +end \ No newline at end of file
