annotate Core.lua @ 90:dcbe1f04bb31

Bugfix
author John@Yosemite-PC
date Mon, 16 Apr 2012 07:06:27 -0400
parents 22b37c800bc4
children 5ade79caeece
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@86 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@86 41 dbversion = 1
John@86 42 commversion = 1
John@86 43
John@42 44 function OnInitialize()
John@0 45
John@69 46 debug = true
John@69 47
John@42 48 db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")
John@0 49
John@42 50 options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
John@42 51 _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
John@42 52 --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
John@0 53
John@74 54 admin = db.profile.admin
John@86 55 if not db.profile.dbversion or db.profile.dbversion < dbversion then
John@86 56 UpgradeDB()
John@86 57 end
John@74 58
John@42 59 local HandlePassThrough = function(...) HandleCommand(...) end
John@42 60 bsk:RegisterChatCommand("bsk", HandlePassThrough)
John@68 61 bsk:OnInitializeSetStaticData()
John@70 62 InitializeComm()
John@73 63 InitializeLooting()
John@0 64 end
John@0 65
John@42 66 function OnEnable()
John@42 67 CreateWorkingStateFromChanges(db.profile.changes)
John@73 68 InitializeState()
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@49 79 action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)
John@0 80
John@49 81 if not action then
John@43 82 print("need args")
John@0 83 return
John@0 84 end
John@49 85 if action == "persons" then
John@42 86 PrintPersons()
John@49 87 elseif action == "changes" then
John@42 88 PrintChanges()
John@49 89 elseif action == "selfdestruct" then
John@49 90 SelfDestruct()
John@49 91 elseif action == "delete" or action == "remove" then
John@49 92 if not arg1 or not arg2 then
John@42 93 PrintTable(param)
John@21 94 return
John@21 95 end
John@49 96 if arg1 == "list" then
John@49 97 DeleteList(arg2)
John@49 98 elseif arg1 == "personfromlist" or "fromlist" then
John@49 99 if not arg3 then
John@42 100 PrintTable(param)
John@22 101 return
John@22 102 end
John@49 103 local person = FixPersonName(arg2)
John@49 104 RemovePersonFromList(person, arg3)
John@49 105 elseif arg1 == "person" then
John@49 106 local person = FixPersonName(arg2)
John@42 107 RemovePerson(person)
John@21 108 else
John@49 109 printf("Deleting anything of type %s is not supported",arg1)
John@21 110 end
John@49 111 elseif action == "nuke" then
John@49 112 if not arg1 then
John@42 113 PrintTable(param)
John@30 114 return
John@30 115 end
John@49 116 local person = FixPersonName(arg1)
John@42 117 NukePerson(person)
John@49 118 elseif action == "add" or action == "create" then
John@49 119 if not arg1 or not arg2 then
John@42 120 PrintTable(param)
John@0 121 return
John@0 122 end
John@49 123 if arg1 == "person" then
John@49 124 if arg2 == "all" or arg2 == "missing" then
John@49 125 PersonList:AddMissing()
John@1 126 else
John@49 127 local person = FixPersonName(arg2)
John@42 128 AddPerson(person)
John@1 129 end
John@49 130 elseif arg1 == "list" then
John@49 131 CreateList(arg2)
John@49 132 elseif arg1 == "tolist" then
John@49 133 if not arg3 then
John@42 134 PrintTable(param)
John@9 135 return
John@9 136 end
John@49 137 local person = FixPersonName(arg2)
John@49 138 AddPersonToListEnd(person,arg3)
John@49 139 elseif arg1 == "tolistrandom" then
John@49 140 if not arg3 then
John@42 141 PrintTable(param)
John@11 142 return
John@11 143 end
John@49 144 local person = FixPersonName(arg2)
John@49 145 AddPersonToListRandom(person,arg3)
John@0 146 end
John@49 147 elseif action == "populate" then
John@49 148 if not arg1 then
John@42 149 PrintTable(param)
John@3 150 return
John@3 151 end
John@3 152 -- list = p2
John@49 153 PopulateListRandom(arg1)
John@49 154 elseif action == "suicide" then
John@49 155 if not arg1 or not arg2 then
John@42 156 PrintTable(param)
John@0 157 return
John@0 158 end
John@49 159 local person = FixPersonName(arg1)
John@49 160 SuicidePerson(person,arg2)
John@49 161 elseif action == "lists" then
John@49 162 if not arg1 then
John@42 163 PrettyPrintLists()
John@14 164 return
John@14 165 else
John@49 166 PrettyPrintList(arg1)
John@14 167 end
John@49 168 elseif action == "reserve" then
John@49 169 if not arg1 then
John@49 170 PrintTable(param)
John@49 171 return
John@49 172 end
John@49 173 local person = FixPersonName(arg1)
John@49 174 ReservePerson(person)
John@49 175 elseif action == "trim" then
John@49 176 if not arg1 then
John@42 177 printtable(param)
John@0 178 return
John@0 179 end
John@49 180 TrimLists(arg1)
John@49 181 elseif action == "rename" then
John@49 182 if not arg1 or not arg2 then
John@49 183 PrintTable(param)
John@5 184 return
John@5 185 end
John@49 186 RenameList(arg1,arg2)
John@66 187 elseif action == "generate" then
John@66 188 if not arg1 then
John@66 189 PrintTable(param)
John@66 190 return
John@66 191 end
John@66 192 PersonList:AddMissing()
John@66 193 CreateList(arg1)
John@66 194 PopulateListRandom(arg1)
John@77 195 elseif action == "liststatus" then
John@77 196 local lids = LootLists:GetAllIds()
John@77 197 for _,v in _G.pairs(lids) do
John@77 198 local lref = LootLists:Select(v)
John@77 199 printf("List %s, modified %s (%s)", lref:GetName(), _G.date("%m/%d/%y %H:%M:%S",lref:GetTime()), lref:GetTime())
John@77 200 end
John@72 201 elseif action == "push" then
John@72 202 Comm:Push()
John@72 203 elseif action == "state" then
John@72 204 print(state)
John@38 205 else
John@42 206 CreateGUI()
John@0 207 end
John@0 208 end
John@0 209
John@42 210 defaults = {
John@0 211 profile = {
John@8 212 persons = {},
John@0 213 changes = {},
John@34 214 lists = {}
John@0 215 }
John@0 216 }
John@0 217
John@86 218 function UpgradeDB()
John@86 219 local mydbver = db.profile.dbversion or 0
John@86 220
John@86 221 if mydbver == 0 then -- difference between 0 and 1 is whether this field is present
John@86 222 db.profile.dbversion = 1
John@86 223 mydbver = 1
John@86 224 end
John@86 225
John@86 226
John@86 227 end