comparison Lists.lua @ 18:bf3e94bc3bf5

Updated todos, lists using creation timestamp as keys
author John@Doomsday
date Fri, 09 Mar 2012 17:35:22 -0500
parents 71fc79846a5d
children cdca1f2ae605
comparison
equal deleted inserted replaced
17:71fc79846a5d 18:bf3e94bc3bf5
8 8
9 9
10 -- TODO: rename player 10 -- TODO: rename player
11 -- TODO: list trimming 11 -- TODO: list trimming
12 -- TODO: collapse slists into delimited strings for space 12 -- TODO: collapse slists into delimited strings for space
13 -- TODO: list-of-lists must not use int indices. those will lead to peril. 13 -- TODO: organize working state data a little more carefully - hard to keep
14 -- track of all the arrays that are floating out there
15 -- TODO: delete list
16 -- TODO: rename list
17 -- TODO: remove player from list
18 -- TODO: (meta) remove player from all lists
19 -- TODO: remove person (actually kinda tricky without casuality problems)
20
14 -- holy crap long notes {{{ 21 -- holy crap long notes {{{
15 -- notes on list storage: 22 -- notes on list storage:
16 -- Using names as keys as I do now is atrocious. 23 -- Using names as keys as I do now is atrocious.
17 -- It prevents insertions (twss) to the middle of the list because then it acts 24 -- It prevents insertions (twss) to the middle of the list because then it acts
18 -- as a side effect onto all the others. ie ABCD -> AXBCD would be phrased as 25 -- as a side effect onto all the others. ie ABCD -> AXBCD would be phrased as
55 -- it is declared invalid. tough tits. it's just not a fair 62 -- it is declared invalid. tough tits. it's just not a fair
56 -- distribution at that point. 63 -- distribution at that point.
57 -- * actually, fuck it. I'll give them an unlock command and 64 -- * actually, fuck it. I'll give them an unlock command and
58 -- let them screw over their lists :) 65 -- let them screw over their lists :)
59 --}}} 66 --}}}
67
60 -- there are some dep chains here. for instance, to have a raidIdP value, a 68 -- there are some dep chains here. for instance, to have a raidIdP value, a
61 -- person must have a bsk.persons value which leads to a personName2id which 69 -- person must have a bsk.persons value which leads to a personName2id which
62 -- leads to a raidIdP 70 -- leads to a raidIdP
63 71
64 bsk.lists = {} 72 bsk.lists = {}
102 end 110 end
103 111
104 -- Debugging {{{ 112 -- Debugging {{{
105 function bsk:PrettyPrintList(listIndex) 113 function bsk:PrettyPrintList(listIndex)
106 local list = bsk.lists[listIndex] 114 local list = bsk.lists[listIndex]
107 bsk:Print("List: " .. list.name .. " (" .. list.time .. ")") 115 bsk:Print("List: " .. list.name .. " (" .. list.id .. ") - last modified" .. date(list.time) .. " (",for)
108 for i = 1,#list do 116 for i = 1,#list do
109 bsk:Print(" " .. i .. " - " .. bsk.persons[list[i].id].main) 117 bsk:Print(" " .. i .. " - " .. bsk.persons[list[i].id].main)
110 end 118 end
111 end 119 end
112 function bsk:PrettyPrintLists() 120 function bsk:PrettyPrintLists()
318 bsk:CreateChange(change) 326 bsk:CreateChange(change)
319 end 327 end
320 end 328 end
321 329
322 function bsk:DoCreateList(change) 330 function bsk:DoCreateList(change)
323 -- TODO: this segment will probably be useful as bsk:SearchForListByName 331 --if bsk:GetListIndex(change.arg.name) then
324 local lists = bsk.lists 332 -- self:Print(sformat("List %s already exists",v.name))
325 for i,v in pairs(lists) do 333 -- return false
326 if v.name == change.arg.name then 334 --end
327 self:Print(sformat("List %s already exists",v.name)) 335 lists[change.arg.id]={name=change.arg.name,time=change.time}
328 return false
329 end
330 end
331 tinsert(lists,{name=change.arg.name,time=change.time})
332 return true 336 return true
333 end 337 end
334 338
335 function bsk:CreateList(name) 339 function bsk:CreateList(name)
336 -- require admin 340 -- require admin
337 local change={action="CreateList",arg={name=name}} 341 local change={action="CreateList",arg={name=name}}
338 bsk:StartChange(change) 342 bsk:StartChange(change)
343 change.arg.id=change.time -- use the creation timestamp as the list's index. it's as unique as anything...
339 self:Print("Creating ... " .. name) 344 self:Print("Creating ... " .. name)
340 if bsk:DoCreateList(change) then 345 if bsk:DoCreateList(change) then
341 bsk:CommitChange(change) 346 bsk:CommitChange(change)
342 end 347 end
343 end 348 end
447 end 452 end
448 end 453 end
449 454
450 function bsk:TrimLists(time) 455 function bsk:TrimLists(time)
451 if not bsk:CheckListCausality() then 456 if not bsk:CheckListCausality() then
452 self:Print("Unable to trim lists due to violated causality") 457 self:Print("Unable to trim changelist due to violated causality")
453 return false 458 return false
454 end 459 end
455 460
456 if type(time) ~= "number" then 461 if type(time) ~= "number" then
457 time = tonumber(time) 462 time = tonumber(time)