view Core.lua @ 68:a177b863ed6c

Event chaining from the data storage to the GUI elements
author John@Yosemite-PC
date Wed, 28 Mar 2012 23:29:36 -0400
parents 331b5e176d79
children b7352f007028
line wrap: on
line source
-- ideas: last attended data and/or remove people who haven't attended in X days

-- order of implementation
-- (*) lists fully functional (/script interface)
-- (*) lists single-user functional via command line interface 
-- (*) all actions should reference the player list rather than player names
-- (?) player entries should persist as long as any list or change references
-- (*) lists store number slots rather than flat indexing
-- ( ) database and comm versioning
-- ( ) limited communication - everyone trusts the loot master
-- ( ) single user + admin gui (manual suicides)
-- ( ) single user + admin gui (master loot)
-- ( ) communication and list merging/trimming
-- ( ) admins
-- ( ) players gui
-- ( ) undo
-- ( ) crypto / protection against tampering
-- ( ) alt tracking
-- (_) reserves

local _G=_G
local strsplit=strsplit
local string=string
local sformat=string.format
local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0")
-- "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0"
_G.bsk=bsk
local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false)
setfenv(1,bsk)

local pkgrev = " @project-revision@ "

-- important things to remember:
-- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int
-- indexing
-- 2) a.x === a["x"]
-- 3) a["1"] =/= a[1]
-- 4) table.remove() works ok if reverse iterating, terrible at anything else
-- 5) pairs() does not have a guaranteed iteration order

function OnInitialize()

    db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")

    options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
    _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
    --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")

    local HandlePassThrough = function(...) HandleCommand(...) end
    bsk:RegisterChatCommand("bsk", HandlePassThrough)
    bsk:OnInitializeSetStaticData()
end

function OnEnable()
    CreateWorkingStateFromChanges(db.profile.changes)
    --CreateGUI()
end

function HandleCommand(paramIn)
    local param = { strsplit(" ", paramIn) }
    local FixPersonName = function(p)
        p = p:lower()
        -- next two lines from sylvanaar
        local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
        return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)  
    end
    action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)

    if not action then
        print("need args")
        return
    end
    if action == "persons" then
        PrintPersons()
    elseif action == "changes" then
        PrintChanges()
    elseif action == "selfdestruct" then
        SelfDestruct()
    elseif action == "delete" or action == "remove" then
        if not arg1 or not arg2 then
            PrintTable(param)
            return
        end
        if arg1 == "list" then
            DeleteList(arg2)
        elseif arg1 == "personfromlist" or "fromlist" then
            if not arg3 then
                PrintTable(param)
                return
            end
            local person = FixPersonName(arg2)
            RemovePersonFromList(person, arg3)
        elseif arg1 == "person" then
            local person = FixPersonName(arg2)
            RemovePerson(person)
        else
            printf("Deleting anything of type %s is not supported",arg1)
        end
    elseif action == "nuke" then
        if not arg1 then
            PrintTable(param)
            return
        end
        local person = FixPersonName(arg1)
        NukePerson(person)
    elseif action == "add" or action == "create" then
        if not arg1 or not arg2 then
            PrintTable(param)
            return
        end
        if arg1 == "person" then
            if arg2 == "all" or arg2 == "missing" then
                PersonList:AddMissing()
            else
                local person = FixPersonName(arg2)
                AddPerson(person)
            end
        elseif arg1 == "list" then
            CreateList(arg2)
        elseif arg1 == "tolist" then
            if not arg3 then
                PrintTable(param)
                return
            end
            local person = FixPersonName(arg2)
            AddPersonToListEnd(person,arg3)
        elseif arg1 == "tolistrandom" then
            if not arg3 then
                PrintTable(param)
                return
            end
            local person = FixPersonName(arg2)
            AddPersonToListRandom(person,arg3)
        end
    elseif action == "populate" then
        if not arg1 then
            PrintTable(param)
            return
        end
        -- list = p2
        PopulateListRandom(arg1)
    elseif action == "suicide" then
        if not arg1 or not arg2 then
            PrintTable(param)
            return
        end
        local person = FixPersonName(arg1)
        SuicidePerson(person,arg2)
    elseif action == "lists" then
        if not arg1 then
            PrettyPrintLists()
            return
        else
            PrettyPrintList(arg1)
        end
    elseif action == "reserve" then
        if not arg1 then
            PrintTable(param)
            return
        end
        local person = FixPersonName(arg1)
        ReservePerson(person)
    elseif action == "trim" then
        if not arg1 then
            printtable(param)
            return
        end
        TrimLists(arg1)
    elseif action == "rename" then
        if not arg1 or not arg2 then
            PrintTable(param)
            return
        end
        RenameList(arg1,arg2)
    elseif action == "generate" then
        if not arg1 then
            PrintTable(param)
            return
        end
        PersonList:AddMissing()
        CreateList(arg1)
        PopulateListRandom(arg1)
    else
        CreateGUI()
    end

    --if frame == nil then
        --CreateGUI()
        --ShowGUI()
    --else
        --ShowGUI()
    --end

end

defaults = {
    profile = {
        persons = {},
        changes = {},
        lists = {}
    }
}