annotate Core.lua @ 71:d5e2dfe0c269

Starting to track loot state separately
author John@Yosemite-PC
date Tue, 03 Apr 2012 23:23:22 -0400
parents 236117ab8a49
children 9e5b0a2368ad
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@70 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@70 15 -- (_) players gui
John@35 16 -- ( ) undo
John@0 17 -- ( ) crypto / protection against tampering
John@0 18 -- ( ) alt tracking
John@70 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@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@42 51 local HandlePassThrough = function(...) HandleCommand(...) end
John@42 52 bsk:RegisterChatCommand("bsk", HandlePassThrough)
John@68 53 bsk:OnInitializeSetStaticData()
John@70 54 InitializeComm()
John@0 55 end
John@0 56
John@42 57 function OnEnable()
John@42 58 CreateWorkingStateFromChanges(db.profile.changes)
John@66 59 --CreateGUI()
John@0 60 end
John@0 61
John@42 62 function HandleCommand(paramIn)
John@0 63 local param = { strsplit(" ", paramIn) }
John@8 64 local FixPersonName = function(p)
John@0 65 p = p:lower()
John@0 66 -- next two lines from sylvanaar
John@0 67 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
John@0 68 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
John@0 69 end
John@49 70 action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)
John@0 71
John@49 72 if not action then
John@43 73 print("need args")
John@0 74 return
John@0 75 end
John@49 76 if action == "persons" then
John@42 77 PrintPersons()
John@49 78 elseif action == "changes" then
John@42 79 PrintChanges()
John@49 80 elseif action == "selfdestruct" then
John@49 81 SelfDestruct()
John@49 82 elseif action == "delete" or action == "remove" then
John@49 83 if not arg1 or not arg2 then
John@42 84 PrintTable(param)
John@21 85 return
John@21 86 end
John@49 87 if arg1 == "list" then
John@49 88 DeleteList(arg2)
John@49 89 elseif arg1 == "personfromlist" or "fromlist" then
John@49 90 if not arg3 then
John@42 91 PrintTable(param)
John@22 92 return
John@22 93 end
John@49 94 local person = FixPersonName(arg2)
John@49 95 RemovePersonFromList(person, arg3)
John@49 96 elseif arg1 == "person" then
John@49 97 local person = FixPersonName(arg2)
John@42 98 RemovePerson(person)
John@21 99 else
John@49 100 printf("Deleting anything of type %s is not supported",arg1)
John@21 101 end
John@49 102 elseif action == "nuke" then
John@49 103 if not arg1 then
John@42 104 PrintTable(param)
John@30 105 return
John@30 106 end
John@49 107 local person = FixPersonName(arg1)
John@42 108 NukePerson(person)
John@49 109 elseif action == "add" or action == "create" then
John@49 110 if not arg1 or not arg2 then
John@42 111 PrintTable(param)
John@0 112 return
John@0 113 end
John@49 114 if arg1 == "person" then
John@49 115 if arg2 == "all" or arg2 == "missing" then
John@49 116 PersonList:AddMissing()
John@1 117 else
John@49 118 local person = FixPersonName(arg2)
John@42 119 AddPerson(person)
John@1 120 end
John@49 121 elseif arg1 == "list" then
John@49 122 CreateList(arg2)
John@49 123 elseif arg1 == "tolist" then
John@49 124 if not arg3 then
John@42 125 PrintTable(param)
John@9 126 return
John@9 127 end
John@49 128 local person = FixPersonName(arg2)
John@49 129 AddPersonToListEnd(person,arg3)
John@49 130 elseif arg1 == "tolistrandom" then
John@49 131 if not arg3 then
John@42 132 PrintTable(param)
John@11 133 return
John@11 134 end
John@49 135 local person = FixPersonName(arg2)
John@49 136 AddPersonToListRandom(person,arg3)
John@0 137 end
John@49 138 elseif action == "populate" then
John@49 139 if not arg1 then
John@42 140 PrintTable(param)
John@3 141 return
John@3 142 end
John@3 143 -- list = p2
John@49 144 PopulateListRandom(arg1)
John@49 145 elseif action == "suicide" then
John@49 146 if not arg1 or not arg2 then
John@42 147 PrintTable(param)
John@0 148 return
John@0 149 end
John@49 150 local person = FixPersonName(arg1)
John@49 151 SuicidePerson(person,arg2)
John@49 152 elseif action == "lists" then
John@49 153 if not arg1 then
John@42 154 PrettyPrintLists()
John@14 155 return
John@14 156 else
John@49 157 PrettyPrintList(arg1)
John@14 158 end
John@49 159 elseif action == "reserve" then
John@49 160 if not arg1 then
John@49 161 PrintTable(param)
John@49 162 return
John@49 163 end
John@49 164 local person = FixPersonName(arg1)
John@49 165 ReservePerson(person)
John@49 166 elseif action == "trim" then
John@49 167 if not arg1 then
John@42 168 printtable(param)
John@0 169 return
John@0 170 end
John@49 171 TrimLists(arg1)
John@49 172 elseif action == "rename" then
John@49 173 if not arg1 or not arg2 then
John@49 174 PrintTable(param)
John@5 175 return
John@5 176 end
John@49 177 RenameList(arg1,arg2)
John@66 178 elseif action == "generate" then
John@66 179 if not arg1 then
John@66 180 PrintTable(param)
John@66 181 return
John@66 182 end
John@66 183 PersonList:AddMissing()
John@66 184 CreateList(arg1)
John@66 185 PopulateListRandom(arg1)
John@38 186 else
John@42 187 CreateGUI()
John@0 188 end
John@0 189
John@42 190 --if frame == nil then
John@42 191 --CreateGUI()
John@42 192 --ShowGUI()
John@0 193 --else
John@42 194 --ShowGUI()
John@0 195 --end
John@0 196
John@0 197 end
John@0 198
John@42 199 defaults = {
John@0 200 profile = {
John@8 201 persons = {},
John@0 202 changes = {},
John@34 203 lists = {}
John@0 204 }
John@0 205 }
John@0 206
John@0 207