Mercurial > wow > breuesk
changeset 9:daed0597deba
Pretty printing for lists
A decision on how to index them up
Bug about reverse list maintenance fixed.
Next step noted.
author | John@Doomsday |
---|---|
date | Wed, 07 Mar 2012 14:56:25 -0500 |
parents | b05fcb225c4a |
children | 433d31ea992a |
files | Core.lua Lists.lua |
diffstat | 2 files changed, 43 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Wed Mar 07 00:18:05 2012 -0500 +++ b/Core.lua Wed Mar 07 14:56:25 2012 -0500 @@ -82,6 +82,13 @@ end elseif param[2] == "list" then bsk:CreateList(param[3]) + elseif param[2] == "persontolist" then + if param[4] == nil or param[4] == "" then + bsk:PrintTable(param) + return + end + local person = FixPersonName(param[3]) + bsk:AddPersonToList(person,param[4]) end elseif param[1] == "populate" then if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then @@ -106,7 +113,7 @@ bsk:PrintTable(param) return end - bsk:PrintLists(param[2]) + bsk:PrettyPrintLists(param[2]) elseif param[1] == "trim" then if param[2] == nil or param[2] == "" then bsk:PrintTable(param)
--- a/Lists.lua Wed Mar 07 00:18:05 2012 -0500 +++ b/Lists.lua Wed Mar 07 14:56:25 2012 -0500 @@ -42,6 +42,16 @@ -- -- Handling conflicts: -- +-- Executive decision: random on a range of [0,1], ie math.random +-- then on an add-to-end event just do last + .1 +-- disallow random after any add-to-end event occurs +-- because the list either elongates beyond 1 OR becomes +-- ridiculously bottom heavy, thus meaning that randoms +-- don't get an even distibution from then on (in fact +-- they'll end up getting top favor) +-- * if a stream contains a random-add after an add-to-end +-- it is declared invalid. tough tits. it's just not a fair +-- distribution at that point. -- todo: list-of-lists must not use int indices. those will lead to peril. bsk.lists = {} @@ -73,6 +83,18 @@ end -- Debugging {{{ +function bsk:PrettyPrintList(listIndex) + local list = bsk.lists[listIndex] + bsk:Print("List: " .. list.name .. " (" .. list.time .. ")") + for i = 1,#list do + bsk:Print(" " .. i .. " - " .. bsk.persons[list[i]].main) + end +end +function bsk:PrettyPrintLists() + for i,_ in pairs(bsk.lists) do + bsk:PrettyPrintList(i) + end +end function bsk:PrintLists() bsk:PrintTable(bsk.lists) end @@ -103,6 +125,14 @@ --}}} +function bsk:UpdatePersonsReverse() + for i,v in pairs(bsk.persons) do + if i ~= "time" then + personsReverse[v.main] = i + end + end +end + function bsk:CreateWorkingStateFromChanges(changes) local personsBase = self.db.profile.persons local listBase = self.db.profile.listBase @@ -119,6 +149,9 @@ for i,v in ipairs(changes) do bsk:ProcessChange(v) end + + -- update the persons reverse list + bsk:UpdatePersonsReverse() end function bsk:CreateChange(change) @@ -276,6 +309,7 @@ end end +-- TODO: break into AddPersonToListEnd and AddPersonToListRandom function bsk:DoAddPersonToList(change) local listIndex = change.arg.listIndex local slist = change.arg.slist @@ -295,6 +329,7 @@ -- require admin local listIndex = bsk:GetListIndex(list) local id = personsReverse[name] + bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, list, listIndex)) local slist = {id} -- TODO: support adding to elsewhere besides the end local change = {action="AddPersonToList",arg={id=id,listIndex=listIndex,slist=slist}} bsk:StartChange(change)