# HG changeset patch # User John@Yosemite-PC # Date 1331355493 18000 # Node ID 27cf1355cd6f0cc942f9acf6a3ff41154339bcdd # Parent ffcea2f51663d52a57f7253d02f7db2bc6a4b423 Bugfixes (changes to zero length lists are killing me) Remove someone from a list diff -r ffcea2f51663 -r 27cf1355cd6f Core.lua --- a/Core.lua Fri Mar 09 23:33:46 2012 -0500 +++ b/Core.lua Fri Mar 09 23:58:13 2012 -0500 @@ -72,6 +72,13 @@ end if param[2] == "list" then bsk:DeleteList(param[3]) + elseif param[2] == "personfromlist" then + if param[4] == nil or param[4] == "" then + bsk:PrintTable(param) + return + end + local person = FixPersonName(param[3]) + bsk:RemovePersonFromList(person, param[4]) else bsk:Print(sformat("Deleting anything of type %s is not supported",param[2])) end diff -r ffcea2f51663 -r 27cf1355cd6f Lists.lua --- a/Lists.lua Fri Mar 09 23:33:46 2012 -0500 +++ b/Lists.lua Fri Mar 09 23:58:13 2012 -0500 @@ -12,7 +12,6 @@ -- TODO: collapse slists into delimited strings for space -- TODO: organize working state data a little more carefully - hard to keep -- track of all the arrays that are floating out there --- TODO: delete list -- TODO: remove player from list -- TODO: (meta) remove player from all lists -- TODO: remove person (actually kinda tricky without casuality problems) @@ -231,6 +230,8 @@ bsk:DoAddPersonToListEnd(change) elseif change.action == "AddToListRand" then bsk:DoAddPersonToListRandom(change) + elseif change.action == "RemovePersonFromList" then + bsk:DoRemovePersonFromList(change) elseif change.action == "SuicidePerson" then bsk:DoSuicidePerson(change) else @@ -352,7 +353,12 @@ function bsk:DoAddPersonToListEnd(change) local list = bsk.lists[change.arg.listIndex] - local index = list[#list].index + 0.1; + local index + if getn(list) > 0 then + index = list[#list].index + 0.1 + else + index = 0.1 + end local entry = {index=index, id=change.arg.id} tinsert(list,entry) @@ -485,6 +491,29 @@ end end +function bsk:DoRemovePersonFromList(change) + local list = bsk.lists[change.arg.listIndex] + + for i,v in pairs(list) do + if v.id == change.arg.id then + table.remove(list,i) + break + end + end + table.sort(list,function(a,b) return a.index < b.index end) + list.time = change.time + return true +end + +function bsk:RemovePersonFromList(name,listName) + local listIndex = bsk:GetListIndex(listName) + local pid = personName2id[name] + local change = {action="RemovePersonFromList",arg={id=pid,listIndex=listIndex}} + bsk:StartChange(change) + if bsk:DoRemovePersonFromList(change) then + bsk:CommitChange(change) + end +end --}}} -- Higher order actions (ie calls other standard actions){{{