annotate Lists.lua @ 10:433d31ea992a

Separated add methods into "end of list" and "random"
author John@Doomsday
date Wed, 07 Mar 2012 17:43:30 -0500
parents daed0597deba
children a6bc3f2d3207
rev   line source
John@0 1 -- lists consist of three things
John@0 2 -- 1) a base state - agreed on by one or more list holders
John@0 3 -- 2) change sets - incremental list changes (can be rolled forwards or
John@0 4 -- backwards)
John@0 5 -- 3) working state - not saved because it can be so easily calculated
John@0 6 --
John@0 7 -- A separate user list is held - lists index into this
John@0 8
John@0 9
John@0 10 -- TODO: rename player
John@5 11 -- TODO: list trimming
John@0 12
John@4 13 -- notes on list storage:
John@7 14 -- Using names as keys as I do now is atrocious.
John@4 15 -- It prevents insertions (twss) to the middle of the list because then it acts
John@4 16 -- as a side effect onto all the others. ie ABCD -> AXBCD would be phrased as
John@4 17 -- "insert X and shift down B,C,D" which sucks. BCD haven't really been affected
John@4 18 -- (yet) because their relative positions to the others are still intact - ie
John@4 19 -- they are still below A right where they belong. But really X hasn't done
John@4 20 -- anything to affect their relative standing.
John@4 21 --
John@4 22 -- Ok so we can't use names.
John@4 23 --
John@4 24 -- We can't use monotonic integers either because it suffers the same problem.
John@4 25 -- Also consider, randoming in someone to a list of ABCD. Say they roll spot 2.
John@4 26 -- What if someone else runs a separate raid and also randoms someone into slot
John@4 27 -- 2? How do you handle that conflict? Difficult. Also, consider this:
John@4 28 -- List of ABCD on night 1.
John@4 29 -- Admin 1 on night 2 rolls in 30 new people. ABCD's indexes are shuffled to be
John@4 30 -- between 1-35.
John@4 31 -- Admin 2 on night 3 rolls in 5 new ones and people ABCD and PQRST now all have
John@4 32 -- indexes between 1-9.
John@4 33 -- When these two are resolved against one another, do the 1-9 peopole end up on
John@4 34 -- top of the list compared to those other 30?
John@4 35 --
John@4 36 -- Solution:
John@4 37 -- Need a huge random space with purposely left gaps to leave plenty of room for
John@4 38 -- conflicts.
John@4 39 -- So if ABCD had randomed on a space of say, 10,000 and then were sorted into
John@4 40 -- order, then the next 30 could roll into that same space and have a proper
John@4 41 -- ordering. Then the next 5, etc.
John@4 42 --
John@4 43 -- Handling conflicts:
John@4 44 --
John@9 45 -- Executive decision: random on a range of [0,1], ie math.random
John@9 46 -- then on an add-to-end event just do last + .1
John@9 47 -- disallow random after any add-to-end event occurs
John@9 48 -- because the list either elongates beyond 1 OR becomes
John@9 49 -- ridiculously bottom heavy, thus meaning that randoms
John@9 50 -- don't get an even distibution from then on (in fact
John@9 51 -- they'll end up getting top favor)
John@9 52 -- * if a stream contains a random-add after an add-to-end
John@9 53 -- it is declared invalid. tough tits. it's just not a fair
John@9 54 -- distribution at that point.
John@10 55 -- * actually, fuck it. I'll give them an unlock command and
John@10 56 -- let them screw over their lists :)
John@0 57
John@8 58 -- todo: list-of-lists must not use int indices. those will lead to peril.
John@0 59 bsk.lists = {}
John@8 60 bsk.persons = {}
John@0 61
John@8 62 local raidList = {}
John@8 63 local reserveList = {}
John@8 64 local activeListKey = 1 -- temporary
John@8 65 local personsReverse = {}
John@0 66
John@0 67 local tinsert = table.insert
John@0 68 local sformat = string.format
John@0 69 local getn = table.getn
John@0 70
John@0 71 function bsk:tcopy(to, from)
John@0 72 for k,v in pairs(from) do
John@0 73 if(type(v)=="table") then
John@0 74 to[k] = {}
John@0 75 bsk:tcopy(to[k], v);
John@0 76 else
John@0 77 to[k] = v;
John@0 78 end
John@0 79 end
John@0 80 end
John@0 81 local shallowCopy = function(t)
John@0 82 local u = { }
John@0 83 for k, v in pairs(t) do u[k] = v end
John@0 84 return setmetatable(u, getmetatable(t))
John@0 85 end
John@0 86
John@1 87 -- Debugging {{{
John@9 88 function bsk:PrettyPrintList(listIndex)
John@9 89 local list = bsk.lists[listIndex]
John@9 90 bsk:Print("List: " .. list.name .. " (" .. list.time .. ")")
John@9 91 for i = 1,#list do
John@9 92 bsk:Print(" " .. i .. " - " .. bsk.persons[list[i]].main)
John@9 93 end
John@9 94 end
John@9 95 function bsk:PrettyPrintLists()
John@9 96 for i,_ in pairs(bsk.lists) do
John@9 97 bsk:PrettyPrintList(i)
John@9 98 end
John@9 99 end
John@1 100 function bsk:PrintLists()
John@1 101 bsk:PrintTable(bsk.lists)
John@1 102 end
John@1 103 function bsk:PrintChanges()
John@1 104 bsk:PrintTable(bsk.db.profile.changes)
John@1 105 end
John@8 106 function bsk:PrintPersons()
John@8 107 bsk:PrintTable(bsk.persons)
John@1 108 end
John@0 109 function bsk:PrintTable(table, depth)
John@0 110 depth = depth or ""
John@0 111 if not table then return end
John@0 112 for i,v in pairs(table) do
John@0 113 if( type(v) == "string" ) then
John@0 114 self:Print(depth .. i .. " - " .. v)
John@0 115 elseif( type(v) == "number" ) then
John@0 116 self:Print(depth .. i .. " - " .. tostring(v))
John@0 117 elseif( type(v) == "table" ) then
John@0 118 self:Print(depth .. i .." - ")
John@0 119 self:PrintTable(v,depth.." ")
John@0 120 elseif( type(v) == "boolean" ) then
John@0 121 self:Print(depth .. i .. " - " .. tostring(v))
John@0 122 else
John@0 123 self:Print(depth .. i .. " - not sure how to print type: " .. type(v) )
John@0 124 end
John@0 125 end
John@0 126 end
John@0 127
John@0 128 --}}}
John@0 129
John@9 130 function bsk:UpdatePersonsReverse()
John@9 131 for i,v in pairs(bsk.persons) do
John@9 132 if i ~= "time" then
John@9 133 personsReverse[v.main] = i
John@9 134 end
John@9 135 end
John@9 136 end
John@9 137
John@5 138 function bsk:CreateWorkingStateFromChanges(changes)
John@8 139 local personsBase = self.db.profile.persons
John@0 140 local listBase = self.db.profile.listBase
John@0 141
John@0 142 -- copy the base to the working state
John@0 143 wipe(bsk.lists)
John@8 144 wipe(bsk.persons)
John@8 145 wipe(personsReverse)
John@8 146
John@0 147 bsk:tcopy(bsk.lists,listBase)
John@8 148 bsk:tcopy(bsk.persons,personsBase)
John@0 149
John@0 150 -- now just go through the changes list applying each
John@5 151 for i,v in ipairs(changes) do
John@0 152 bsk:ProcessChange(v)
John@0 153 end
John@9 154
John@9 155 -- update the persons reverse list
John@9 156 bsk:UpdatePersonsReverse()
John@0 157 end
John@0 158
John@0 159 function bsk:CreateChange(change)
John@0 160 -- sanity
John@0 161 assert(change)
John@0 162 assert(change.action)
John@0 163 assert(change.arg)
John@0 164
John@0 165 bsk:StartChange(change)
John@0 166 bsk:CommitChange(change)
John@0 167 end
John@0 168
John@0 169 function bsk:StartChange(change)
John@0 170 local changes = self.db.profile.changes
John@0 171 change.time = time()
John@0 172 local n = getn(changes)
John@0 173 if n > 0 then
John@0 174 if changes[n].time >= change.time then
John@0 175 change.time = changes[n].time + 1
John@0 176 end
John@0 177 end
John@0 178 end
John@0 179
John@0 180 function bsk:CommitChange(change)
John@0 181 local changes = self.db.profile.changes
John@0 182 tinsert(changes,change)
John@0 183 -- TODO: broadcast change
John@0 184 end
John@0 185
John@0 186
John@0 187 -- timestamp logic:
John@0 188 -- use time() for comparisons - local clients use date() to make it pretty. only
John@0 189 -- dowisde - we can't have a server timestamp. Which kind of sucks, but it turns
John@0 190 -- out you can change timezones when you enter an instance server, so you really
John@0 191 -- never know what time it is.
John@0 192 -- There's unfortunately no hard-and-proven method for determining the true time
John@0 193 -- difference between local time and server time. You can't just query the two
John@0 194 -- and compare them because your server timezone can change (!) if you go into
John@0 195 -- an instance server with a different timezone. This is apparently a big
John@0 196 -- problem on Oceanic realms.
John@0 197 --
John@0 198 -- Timestamp handling (brainstorming how to deal with drift):
John@0 199 -- (not an issue) if someone sends you time in the future, update your offset so you won't
John@0 200 -- send out events in the "past" to that person
John@0 201 -- (not an issue - using local UTC now) on change-zone-event: check if you've changed timezones - might need update
John@0 202 -- each time you add a change, check the tail of the change list; if this is
John@0 203 -- less than that, you have a problem. Print a message. if this is equal, then
John@0 204 -- that's ok, just bump it by 1 second. This could happen in the case of, say,
John@0 205 -- spam-clicking the undo button or adding names to the list. The recipients
John@0 206 -- should be ok with this since they'll follow the same algorithm. The only
John@0 207 -- real chance for a problem is if two people click within the 1 second window?
John@0 208 -- if someone sends you a past event,
John@0 209 -- it's ok if it's newer than anything in the changes list
John@0 210 -- otherwise ... causality has been violated.
John@0 211 -- Whenever an admin signon event happens, have the admins each perform a
John@0 212 -- timestamp check. Issue warnings for anyone with a clock that's more than
John@0 213 -- X seconds out of sync with the others. Seriously, why isn't NTP a standard
John@0 214 -- setting on all operating systems ...
John@0 215
John@0 216 function bsk:ProcessChange(change)
John@8 217 if change.action == "AddPerson" then
John@8 218 bsk:DoAddPerson(change)
John@0 219 elseif change.action == "CreateList" then
John@0 220 bsk:DoCreateList(change)
John@10 221 elseif change.action == "AddToListEnd" then
John@10 222 bsk:DoAddPersonToListEnd(change)
John@10 223 elseif change.action == "AddToListRand" then
John@10 224 bsk:DoAddPersonToListRandom(change)
John@8 225 elseif change.action == "SuicidePerson" then
John@8 226 bsk:DoSuicidePerson(change)
John@0 227 else
John@0 228 bsk:Print("Unknown message encountered")
John@0 229 bsk:PrintTable(change)
John@0 230 assert(false)
John@0 231 end
John@0 232 end
John@0 233
John@1 234 -- Action and DoAction defs {{{
John@0 235 --
John@0 236 -- The actual actions for changes start here
John@0 237 --
John@0 238 -- Each action occurs as a pair of functions. The bsk:Action() function is from
John@0 239 -- a list admin's point of view. Each will check for admin status, then create a
John@0 240 -- change bundle, call the handler for that change (ie the DoAction func), and
John@0 241 -- then record/transmist the bundle. These are simple and repetitive functions.
John@0 242 --
John@0 243 -- The bsk:DoAction() function is tasked with executing the bundle and is what
John@0 244 -- non-admins and admins alike will call to transform their working state via a
John@0 245 -- change packet. Each Do() function will accept *only* a change packet, and
John@0 246 -- it's assumed that the change has been vetted elsewhere. These are very blunt
John@0 247 -- routines.
John@0 248 --
John@0 249 -- Note that "undo" has no special voodoo to it. It's basically a change that
John@0 250 -- reverses the prior change on the stack.
John@0 251
John@8 252 -- persons list
John@8 253 function bsk:DoAddPerson(change)
John@0 254 assert(change)
John@8 255 assert(change.arg.id)
John@0 256 local arg = change.arg
John@0 257 -- require admin
John@8 258 local persons = bsk.persons
John@0 259 local name = arg.name
John@8 260 local id = arg.id
John@8 261 assert(persons[id]==nil)
John@8 262 persons[id] = {main=name}
John@8 263 persons.time=change.time
John@8 264 personsReverse[name] = id
John@0 265 return true
John@0 266 end
John@0 267
John@8 268 function bsk:AddPerson(name)
John@8 269 local persons = bsk.persons
John@0 270 local guid = UnitGUID(name)
John@0 271 -- TODO: check guid to be sure it's a player
John@0 272 if not guid then
John@0 273 self:Print(sformat("Could not add player %s - they must be in range or group",name))
John@0 274 return
John@0 275 end
John@8 276 local id = string.sub(guid,6) -- skip at least 0x0580 ...
John@8 277 id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining
John@8 278
John@8 279 if persons[id] and persons[id] ~= name then
John@8 280 self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id], name))
John@0 281 return
John@0 282 end
John@8 283 if persons[id] ~= nil then
John@8 284 self:Print(sformat("%s is already in the persons list; disregarding", name))
John@0 285 return
John@0 286 end
John@8 287 local change = {action="AddPerson",arg={name=name,id=id}}
John@8 288 if bsk:DoAddPerson(change) then
John@0 289 bsk:CreateChange(change)
John@0 290 end
John@0 291 end
John@0 292
John@0 293 function bsk:DoCreateList(change)
John@0 294 -- TODO: this segment will probably be useful as bsk:SearchForListByName
John@0 295 local lists = bsk.lists
John@0 296 for i,v in pairs(lists) do
John@0 297 if v.name == change.arg.name then
John@0 298 self:Print(sformat("List %s already exists",v.name))
John@0 299 return false
John@0 300 end
John@0 301 end
John@0 302 tinsert(lists,{name=change.arg.name,time=change.time})
John@0 303 return true
John@0 304 end
John@0 305
John@0 306 function bsk:CreateList(name)
John@0 307 -- require admin
John@0 308 local change={action="CreateList",arg={name=name}}
John@0 309 bsk:StartChange(change)
John@0 310 self:Print("Creating ... " .. name)
John@0 311 if bsk:DoCreateList(change) then
John@0 312 bsk:CommitChange(change)
John@0 313 end
John@0 314 end
John@0 315
John@10 316 function bsk:DoAddPersonToListEnd(change)
John@10 317 local list = bsk.lists[change.arg.listIndex]
John@10 318 local index = list[#list].index + 0.1;
John@10 319 local entry = {index=index, id=change.arg.id}
John@0 320
John@10 321 tinsert(list,entry)
John@10 322 list.time = change.time
John@10 323 list.closedRandom = true
John@10 324
John@0 325 return true
John@0 326 end
John@0 327
John@10 328 function bsk:AddPersonToListEnd(name,list)
John@0 329 -- require admin
John@0 330 local listIndex = bsk:GetListIndex(list)
John@8 331 local id = personsReverse[name]
John@9 332 bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, list, listIndex))
John@10 333 local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}}
John@0 334 bsk:StartChange(change)
John@10 335 if bsk:DoAddPersonToListEnd(change) then
John@10 336 bsk:CommitChange(change)
John@10 337 end
John@10 338 end
John@10 339
John@10 340 function bsk:DoAddPersonToListRandom(change)
John@10 341 local list = bsk.lists[change.arg.listIndex]
John@10 342 local entry = {index=change.arg.roll, id=change.arg.id}
John@10 343
John@10 344 tinsert(list,entry)
John@10 345 table.sort(list,function(a,b) return a.roll < b.roll end)
John@10 346 list.time = change.time
John@10 347
John@10 348 return true
John@10 349 end
John@10 350
John@10 351 function bsk:AddPersonToListRandom(name,list)
John@10 352 -- require admin
John@10 353 local listIndex = bsk:GetListIndex(list)
John@10 354 if bsk.lists[listIndex].closedRandom then
John@10 355 self:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred")
John@10 356 end
John@10 357 local id = personsReverse[name]
John@10 358 local roll = math.random()
John@10 359 bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, list, listIndex, roll))
John@10 360 local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}}
John@10 361 bsk:StartChange(change)
John@10 362 if bsk:DoAddPersonToListRandom(change) then
John@0 363 bsk:CommitChange(change)
John@0 364 end
John@0 365 end
John@0 366
John@8 367 function bsk:DoRemovePerson(change)
John@0 368
John@0 369 -- return true
John@0 370 end
John@0 371
John@8 372 function bsk:RemovePerson(name)
John@8 373 -- from both persons and lists
John@0 374 end
John@0 375
John@8 376 function bsk:DoSuicidePerson(change)
John@0 377 local listIndex = change.arg.listIndex
John@0 378 local list = bsk.lists[listIndex]
John@0 379 local slist = shallowCopy(change.arg.list)
John@0 380 -- the goal here is to rotate the suicide list by 1
John@0 381 -- then we can just mash it on top of the intersection between the original
John@0 382 -- list and the working copy
John@0 383 local stemp = shallowCopy(change.arg.list)
John@0 384 local temp = table.remove(stemp,1) -- pop
John@0 385 tinsert(stemp,temp) -- push_back
John@0 386 --bsk:Print(sformat("Before suicide of %s on list %s",slist[1],list.name))
John@0 387 --bsk:PrintTable(list)
John@0 388 for i = 1, #list do
John@10 389 if list[i].id == slist[1] then
John@0 390 table.remove(slist,1)
John@10 391 list[i].id = stemp[1]
John@0 392 table.remove(stemp,1)
John@0 393 end
John@0 394 end
John@0 395 list.time=change.time
John@0 396 return true
John@0 397 end
John@0 398
John@8 399 function bsk:SuicidePerson(name,list)
John@0 400 -- require admin
John@0 401 bsk:PopulateRaidList()
John@0 402 local listIndex = bsk:GetListIndex(list)
John@1 403 local slist=bsk:GetSuicideList(name,bsk.lists[listIndex])
John@8 404 local change = {action="SuicidePerson",arg={names=names,list=slist,listIndex=listIndex}}
John@10 405 bsk:PrintTable(change)
John@0 406 bsk:StartChange(change)
John@8 407 if bsk:DoSuicidePerson(change) then
John@0 408 bsk:CommitChange(change)
John@0 409 end
John@0 410 end
John@5 411
John@5 412 function bsk:TrimLists(time)
John@5 413 if not bsk:CheckListCausality() then
John@5 414 self:Print("Unable to trim lists due to violated causality")
John@5 415
John@5 416 return false
John@5 417 end
John@5 418
John@5 419 if type(time) ~= "number" then
John@5 420 time = tonumber(time)
John@5 421 end
John@5 422
John@5 423 -- bisect the changes list by "time"
John@5 424 local before = {}
John@5 425 for i,v in ipairs(self.db.profile.changes) do
John@5 426 if v.time <= time then
John@5 427 tinsert(before,v)
John@5 428 else
John@5 429 break
John@5 430 end
John@5 431 end
John@5 432
John@5 433 -- apply first half
John@5 434 bsk:CreateWorkingStateFromChanges(before)
John@5 435
John@5 436 -- save this state permanently; trim the changes permanently
John@8 437 bsk:tcopy(bsk.db.profile.persons,bsk.persons)
John@5 438 bsk:tcopy(bsk.db.profile.listBase,bsk.lists)
John@8 439 while bsk.db.profile.changes ~= nil and bsk.db.profile.changes[1] ~= nil and bsk.db.profile.changes[1].time <= time do
John@5 440 table.remove(bsk.db.profile.changes,1)
John@5 441 end
John@5 442
John@5 443 -- using the trimmed list and the new bases, recreate the working state
John@5 444 bsk:CreateWorkingStateFromChanges(bsk.db.profile.changes)
John@5 445 end
John@5 446
John@1 447 --}}}
John@1 448 -- Higher order actions (ie calls other Doers){{{
John@8 449 function bsk:AddMissingPersons()
John@1 450 bsk:PopulateRaidList()
John@1 451 local t = {}
John@8 452 for _,v in pairs(bsk.persons) do
John@8 453 t[v.main] = true
John@8 454 -- TODO: also add alts here
John@1 455 end
John@8 456 for i,_ in pairs(raidList) do
John@2 457 if t[i] == nil then
John@8 458 bsk:Print(sformat("Person %s is missing from the persons list - adding",i))
John@8 459 bsk:AddPerson(i)
John@1 460 end
John@1 461 end
John@1 462 -- TODO: batch into a single op - no need to spam 25 messages in a row
John@1 463 end
John@3 464 function bsk:PopulateListRandom(index)
John@3 465 -- difference (raid+reserve)^list, then random shuffle that, then add
John@3 466 bsk:PopulateRaidList()
John@3 467 local list = bsk.lists[index]
John@3 468
John@3 469 local t = {}
John@3 470 --for i = 1,#list do
John@8 471 -- if not (raidList(list[i]) or reserveList(list[i])) then
John@3 472 -- tinsert(t,)
John@3 473 -- end
John@3 474 --end
John@3 475 end
John@1 476 --}}}
John@1 477
John@1 478 -- "Soft" actions- ie things that cause nonpermanent state {{{
John@1 479
John@1 480 -- reserves
John@1 481 function bsk:AddReserve(name)
John@8 482 reserveList[name]=true
John@1 483 -- TODO: communicate to others. don't store this in any way.
John@1 484 end
John@1 485
John@1 486 function bsk:RemoveReserve(name)
John@8 487 reserveList[name]=false
John@1 488 -- TODO: communicate to others. don't store this in any way.
John@1 489 end
John@1 490
John@1 491
John@1 492 --function bsk:GetActiveList()
John@1 493 -- return bsk.lists[1] -- todo!
John@1 494 --end
John@1 495
John@1 496 --}}}
John@0 497
John@0 498 -- The following code is from Xinhuan (wowace forum member)
John@0 499 -- Pre-create the unitID strings we will use
John@0 500 local pID = {}
John@0 501 local rID = {}
John@0 502 for i = 1, 4 do
John@0 503 pID[i] = format("party%d", i)
John@0 504 end
John@0 505 for i = 1, 40 do
John@0 506 rID[i] = format("raid%d", i)
John@0 507 end
John@0 508 function bsk:PopulateRaidList()
John@0 509 local inParty = GetNumPartyMembers()
John@0 510 local inRaid = GetNumRaidMembers()
John@0 511
John@8 512 wipe(raidList)
John@0 513 if inRaid > 0 then
John@0 514 for i = 1, inRaid do
John@8 515 raidList[UnitName(rID[i])]=true
John@0 516 end
John@0 517 elseif inParty > 0 then
John@0 518 for i = 1, inParty do
John@8 519 raidList[UnitName(pID[i])]=true
John@0 520 end
John@0 521 -- Now add yourself as the last party member
John@8 522 raidList[UnitName("player")]=true
John@0 523 else
John@0 524 -- You're alone
John@8 525 raidList[UnitName("player")]=true
John@0 526 end
John@0 527 end
John@0 528
John@0 529 -- undo rules!
John@0 530 -- only the most recent event can be undone
John@0 531 -- ^^^ on a given list?
John@0 532 -- algorithm is easy, given "Suicide A B C"
John@0 533 -- just find A,B,C in the list and replace in order from the s message
John@0 534 -- while undo is allowed *per-list*, certain events in the stream will
John@0 535 -- prevent proper undo, such as add/delete player or add/delete list
John@0 536
John@0 537
John@1 538 function bsk:GetSuicideList(name,list)
John@1 539 --self:Print("Calculating changeset for "..name.." from list -")
John@1 540 --self:PrintTable(list)
John@1 541 local t = {}
John@1 542 local ret = {}
John@1 543 local pushing = false
John@1 544 for i = 1, #list do
John@1 545 if list[i] == name then
John@1 546 pushing = true
John@1 547 end
John@8 548 if pushing and (raidList[list[i]] or reserveList[list[i]]) then
John@10 549 tinsert(ret,list[i].id)
John@1 550 end
John@1 551 end
John@1 552 return ret
John@0 553 end
John@0 554
John@5 555 -- returns true if the events in the list are in time order
John@5 556 function bsk:CheckListCausality()
John@5 557 local t = nil
John@5 558 for i,v in ipairs(bsk.db.profile.changes) do
John@5 559 if t ~= nil then
John@5 560 if v.time <= t then
John@5 561 return false
John@5 562 end
John@5 563 end
John@5 564 t = v.time
John@5 565 end
John@5 566 return true
John@5 567 end
John@0 568
John@0 569 -- Support functions
John@0 570
John@0 571 function bsk:GetListIndex(name)
John@0 572 for i,v in pairs(bsk.lists) do
John@0 573 if v.name == name then
John@0 574 return i
John@0 575 end
John@0 576 end
John@0 577 assert(false)
John@0 578 end
John@1 579
John@3 580 local shuffleArray = function(array)
John@3 581 local arrayCount = #array
John@3 582 for i = arrayCount, 2, -1 do
John@3 583 local j = math.random(1, i)
John@3 584 array[i], array[j] = array[j], array[i]
John@3 585 end
John@3 586 return array
John@3 587 end
John@3 588