comparison core.lua @ 0:25906be72a8b

First Commit
author Aaron Bregger
date Wed, 11 Aug 2010 12:01:21 -0500
parents
children dceccfaf0a50
comparison
equal deleted inserted replaced
-1:000000000000 0:25906be72a8b
1 local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
2 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
3 local tabletest = {}
4 local db = {}
5 RecipeProfit.db = db;
6
7 function debugprint(val, indent)
8 indent = indent or "";
9 if not(type(val) == "table") then
10 print("Not table: " .. val)
11 return
12 end
13
14 for k,v in pairs(val) do
15 if(type(k) == "table" and type(v) == "table") then
16 print(indent .. "table key: {")
17 debugprint(k, indent .. " ")
18 print(indent .. "} = {")
19 debugprint(v, indent .. " ")
20 print(indent .. "}")
21 elseif(type(v) == "table") then
22 print(indent .. k .. " = {")
23 debugprint(v, indent .. " ")
24 print(indent .. "}")
25 else
26 print(indent .. k .. " = " .. v)
27 end
28 end
29 end
30
31 local options = {
32 type = "group",
33 name = "RecipeProfit", -- addon name to import from, don't localize
34 handler = {},
35 disabled = false,
36 args = {
37 faction = {
38 order = 1,
39 name = "Select Database",
40 desc = "Show a different database",
41 type = "group",
42 guiInline = true,
43 args = {
44 faction = {
45 order = 0,
46 name = "Faction",
47 desc = "Show a different database.",
48 type = "select",
49 values = {
50 ["Alliance"] = "Alliance",
51 ["Horde"] = "Horde",
52 ["default"] = "Default (Determined By Character)",
53 },
54 arg = "faction",
55 },
56 },
57 get = function(k) print(k); return db.profile[k.arg]; end,
58 set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end,
59 },
60 loadData = {
61 order = 8,
62 name = "Import Data",
63 desc = "Load RecipeProfit and import the data to your database.",
64 type = "execute",
65 func = function()
66 RecipeProfit:DoMerge()
67 end
68 },
69 }
70 }
71
72 local defaults = {
73 faction = nil,
74 }
75
76 function RecipeProfit:OnInitialize()
77 profile = profile or defaults
78 db.profile = profile
79 db.storage = {}
80
81 GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
82 GatherMate:RegisterDBType("RecipeProfit", db.storage)
83 GatherMate.db.profile.show["RecipeProfit"] = "always"
84 GatherMate.nodeIDs["RecipeProfit"] = {}
85 GatherMate.nodeTextures["RecipeProfit"] = {}
86 GatherMate.nodeMinHarvest["RecipeProfit"] = {}
87 nodes = GatherMate.nodeIDs["RecipeProfit"]
88
89 for id, note in pairs(RECIPEPROFIT_alliance) do
90 nodes[note.item.." - ("..note.vendor.." A)"] = id * 10
91 GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05"
92 end
93
94 for id, note in pairs(RECIPEPROFIT_horde) do
95 nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1
96 GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05"
97 end
98
99 GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
100 GatherMate:GetModule("Config"):UpdateConfig()
101
102 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
103 end
104
105 function RecipeProfit:OnEnable()
106 db.profile.faction = db.profile.faction or UnitFactionGroup("player")
107
108 RecipeProfit:DoMerge()
109 end
110
111 local ids = {}
112 function findGoodId(x, y)
113 if ids[x.." "..y] then
114 return findGoodId(x + .01, y)
115 end
116
117 ids[x.." "..y] = true
118 return x, y
119 end
120
121 function RecipeProfit:DoMerge()
122 ids = {}
123 GatherMate:ClearDB("RecipeProfit")
124 for id, note in pairs(db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or RECIPEPROFIT_horde) do
125 x, y = findGoodId(note.x, note.y)
126 GatherMate:AddNode(note.map, x / 100, y / 100, "RecipeProfit",
127 note.item.." - ("..note.vendor.." ".. (db.profile.faction == "Alliance" and "A" or "H") ..")")
128 end
129
130 GatherMate:SendMessage("GatherMateDataImport")
131 GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
132 end