comparison Lists.lua @ 22:27cf1355cd6f

Bugfixes (changes to zero length lists are killing me) Remove someone from a list
author John@Yosemite-PC
date Fri, 09 Mar 2012 23:58:13 -0500
parents ffcea2f51663
children ac50a4fc7229
comparison
equal deleted inserted replaced
21:ffcea2f51663 22:27cf1355cd6f
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: organize working state data a little more carefully - hard to keep 13 -- TODO: organize working state data a little more carefully - hard to keep
14 -- track of all the arrays that are floating out there 14 -- track of all the arrays that are floating out there
15 -- TODO: delete list
16 -- TODO: remove player from list 15 -- TODO: remove player from list
17 -- TODO: (meta) remove player from all lists 16 -- TODO: (meta) remove player from all lists
18 -- TODO: remove person (actually kinda tricky without casuality problems) 17 -- TODO: remove person (actually kinda tricky without casuality problems)
19 18
20 -- holy crap long notes {{{ 19 -- holy crap long notes {{{
229 bsk:DoDeleteList(change) 228 bsk:DoDeleteList(change)
230 elseif change.action == "AddToListEnd" then 229 elseif change.action == "AddToListEnd" then
231 bsk:DoAddPersonToListEnd(change) 230 bsk:DoAddPersonToListEnd(change)
232 elseif change.action == "AddToListRand" then 231 elseif change.action == "AddToListRand" then
233 bsk:DoAddPersonToListRandom(change) 232 bsk:DoAddPersonToListRandom(change)
233 elseif change.action == "RemovePersonFromList" then
234 bsk:DoRemovePersonFromList(change)
234 elseif change.action == "SuicidePerson" then 235 elseif change.action == "SuicidePerson" then
235 bsk:DoSuicidePerson(change) 236 bsk:DoSuicidePerson(change)
236 else 237 else
237 bsk:Print("Unknown message encountered") 238 bsk:Print("Unknown message encountered")
238 bsk:PrintTable(change) 239 bsk:PrintTable(change)
350 end 351 end
351 end 352 end
352 353
353 function bsk:DoAddPersonToListEnd(change) 354 function bsk:DoAddPersonToListEnd(change)
354 local list = bsk.lists[change.arg.listIndex] 355 local list = bsk.lists[change.arg.listIndex]
355 local index = list[#list].index + 0.1; 356 local index
357 if getn(list) > 0 then
358 index = list[#list].index + 0.1
359 else
360 index = 0.1
361 end
356 local entry = {index=index, id=change.arg.id} 362 local entry = {index=index, id=change.arg.id}
357 363
358 tinsert(list,entry) 364 tinsert(list,entry)
359 list.time = change.time 365 list.time = change.time
360 list.closedRandom = true 366 list.closedRandom = true
483 if bsk:DoDeleteList(change) then 489 if bsk:DoDeleteList(change) then
484 bsk:CommitChange(change) 490 bsk:CommitChange(change)
485 end 491 end
486 end 492 end
487 493
494 function bsk:DoRemovePersonFromList(change)
495 local list = bsk.lists[change.arg.listIndex]
496
497 for i,v in pairs(list) do
498 if v.id == change.arg.id then
499 table.remove(list,i)
500 break
501 end
502 end
503 table.sort(list,function(a,b) return a.index < b.index end)
504 list.time = change.time
505 return true
506 end
507
508 function bsk:RemovePersonFromList(name,listName)
509 local listIndex = bsk:GetListIndex(listName)
510 local pid = personName2id[name]
511 local change = {action="RemovePersonFromList",arg={id=pid,listIndex=listIndex}}
512 bsk:StartChange(change)
513 if bsk:DoRemovePersonFromList(change) then
514 bsk:CommitChange(change)
515 end
516 end
488 --}}} 517 --}}}
489 -- Higher order actions (ie calls other standard actions){{{ 518 -- Higher order actions (ie calls other standard actions){{{
490 519
491 function bsk:TrimLists(time) 520 function bsk:TrimLists(time)
492 if not bsk:CheckListCausality() then 521 if not bsk:CheckListCausality() then