diff 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
line wrap: on
line diff
--- a/core.lua	Sun Aug 15 17:59:03 2010 -0500
+++ b/core.lua	Mon Aug 16 23:07:50 2010 -0500
@@ -18,16 +18,22 @@
 local safeRecipes = {}
 local ids = {}
 
+local profile
+
 RecipeProfit.db = db;
 
--- Forward Definitions (for local functions)
+--[[ Forward Definitions (for local functions) ]]
 local get_faction_db, 
       add_note, 
       button_update, 
       find_good_id, 
       safe_cache_vendor,
-      get_note_title;
+      get_note_title,
+      get_next_texture_id,
+      set_node_constants,
+      inject_options;
 
+--[[ Deep table inspection for debugging ]]
 function debugprint(val, indent)
     indent = indent or "";
     if not(type(val) == "table") then
@@ -148,7 +154,7 @@
 }
 
 function RecipeProfit:OnInitialize()
-    profile = profile or defaults
+    profile = RECIPEPROFIT_profile or defaults
     
     for k, v in pairs(defaults) do
         profile[k] = profile[k] or v;
@@ -164,50 +170,27 @@
     GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
     GatherMate:RegisterDBType("RecipeProfit", db.storage)
     GatherMate.db.profile.show["RecipeProfit"] = GatherMate.db.profile.show["RecipeProfit"] or "always"
-    GatherMate.nodeIDs["RecipeProfit"] = {}
-    GatherMate.nodeTextures["RecipeProfit"] = {}
-    GatherMate.nodeMinHarvest["RecipeProfit"] = {}
-    local nodes = GatherMate.nodeIDs["RecipeProfit"]
     
-    for id, note in pairs(RECIPEPROFIT_alliance) do
-        safeRecipes[note.item] = true;
-        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[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)
-    
-    GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = {
-        order = 6,
-        name = "Show RecipeProfit nodes.",
-        desc = "Toggle showing nodes added by RecipeProfit.",
-        type = "select",
-        values = {
-            ["always"] = "Always show",
-            ["never"]  = "Never show",
-        },
-        arg = "RecipeProfit",
-    }
-    
-    GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = {
-        order = 6.5,
-        name = "RecipeProfit",
-        desc = "Color of the tracking circle.",
-        type = "color",
-        hasAlpha = true,
-        arg = "RecipeProfit",		
-    }
+    set_node_constants()
+    inject_options()
     
     GatherMate:GetModule("Config"):UpdateConfig()
     GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
 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:ShowOptions()
     LibStub("AceConfigDialog-3.0"):Open("GatherMate")
     LibStub("AceConfigDialog-3.0"):SelectGroup("GatherMate", "RecipeProfit")
@@ -228,20 +211,7 @@
             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     
+end   
 
 function RecipeProfit:DoMerge()
     ids = {}
@@ -325,4 +295,57 @@
     
     ids[x.." "..y] = true
     return x, y
-end   
\ No newline at end of file
+end   
+
+local lastNodeTextureId = 0;
+
+function get_next_texture_id()
+    lastNodeTextureId = lastNodeTextureId + 1;
+    return lastNodeTextureId;
+end
+
+function set_node_constants()
+    GatherMate.nodeIDs["RecipeProfit"] = {}
+    GatherMate.nodeTextures["RecipeProfit"] = {}
+    GatherMate.nodeMinHarvest["RecipeProfit"] = {}
+    
+    local nodes = GatherMate.nodeIDs["RecipeProfit"]
+    for id, note in pairs(RECIPEPROFIT_alliance) do
+        safeRecipes[note.item] = true;
+        nodes[get_note_title(note, "A")] = get_next_texture_id()
+    end
+    
+    for id, note in pairs(RECIPEPROFIT_horde) do
+        safeRecipes[note.item] = true;
+        nodes[get_note_title(note, "H")] = get_next_texture_id()
+    end
+    
+    for i = 1, lastNodeTextureId, 1 do
+        GatherMate.nodeTextures["RecipeProfit"][i] = "Interface\\Icons\\INV_Scroll_05"
+    end
+    
+    GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
+end
+
+function inject_options()
+    GatherMate:GetModule("Config").options.args.display.args.general.args.showGroup.args["showRecipeProfit"] = {
+        order = 6,
+        name = "Show RecipeProfit nodes.",
+        desc = "Toggle showing nodes added by RecipeProfit.",
+        type = "select",
+        values = {
+            ["always"] = "Always show",
+            ["never"]  = "Never show",
+        },
+        arg = "RecipeProfit",
+    }
+    
+    GatherMate:GetModule("Config").options.args.display.args.general.args.iconGroup.args.tracking.args["showRecipeProfit"] = {
+        order = 6.5,
+        name = "RecipeProfit",
+        desc = "Color of the tracking circle.",
+        type = "color",
+        hasAlpha = true,
+        arg = "RecipeProfit",		
+    }
+end