diff Lists.lua @ 91:5ade79caeece

Starting to add a global timestamp to allow for incremental updates.
author John@Yosemite-PC
date Mon, 16 Apr 2012 07:06:50 -0400
parents 39be9328acd0
children 082ff877c443
line wrap: on
line diff
--- a/Lists.lua	Mon Apr 16 07:06:27 2012 -0400
+++ b/Lists.lua	Mon Apr 16 07:06:50 2012 -0400
@@ -85,6 +85,7 @@
 setfenv(1,bsk)
 
 changeListener = nil -- todo: really should not be scoped like this
+timestamp = 0
 
 ListEntry = 
 {
@@ -441,7 +442,7 @@
     end
 end
 function PersonList:SaveToDB(db)
-    db.profile.persons = { toons=self.toons, time=self.time }
+    db.profile.persons = { toons=self.toons, time=self.time } -- if this changes, also check the comm functions that send persons
 end
 function PersonList:Reset()
     self.toons = {}
@@ -637,9 +638,11 @@
     local action = change.action
     if PersonList[action] then
         PersonList[action](PersonList,change.arg,change.time)
+        timestamp = change.time
         return
     elseif LootLists[action] then
         LootLists[action](LootLists,change.arg,change.time)
+        timestamp = change.time
         return
     else
         -- pray that the change has a listIndex in it ...
@@ -647,6 +650,7 @@
             local l = LootLists:Select(change.arg.listIndex)
             if l and l[action] then
                 l[action](l,change.arg,change.time)
+                timestamp = change.time
                 return
             end
         end
@@ -657,6 +661,7 @@
 function SelfDestruct()
     LootLists:Reset()
     PersonList:Reset()
+    db.profile.time = 0
     db.profile.persons = {}
     db.profile.changes = {}
     db.profile.lists = {}
@@ -706,6 +711,7 @@
     -- copy the base to the working state
     LootLists:ConstructFromDB(db)
     PersonList:ConstructFromDB(db)
+    timestamp = db.profile.time
 
     -- now just go through the changes list applying each
     for i,v in ipairs(changes) do
@@ -834,9 +840,11 @@
 
     -- bisect the changes list by "time"
     local before = {}
+    local lastTime = 0
     for i,v in ipairs(db.profile.changes) do
         if v.time <= time then
             tinsert(before,v)
+            lastTime = v.time
         else
             break
         end
@@ -851,6 +859,7 @@
     while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do
         table.remove(db.profile.changes,1)
     end
+    db.profile.time = lastTime
 
     -- using the trimmed list and the new bases, recreate the working state
     CreateWorkingStateFromChanges(db.profile.changes)