view core.lua @ 0:25906be72a8b

First Commit
author Aaron Bregger
date Wed, 11 Aug 2010 12:01:21 -0500
parents
children dceccfaf0a50
line wrap: on
line source
local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
local tabletest = {}
local db = {}
RecipeProfit.db = db;

function debugprint(val, indent)
    indent = indent or "";
    if not(type(val) == "table") then
        print("Not table: " .. val)
        return
    end
    
    for k,v in pairs(val) do
        if(type(k) == "table" and type(v) == "table") then
            print(indent .. "table key: {")
            debugprint(k, indent .. "    ")
            print(indent .. "} = {")
            debugprint(v, indent .. "    ")
            print(indent .. "}")
        elseif(type(v) == "table") then
            print(indent .. k .. " = {")
            debugprint(v, indent .. "    ")
            print(indent .. "}") 
        else
            print(indent .. k .. " = " .. v)
        end
    end
end

local options = {
 	type = "group",
	name = "RecipeProfit", -- addon name to import from, don't localize
	handler = {},
	disabled = false,
	args = {
        faction = {
            order = 1,
            name = "Select Database",
            desc = "Show a different database",
            type = "group",
            guiInline = true,
            args = {
                faction = {
                    order = 0,
                    name = "Faction",
                    desc = "Show a different database.",
                    type = "select",
                    values = {
                        ["Alliance"] = "Alliance",
                        ["Horde"]    = "Horde",
                        ["default"]  = "Default (Determined By Character)",
                    },
                    arg = "faction",
                },
            },
            get = function(k) print(k); return db.profile[k.arg]; end,
            set = function(k, v) db.profile[k.arg] = v; RecipeProfit:DoMerge(); end,
        },
		loadData = {
			order = 8,
			name = "Import Data",
			desc = "Load RecipeProfit and import the data to your database.",
			type = "execute",
			func = function() 
                RecipeProfit:DoMerge()
			end
        },
    }
}

local defaults = {
    faction = nil,
}

function RecipeProfit:OnInitialize()
    profile = profile or defaults
    db.profile = profile
    db.storage = {}
    
    GatherMate:GetModule("Config"):RegisterModule("RecipeProfit", options)
    GatherMate:RegisterDBType("RecipeProfit", db.storage)
    GatherMate.db.profile.show["RecipeProfit"] = "always"
    GatherMate.nodeIDs["RecipeProfit"] = {}
    GatherMate.nodeTextures["RecipeProfit"] = {}
    GatherMate.nodeMinHarvest["RecipeProfit"] = {}
    nodes = GatherMate.nodeIDs["RecipeProfit"]
    
    for id, note in pairs(RECIPEPROFIT_alliance) do
        nodes[note.item.." - ("..note.vendor.." A)"] = id * 10
        GatherMate.nodeTextures["RecipeProfit"][id * 10] = "Interface\\Icons\\INV_Scroll_05"
    end
    
    for id, note in pairs(RECIPEPROFIT_horde) do
        nodes[note.item.." - ("..note.vendor.." H)"] = id * 10 + 1
        GatherMate.nodeTextures["RecipeProfit"][id * 10 + 1] = "Interface\\Icons\\INV_Scroll_05"
    end
    
    GatherMate.reverseNodeIDs["RecipeProfit"] = GatherMate:CreateReversedTable(nodes)
    GatherMate:GetModule("Config"):UpdateConfig()
    
    GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
end

function RecipeProfit:OnEnable()
    db.profile.faction = db.profile.faction or UnitFactionGroup("player")
    
    RecipeProfit:DoMerge()
end    

local ids = {}
function findGoodId(x, y)
    if ids[x.." "..y] then
        return findGoodId(x + .01, y)
    end
    
    ids[x.." "..y] = true
    return x, y
end    

function RecipeProfit:DoMerge()
    ids = {}
    GatherMate:ClearDB("RecipeProfit")
    for id, note in pairs(db.profile.faction == "Alliance" and RECIPEPROFIT_alliance or RECIPEPROFIT_horde) 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") ..")")
    end
    
    GatherMate:SendMessage("GatherMateDataImport")
    GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
end