annotate Core.lua @ 53:708d8a423b4c

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