view Core.lua @ 105:c6c748a5823b tip

Collaborative list trimming 80% functional Updates for the zone-in problem
author John@Yosemite-PC
date Sun, 06 May 2012 08:33:34 -0400
parents 0cd1d46e7b66
children
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
-- (x) 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)
-- (*) whisper UI
-- (_) communication and list merging/trimming
-- (_) admins
-- (*) players gui
-- ( ) undo
-- ( ) crypto / protection against tampering
-- ( ) alt tracking
-- (*) reserves
-- ( ) comparison vs currently equipped item


-- Trimming. 
-- * on login, check self state vs admin states
-- * trim up to the common point
-- * broadcast to other admins your present state (they will simply record this)

local _G=_G
local strsplit=strsplit
local string=string
local sformat=string.format
local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-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

dbversion = 1
commversion = 1

function OnInitialize()

    debug = true

    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")

    admin = db.profile.admin
    if not db.profile.dbversion or db.profile.dbversion < dbversion then
        UpgradeDB()
    end

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

function OnEnable()
    CreateWorkingStateFromChanges(db.profile.changes)
    InitializeState()
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)
    elseif action == "liststatus" then
        local lids = LootLists:GetAllIds()
        for _,v in _G.pairs(lids) do
            local lref = LootLists:Select(v)
            printf("List %s, modified %s (%s)", lref:GetName(), _G.date("%m/%d/%y %H:%M:%S",lref:GetTime()), lref:GetTime())
        end
    elseif action == "push" then
        Comm:Push()
    elseif action == "state" then
        print(state)
    else
        CreateGUI()
    end
end

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

function UpgradeDB()
    local mydbver = db.profile.dbversion or 0

    if mydbver == 0 then -- difference between 0 and 1 is whether this field is present
        db.profile.dbversion = 1
        mydbver = 1
    end


end