changeset 27:611808dbc0c0

Untested impl for RemovePerson
author John@Yosemite-PC
date Sat, 10 Mar 2012 17:21:48 -0500
parents 4c3140c7a1b4
children eb3a3f69559e
files Core.lua Lists.lua
diffstat 2 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Sat Mar 10 09:05:37 2012 -0500
+++ b/Core.lua	Sat Mar 10 17:21:48 2012 -0500
@@ -5,8 +5,8 @@
 -- order of implementation
 -- (_) lists fully functional (/script interface)
 -- (_) lists single-user functional via command line interface 
--- (_) all actions should reference the player list rather than player names
--- ( ) player entries should persist as long as any list or change references
+-- (*) all actions should reference the player list rather than player names
+-- (?) player entries should persist as long as any list or change references
 -- ( ) convert slist entries down to a delimited string - much smaller
 -- (*) lists store number slots rather than flat indexing
 -- ( ) limited communication - everyone trusts the loot master
--- a/Lists.lua	Sat Mar 10 09:05:37 2012 -0500
+++ b/Lists.lua	Sat Mar 10 17:21:48 2012 -0500
@@ -7,11 +7,12 @@
 -- A separate user list is held - lists index into this
 
 
--- TODO: list trimming
+-- TODO: switch all action functions to use identifiers rather than names
+-- TODO: collaborative list trimming
 -- TODO: collapse slists into delimited strings for space (premature optimization?)
 -- TODO: organize working state data a little more carefully - hard to keep
 -- track of all the arrays that are floating out there
--- TODO: (meta) remove player from all lists
+-- TODO: (meta) remove/nuke player from all lists
 -- TODO: remove person (trivial unless implementing a history viewer or
 -- something)
 
@@ -229,6 +230,8 @@
         bsk:DoAddPersonToListEnd(change)
     elseif change.action == "AddToListRand" then
         bsk:DoAddPersonToListRandom(change)
+    elseif change.action == "RemovePerson" then
+        bsk:DoRemovePerson(change)
     elseif change.action == "RemovePersonFromList" then
         bsk:DoRemovePersonFromList(change)
     elseif change.action == "SuicidePerson" then
@@ -241,7 +244,7 @@
 end
 
 --}}}
-
+-- holy crap long winded {{{
 -- timestamp logic:
 -- use time() for comparisons - local clients use date() to make it pretty. only
 -- dowisde - we can't have a server timestamp. Which kind of sucks, but it turns
@@ -270,9 +273,10 @@
 --  timestamp check. Issue warnings for anyone with a clock that's more than
 --  X seconds out of sync with the others. Seriously, why isn't NTP a standard
 --  setting on all operating systems ...
+--}}}
 
 -- Action and DoAction defs {{{
---
+-- Action Discussion {{{
 -- The actual actions for changes start here
 --
 -- Each action occurs as a pair of functions. The bsk:Action() function is from
@@ -287,8 +291,7 @@
 -- routines.
 --
 -- Note that "undo" has no special voodoo to it. It's basically a change that
--- reverses the prior change on the stack.
-
+-- reverses the prior change on the stack.--}}}
 function bsk:DoAddPerson(change)--{{{
     assert(change)
     assert(change.arg.id)
@@ -407,11 +410,23 @@
     end
 end--}}}
 function bsk:DoRemovePerson(change)--{{{
-
-    -- return true
+    local person = bsk.persons[change.arg.id]
+    personName2id[person.main] = nil
+    bsk.persons[change.arg.id] = nil
+    bsk.persons.time = change.time
+    return true
 end--}}}
 function bsk:RemovePerson(name)--{{{
-    -- from both persons and lists
+    local id = personName2id[name]
+    if not id then
+        bsk:Print(sformat("%s is not in the persons list, please check your spelling", name))
+        return false
+    end
+    local change = {action="RemovePerson",arg={id=id}}
+    bsk:StartChange(change)
+    if bsk:DoRemovePerson() then
+        bsk:CommitChange(change)
+    end
 end--}}}
 function bsk:DoSuicidePerson(change)--{{{
     local list = bsk.lists[change.arg.listIndex]