annotate Core.lua @ 68:a177b863ed6c

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