diff 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
line wrap: on
line diff
--- a/core.lua	Thu Aug 12 00:32:04 2010 -0500
+++ b/core.lua	Thu Aug 12 11:58:58 2010 -0500
@@ -14,11 +14,28 @@
 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
 local tabletest = {}
-local db = {}
+ db = {}
 local safeRecipes = {}
 safer = safeRecipes
 RecipeProfit.db = db;
 
+local function deepcopy(object)
+    local lookup_table = {}
+    local function _copy(object)
+        if type(object) ~= "table" then
+            return object
+        elseif lookup_table[object] then
+            return lookup_table[object]
+        end
+        local new_table = {}
+        lookup_table[object] = new_table
+        for index, value in pairs(object) do
+            new_table[_copy(index)] = _copy(value)
+        end
+        return setmetatable(new_table, getmetatable(object))
+    end
+    return _copy(object)
+end
 
 function debugprint(val, indent)
     indent = indent or "";
@@ -43,6 +60,17 @@
         end
     end
 end
+local defaultProfile = {
+    ["show"] = {
+        ["RecipeProfit"] = "always",
+        ["Herb Gathering"] = "never",
+        ["Extract Gas"] = "never",
+        ["Fishing"] = "never",
+        ["Mining"] = "never",
+        ["Treasure"] = "never",
+    },
+    ["trackShow"] = "never",
+}
 
 local options = {
  	type = "group",
@@ -76,7 +104,7 @@
                     desc = "Warn when buying a recipe not on the RecipeProfit list.",
                     type = "select",
                     values = {
-                        ["on"] = "On",
+                        --["on"] = "On",
                         ["off"]= "Off",
                     },
                     arg = "safebuy",
@@ -94,6 +122,23 @@
                 RecipeProfit:DoMerge()
 			end
         },
+		loadProfile = {
+			order = 9,
+			name = "Load RecipeProfit Profile",
+			desc = "Loads the RecipeProfit Profile into Gathermate for easy recipe tracking.",
+			type = "execute",
+			func = function() 
+                GatherMate.db.profiles["RecipeProfit"] = GatherMate.db.profiles["RecipeProfit"] or {}
+                gmdb = GatherMate.db.profiles["RecipeProfit"]
+                for k, v in pairs(defaultProfile) do
+                    gmdb[k] = v;
+                end
+                GatherMate:SendMessage("OnProfileChanged");
+                GatherMate:GetModule("Config"):UpdateConfig()
+                GatherMate:SendMessage("GatherMateConfigChanged")
+                GatherMate.db:SetProfile("RecipeProfit")
+			end
+        },
     }
 }
 
@@ -104,6 +149,7 @@
 
 function RecipeProfit:OnInitialize()
     profile = profile or defaults
+    
     for k, v in pairs(defaults) do
         profile[k] = profile[k] or v;
     end
@@ -165,8 +211,10 @@
             end
         end)
         
-        RecipeProfit:DoMerge()
+
     end
+    
+    RecipeProfit:DoMerge()
 end    
 
 local ids = {}
@@ -181,14 +229,16 @@
 
 function RecipeProfit:DoMerge()
     ids = {}
-    selectedDB = db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or 
-        db.profile.faction == "default" and UnitFactionGroup("player") == "Alliance" and
+    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" and "A" or "H") ..")")
+            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")