annotate Core.lua @ 43:4109683c3172

Kept AceConsole embedded - it handily disables the chat commands when the addon is disabled Did a little passthrough to properly set the self param for commands like Print()
author John@Yosemite-PC
date Thu, 15 Mar 2012 22:27:51 -0400
parents 72055fc7e115
children 8913e7d79cad
rev   line source
John@0 1 -- ideas: last attended data and/or remove people who haven't attended in X days
John@0 2
John@0 3 -- order of implementation
John@31 4 -- (*) lists fully functional (/script interface)
John@31 5 -- (*) lists single-user functional via command line interface
John@27 6 -- (*) all actions should reference the player list rather than player names
John@27 7 -- (?) player entries should persist as long as any list or change references
John@18 8 -- (*) lists store number slots rather than flat indexing
John@33 9 -- ( ) database and comm versioning
John@18 10 -- ( ) limited communication - everyone trusts the loot master
John@0 11 -- ( ) single user + admin gui (manual suicides)
John@0 12 -- ( ) single user + admin gui (master loot)
John@18 13 -- ( ) communication and list merging/trimming
John@0 14 -- ( ) admins
John@0 15 -- ( ) players gui
John@35 16 -- ( ) undo
John@0 17 -- ( ) crypto / protection against tampering
John@0 18 -- ( ) alt tracking
John@32 19 -- (_) reserves
John@32 20
John@42 21 local _G=_G
John@42 22 local strsplit=strsplit
John@42 23 local string=string
John@42 24 local sformat=string.format
John@43 25 local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0")
John@43 26 -- "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0"
John@42 27 _G.bsk=bsk
John@42 28 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false)
John@42 29 setfenv(1,bsk)
John@42 30
John@34 31 local pkgrev = " @project-revision@ "
John@0 32
John@0 33 -- important things to remember:
John@1 34 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int
John@1 35 -- indexing
John@0 36 -- 2) a.x === a["x"]
John@0 37 -- 3) a["1"] =/= a[1]
John@5 38 -- 4) table.remove() works ok if reverse iterating, terrible at anything else
John@5 39 -- 5) pairs() does not have a guaranteed iteration order
John@0 40
John@43 41 -- These two functions properly format the call to AceConsole:Print(), which
John@43 42 -- needs a full object. Calling "Print" will call the mixed-in console functions
John@43 43 -- but without a self parameter because of the namespacing. I would disembed
John@43 44 -- console, except that it has handy OnDisable behavior to disable chat
John@43 45 -- commands.
John@43 46 function print(...)
John@43 47 bsk:Print(...)
John@43 48 end
John@0 49
John@43 50 function printf(...)
John@43 51 bsk:Printf(...)
John@43 52 end
John@0 53
John@42 54 function OnInitialize()
John@0 55
John@42 56 db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")
John@0 57
John@42 58 options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
John@42 59 _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
John@42 60 --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
John@0 61
John@42 62 local HandlePassThrough = function(...) HandleCommand(...) end
John@42 63 bsk:RegisterChatCommand("bsk", HandlePassThrough)
John@0 64 end
John@0 65
John@42 66 function OnEnable()
John@42 67 CreateWorkingStateFromChanges(db.profile.changes)
John@43 68 --CreateGUI()
John@0 69 end
John@0 70
John@42 71 function HandleCommand(paramIn)
John@0 72 local param = { strsplit(" ", paramIn) }
John@8 73 local FixPersonName = function(p)
John@0 74 p = p:lower()
John@0 75 -- next two lines from sylvanaar
John@0 76 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
John@0 77 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
John@0 78 end
John@0 79
John@0 80 if param[1] == nil or param[1] == "" then
John@43 81 print("need args")
John@0 82 return
John@0 83 end
John@8 84 if param[1] == "persons" then
John@42 85 PrintPersons()
John@8 86 elseif param[1] == "changes" then
John@42 87 PrintChanges()
John@21 88 elseif param[1] == "delete" then
John@21 89 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@42 90 PrintTable(param)
John@21 91 return
John@21 92 end
John@21 93 if param[2] == "list" then
John@42 94 DeleteList(param[3])
John@22 95 elseif param[2] == "personfromlist" then
John@22 96 if param[4] == nil or param[4] == "" then
John@42 97 PrintTable(param)
John@22 98 return
John@22 99 end
John@22 100 local person = FixPersonName(param[3])
John@42 101 RemovePersonFromList(person, param[4])
John@28 102 elseif param[2] == "person" then
John@28 103 local person = FixPersonName(param[3])
John@42 104 RemovePerson(person)
John@21 105 else
John@43 106 printf("Deleting anything of type %s is not supported",param[2])
John@21 107 end
John@30 108 elseif param[1] == "nuke" then
John@30 109 if param[2] == nil or param[2] == "" then
John@42 110 PrintTable(param)
John@30 111 return
John@30 112 end
John@30 113 local person = FixPersonName(param[2])
John@42 114 NukePerson(person)
John@0 115 elseif param[1] == "add" then
John@0 116 if param[2] == nil or param[2] == "" then
John@42 117 PrintTable(param)
John@0 118 return
John@0 119 end
John@0 120 if param[3] == nil or param[3] == "" then
John@42 121 PrintTable(param)
John@0 122 return
John@0 123 end
John@8 124 if param[2] == "person" then
John@1 125 if param[3] == "all" then
John@42 126 AddMissingPersons()
John@1 127 else
John@8 128 local person = FixPersonName(param[3])
John@42 129 AddPerson(person)
John@1 130 end
John@0 131 elseif param[2] == "list" then
John@42 132 CreateList(param[3])
John@11 133 elseif param[2] == "tolist" then
John@9 134 if param[4] == nil or param[4] == "" then
John@42 135 PrintTable(param)
John@9 136 return
John@9 137 end
John@9 138 local person = FixPersonName(param[3])
John@42 139 AddPersonToListEnd(person,param[4])
John@11 140 elseif param[2] == "tolistrandom" then
John@11 141 if param[4] == nil or param[4] == "" then
John@42 142 PrintTable(param)
John@11 143 return
John@11 144 end
John@11 145 local person = FixPersonName(param[3])
John@42 146 AddPersonToListRandom(person,param[4])
John@0 147 end
John@3 148 elseif param[1] == "populate" then
John@3 149 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@42 150 PrintTable(param)
John@3 151 return
John@3 152 end
John@3 153 -- list = p2
John@42 154 local index = GetListIndex(param[2])
John@3 155 if param[3] == "random" then
John@42 156 PopulateListRandom(index)
John@3 157 end
John@0 158 elseif param[1] == "suicide" then
John@0 159 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@42 160 PrintTable(param)
John@0 161 return
John@0 162 end
John@8 163 local person = FixPersonName(param[2])
John@42 164 SuicidePerson(person,param[3])
John@14 165 elseif param[1] == "lists" then
John@0 166 if param[2] == nil or param[2] == "" then
John@42 167 PrettyPrintLists()
John@14 168 return
John@14 169 else
John@42 170 local listIndex = GetListIndex(param[2])
John@42 171 PrettyPrintList(listIndex)
John@14 172 end
John@14 173 elseif param[1] == "reserve" then
John@14 174 if param[2] == nil or param[2] == "" then
John@42 175 printtable(param)
John@0 176 return
John@0 177 end
John@14 178 local person = FixPersonName(param[2])
John@42 179 AddReserve(person)
John@5 180 elseif param[1] == "trim" then
John@5 181 if param[2] == nil or param[2] == "" then
John@42 182 printtable(param)
John@5 183 return
John@5 184 end
John@42 185 TrimLists(param[2])
John@20 186 elseif param[1] == "rename" then
John@20 187 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then
John@42 188 printtable(param)
John@20 189 return
John@20 190 end
John@42 191 RenameList(param[2],param[3])
John@17 192 elseif param[1] == "selfdestruct" then
John@42 193 SelfDestruct()
John@38 194 else
John@42 195 CreateGUI()
John@0 196 end
John@0 197
John@42 198 --if frame == nil then
John@42 199 --CreateGUI()
John@42 200 --ShowGUI()
John@0 201 --else
John@42 202 --ShowGUI()
John@0 203 --end
John@0 204
John@0 205 end
John@0 206
John@42 207 defaults = {
John@0 208 profile = {
John@8 209 persons = {},
John@0 210 changes = {},
John@34 211 lists = {}
John@0 212 }
John@0 213 }
John@0 214
John@0 215