annotate Core.lua @ 26:4c3140c7a1b4

Lots of folding markers so I can see the API clearly
author John@Yosemite-PC
date Sat, 10 Mar 2012 09:05:37 -0500
parents 27cf1355cd6f
children 611808dbc0c0
rev   line source
John@0 1 -- ideas: last attended data and/or remove people who haven't attended in X days
John@0 2 -- and/or just a "remove from all lists" option
John@0 3
John@0 4
John@0 5 -- order of implementation
John@1 6 -- (_) lists fully functional (/script interface)
John@1 7 -- (_) lists single-user functional via command line interface
John@15 8 -- (_) all actions should reference the player list rather than player names
John@6 9 -- ( ) player entries should persist as long as any list or change references
John@6 10 -- ( ) convert slist entries down to a delimited string - much smaller
John@18 11 -- (*) lists store number slots rather than flat indexing
John@18 12 -- ( ) limited communication - everyone trusts the loot master
John@0 13 -- ( ) single user + admin gui (manual suicides)
John@0 14 -- ( ) single user + admin gui (master loot)
John@18 15 -- ( ) communication and list merging/trimming
John@0 16 -- ( ) admins
John@0 17 -- ( ) players gui
John@0 18 -- ( ) crypto / protection against tampering
John@0 19 -- ( ) alt tracking
John@0 20 -- ( ) reserves
John@0 21
John@0 22 -- important things to remember:
John@1 23 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int
John@1 24 -- indexing
John@0 25 -- 2) a.x === a["x"]
John@0 26 -- 3) a["1"] =/= a[1]
John@5 27 -- 4) table.remove() works ok if reverse iterating, terrible at anything else
John@5 28 -- 5) pairs() does not have a guaranteed iteration order
John@0 29
John@0 30 bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0", "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0")
John@0 31 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false)
John@0 32
John@0 33 local AceGUI = LibStub("AceGUI-3.0")
John@0 34
John@0 35 function bsk:OnInitialize()
John@0 36
John@0 37 self.db = LibStub("AceDB-3.0"):New("BskDB", self.defaults, "Default")
John@0 38
John@0 39 self.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
John@0 40 LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", self.options)
John@0 41 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
John@0 42
John@0 43 self:RegisterChatCommand("bsk", "HandleCommand")
John@0 44 end
John@0 45
John@0 46 function bsk:OnEnable()
John@5 47 bsk:CreateWorkingStateFromChanges(self.db.profile.changes)
John@0 48 --self:HandleCommand()
John@0 49 end
John@0 50
John@0 51 function bsk:HandleCommand(paramIn)
John@0 52 local param = { strsplit(" ", paramIn) }
John@8 53 local FixPersonName = function(p)
John@0 54 p = p:lower()
John@0 55 -- next two lines from sylvanaar
John@0 56 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
John@0 57 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
John@0 58 end
John@0 59
John@0 60 if param[1] == nil or param[1] == "" then
John@0 61 bsk:Print("need args")
John@0 62 return
John@0 63 end
John@8 64 if param[1] == "persons" then
John@8 65 bsk:PrintPersons()
John@8 66 elseif param[1] == "changes" then
John@8 67 bsk:PrintChanges()
John@21 68 elseif param[1] == "delete" then
John@21 69 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@21 70 bsk:PrintTable(param)
John@21 71 return
John@21 72 end
John@21 73 if param[2] == "list" then
John@21 74 bsk:DeleteList(param[3])
John@22 75 elseif param[2] == "personfromlist" then
John@22 76 if param[4] == nil or param[4] == "" then
John@22 77 bsk:PrintTable(param)
John@22 78 return
John@22 79 end
John@22 80 local person = FixPersonName(param[3])
John@22 81 bsk:RemovePersonFromList(person, param[4])
John@21 82 else
John@21 83 bsk:Print(sformat("Deleting anything of type %s is not supported",param[2]))
John@21 84 end
John@0 85 elseif param[1] == "add" then
John@0 86 if param[2] == nil or param[2] == "" then
John@0 87 bsk:PrintTable(param)
John@0 88 return
John@0 89 end
John@0 90 if param[3] == nil or param[3] == "" then
John@0 91 bsk:PrintTable(param)
John@0 92 return
John@0 93 end
John@8 94 if param[2] == "person" then
John@1 95 if param[3] == "all" then
John@8 96 bsk:AddMissingPersons()
John@1 97 else
John@8 98 local person = FixPersonName(param[3])
John@8 99 bsk:AddPerson(person)
John@1 100 end
John@0 101 elseif param[2] == "list" then
John@0 102 bsk:CreateList(param[3])
John@11 103 elseif param[2] == "tolist" then
John@9 104 if param[4] == nil or param[4] == "" then
John@9 105 bsk:PrintTable(param)
John@9 106 return
John@9 107 end
John@9 108 local person = FixPersonName(param[3])
John@11 109 bsk:AddPersonToListEnd(person,param[4])
John@11 110 elseif param[2] == "tolistrandom" then
John@11 111 if param[4] == nil or param[4] == "" then
John@11 112 bsk:PrintTable(param)
John@11 113 return
John@11 114 end
John@11 115 local person = FixPersonName(param[3])
John@11 116 bsk:AddPersonToListRandom(person,param[4])
John@0 117 end
John@3 118 elseif param[1] == "populate" then
John@3 119 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@3 120 bsk:PrintTable(param)
John@3 121 return
John@3 122 end
John@3 123 -- list = p2
John@3 124 local index = bsk:GetListIndex(param[2])
John@3 125 if param[3] == "random" then
John@3 126 bsk:PopulateListRandom(index)
John@3 127 end
John@0 128 elseif param[1] == "suicide" then
John@0 129 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@0 130 bsk:PrintTable(param)
John@0 131 return
John@0 132 end
John@8 133 local person = FixPersonName(param[2])
John@8 134 bsk:SuicidePerson(person,param[3])
John@14 135 elseif param[1] == "lists" then
John@0 136 if param[2] == nil or param[2] == "" then
John@14 137 bsk:PrettyPrintLists()
John@14 138 return
John@14 139 else
John@14 140 local listIndex = bsk:GetListIndex(param[2])
John@14 141 bsk:PrettyPrintList(listIndex)
John@14 142 end
John@14 143 elseif param[1] == "reserve" then
John@14 144 if param[2] == nil or param[2] == "" then
John@14 145 bsk:printtable(param)
John@0 146 return
John@0 147 end
John@14 148 local person = FixPersonName(param[2])
John@14 149 bsk:AddReserve(person)
John@5 150 elseif param[1] == "trim" then
John@5 151 if param[2] == nil or param[2] == "" then
John@14 152 bsk:printtable(param)
John@5 153 return
John@5 154 end
John@5 155 bsk:TrimLists(param[2])
John@20 156 elseif param[1] == "rename" then
John@20 157 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@20 158 bsk:printtable(param)
John@20 159 return
John@20 160 end
John@20 161 bsk:RenameList(param[2],param[3])
John@17 162 elseif param[1] == "selfdestruct" then
John@17 163 bsk:SelfDestruct()
John@0 164 end
John@0 165
John@0 166 --if self.frame == nil then
John@0 167 --self:CreateGUI()
John@0 168 --self:ShowGUI()
John@0 169 --else
John@0 170 --self:ShowGUI()
John@0 171 --end
John@0 172
John@0 173 end
John@0 174
John@0 175 bsk.defaults = {
John@0 176 profile = {
John@8 177 persons = {},
John@0 178 changes = {},
John@0 179 listBase = {}
John@0 180 }
John@0 181 }
John@0 182
John@0 183