annotate Core.lua @ 85:f938ec08d5a6

Cleanup
author John@Yosemite-PC
date Sat, 14 Apr 2012 10:12:06 -0400
parents 70fac446f3ee
children 22b37c800bc4
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@77 10 -- (_) limited communication - everyone trusts the loot master
John@85 11 -- (*) single user + admin gui (manual suicides)
John@85 12 -- (*) single user + admin gui (master loot)
John@84 13 -- (*) whisper UI
John@85 14 -- (_) communication and list merging/trimming
John@85 15 -- (_) admins
John@77 16 -- (*) players gui
John@35 17 -- ( ) undo
John@0 18 -- ( ) crypto / protection against tampering
John@0 19 -- ( ) alt tracking
John@70 20 -- (*) reserves
John@32 21
John@42 22 local _G=_G
John@42 23 local strsplit=strsplit
John@42 24 local string=string
John@42 25 local sformat=string.format
John@43 26 local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-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@42 41 function OnInitialize()
John@0 42
John@69 43 debug = true
John@69 44
John@42 45 db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")
John@0 46
John@42 47 options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
John@42 48 _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
John@42 49 --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
John@0 50
John@74 51 admin = db.profile.admin
John@74 52
John@42 53 local HandlePassThrough = function(...) HandleCommand(...) end
John@42 54 bsk:RegisterChatCommand("bsk", HandlePassThrough)
John@68 55 bsk:OnInitializeSetStaticData()
John@70 56 InitializeComm()
John@73 57 InitializeLooting()
John@0 58 end
John@0 59
John@42 60 function OnEnable()
John@42 61 CreateWorkingStateFromChanges(db.profile.changes)
John@73 62 InitializeState()
John@0 63 end
John@0 64
John@42 65 function HandleCommand(paramIn)
John@0 66 local param = { strsplit(" ", paramIn) }
John@8 67 local FixPersonName = function(p)
John@0 68 p = p:lower()
John@0 69 -- next two lines from sylvanaar
John@0 70 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
John@0 71 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
John@0 72 end
John@49 73 action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)
John@0 74
John@49 75 if not action then
John@43 76 print("need args")
John@0 77 return
John@0 78 end
John@49 79 if action == "persons" then
John@42 80 PrintPersons()
John@49 81 elseif action == "changes" then
John@42 82 PrintChanges()
John@49 83 elseif action == "selfdestruct" then
John@49 84 SelfDestruct()
John@49 85 elseif action == "delete" or action == "remove" then
John@49 86 if not arg1 or not arg2 then
John@42 87 PrintTable(param)
John@21 88 return
John@21 89 end
John@49 90 if arg1 == "list" then
John@49 91 DeleteList(arg2)
John@49 92 elseif arg1 == "personfromlist" or "fromlist" then
John@49 93 if not arg3 then
John@42 94 PrintTable(param)
John@22 95 return
John@22 96 end
John@49 97 local person = FixPersonName(arg2)
John@49 98 RemovePersonFromList(person, arg3)
John@49 99 elseif arg1 == "person" then
John@49 100 local person = FixPersonName(arg2)
John@42 101 RemovePerson(person)
John@21 102 else
John@49 103 printf("Deleting anything of type %s is not supported",arg1)
John@21 104 end
John@49 105 elseif action == "nuke" then
John@49 106 if not arg1 then
John@42 107 PrintTable(param)
John@30 108 return
John@30 109 end
John@49 110 local person = FixPersonName(arg1)
John@42 111 NukePerson(person)
John@49 112 elseif action == "add" or action == "create" then
John@49 113 if not arg1 or not arg2 then
John@42 114 PrintTable(param)
John@0 115 return
John@0 116 end
John@49 117 if arg1 == "person" then
John@49 118 if arg2 == "all" or arg2 == "missing" then
John@49 119 PersonList:AddMissing()
John@1 120 else
John@49 121 local person = FixPersonName(arg2)
John@42 122 AddPerson(person)
John@1 123 end
John@49 124 elseif arg1 == "list" then
John@49 125 CreateList(arg2)
John@49 126 elseif arg1 == "tolist" then
John@49 127 if not arg3 then
John@42 128 PrintTable(param)
John@9 129 return
John@9 130 end
John@49 131 local person = FixPersonName(arg2)
John@49 132 AddPersonToListEnd(person,arg3)
John@49 133 elseif arg1 == "tolistrandom" then
John@49 134 if not arg3 then
John@42 135 PrintTable(param)
John@11 136 return
John@11 137 end
John@49 138 local person = FixPersonName(arg2)
John@49 139 AddPersonToListRandom(person,arg3)
John@0 140 end
John@49 141 elseif action == "populate" then
John@49 142 if not arg1 then
John@42 143 PrintTable(param)
John@3 144 return
John@3 145 end
John@3 146 -- list = p2
John@49 147 PopulateListRandom(arg1)
John@49 148 elseif action == "suicide" then
John@49 149 if not arg1 or not arg2 then
John@42 150 PrintTable(param)
John@0 151 return
John@0 152 end
John@49 153 local person = FixPersonName(arg1)
John@49 154 SuicidePerson(person,arg2)
John@49 155 elseif action == "lists" then
John@49 156 if not arg1 then
John@42 157 PrettyPrintLists()
John@14 158 return
John@14 159 else
John@49 160 PrettyPrintList(arg1)
John@14 161 end
John@49 162 elseif action == "reserve" then
John@49 163 if not arg1 then
John@49 164 PrintTable(param)
John@49 165 return
John@49 166 end
John@49 167 local person = FixPersonName(arg1)
John@49 168 ReservePerson(person)
John@49 169 elseif action == "trim" then
John@49 170 if not arg1 then
John@42 171 printtable(param)
John@0 172 return
John@0 173 end
John@49 174 TrimLists(arg1)
John@49 175 elseif action == "rename" then
John@49 176 if not arg1 or not arg2 then
John@49 177 PrintTable(param)
John@5 178 return
John@5 179 end
John@49 180 RenameList(arg1,arg2)
John@66 181 elseif action == "generate" then
John@66 182 if not arg1 then
John@66 183 PrintTable(param)
John@66 184 return
John@66 185 end
John@66 186 PersonList:AddMissing()
John@66 187 CreateList(arg1)
John@66 188 PopulateListRandom(arg1)
John@77 189 elseif action == "liststatus" then
John@77 190 local lids = LootLists:GetAllIds()
John@77 191 for _,v in _G.pairs(lids) do
John@77 192 local lref = LootLists:Select(v)
John@77 193 printf("List %s, modified %s (%s)", lref:GetName(), _G.date("%m/%d/%y %H:%M:%S",lref:GetTime()), lref:GetTime())
John@77 194 end
John@72 195 elseif action == "push" then
John@72 196 Comm:Push()
John@72 197 elseif action == "state" then
John@72 198 print(state)
John@38 199 else
John@42 200 CreateGUI()
John@0 201 end
John@0 202 end
John@0 203
John@42 204 defaults = {
John@0 205 profile = {
John@8 206 persons = {},
John@0 207 changes = {},
John@34 208 lists = {}
John@0 209 }
John@0 210 }
John@0 211