comparison 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
comparison
equal deleted inserted replaced
90:dcbe1f04bb31 91:5ade79caeece
83 local getmetatable=getmetatable 83 local getmetatable=getmetatable
84 local setmetatable=setmetatable 84 local setmetatable=setmetatable
85 setfenv(1,bsk) 85 setfenv(1,bsk)
86 86
87 changeListener = nil -- todo: really should not be scoped like this 87 changeListener = nil -- todo: really should not be scoped like this
88 timestamp = 0
88 89
89 ListEntry = 90 ListEntry =
90 { 91 {
91 index = 0.0, 92 index = 0.0,
92 id = 0, 93 id = 0,
439 local te = Toon:new(v) 440 local te = Toon:new(v)
440 table.insert(self.toons,te) 441 table.insert(self.toons,te)
441 end 442 end
442 end 443 end
443 function PersonList:SaveToDB(db) 444 function PersonList:SaveToDB(db)
444 db.profile.persons = { toons=self.toons, time=self.time } 445 db.profile.persons = { toons=self.toons, time=self.time } -- if this changes, also check the comm functions that send persons
445 end 446 end
446 function PersonList:Reset() 447 function PersonList:Reset()
447 self.toons = {} 448 self.toons = {}
448 self.time = 0 449 self.time = 0
449 self.active = { raid={}, reserve={}, raidExtras={} } 450 self.active = { raid={}, reserve={}, raidExtras={} }
635 function ProcessChange(change) 636 function ProcessChange(change)
636 -- try list-o-lists and persons - if has matching function, call it 637 -- try list-o-lists and persons - if has matching function, call it
637 local action = change.action 638 local action = change.action
638 if PersonList[action] then 639 if PersonList[action] then
639 PersonList[action](PersonList,change.arg,change.time) 640 PersonList[action](PersonList,change.arg,change.time)
641 timestamp = change.time
640 return 642 return
641 elseif LootLists[action] then 643 elseif LootLists[action] then
642 LootLists[action](LootLists,change.arg,change.time) 644 LootLists[action](LootLists,change.arg,change.time)
645 timestamp = change.time
643 return 646 return
644 else 647 else
645 -- pray that the change has a listIndex in it ... 648 -- pray that the change has a listIndex in it ...
646 if change.arg.listIndex then 649 if change.arg.listIndex then
647 local l = LootLists:Select(change.arg.listIndex) 650 local l = LootLists:Select(change.arg.listIndex)
648 if l and l[action] then 651 if l and l[action] then
649 l[action](l,change.arg,change.time) 652 l[action](l,change.arg,change.time)
653 timestamp = change.time
650 return 654 return
651 end 655 end
652 end 656 end
653 end 657 end
654 _G.error("Could not process change: " .. change.action) 658 _G.error("Could not process change: " .. change.action)
655 end 659 end
656 660
657 function SelfDestruct() 661 function SelfDestruct()
658 LootLists:Reset() 662 LootLists:Reset()
659 PersonList:Reset() 663 PersonList:Reset()
664 db.profile.time = 0
660 db.profile.persons = {} 665 db.profile.persons = {}
661 db.profile.changes = {} 666 db.profile.changes = {}
662 db.profile.lists = {} 667 db.profile.lists = {}
663 end 668 end
664 669
704 -- Change processing {{{ 709 -- Change processing {{{
705 function CreateWorkingStateFromChanges(changes) 710 function CreateWorkingStateFromChanges(changes)
706 -- copy the base to the working state 711 -- copy the base to the working state
707 LootLists:ConstructFromDB(db) 712 LootLists:ConstructFromDB(db)
708 PersonList:ConstructFromDB(db) 713 PersonList:ConstructFromDB(db)
714 timestamp = db.profile.time
709 715
710 -- now just go through the changes list applying each 716 -- now just go through the changes list applying each
711 for i,v in ipairs(changes) do 717 for i,v in ipairs(changes) do
712 ProcessChange(v) 718 ProcessChange(v)
713 end 719 end
832 time = tonumber(time) 838 time = tonumber(time)
833 end 839 end
834 840
835 -- bisect the changes list by "time" 841 -- bisect the changes list by "time"
836 local before = {} 842 local before = {}
843 local lastTime = 0
837 for i,v in ipairs(db.profile.changes) do 844 for i,v in ipairs(db.profile.changes) do
838 if v.time <= time then 845 if v.time <= time then
839 tinsert(before,v) 846 tinsert(before,v)
847 lastTime = v.time
840 else 848 else
841 break 849 break
842 end 850 end
843 end 851 end
844 852
849 LootLists:SaveToDB(db) 857 LootLists:SaveToDB(db)
850 PersonList:SaveToDB(db) 858 PersonList:SaveToDB(db)
851 while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do 859 while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do
852 table.remove(db.profile.changes,1) 860 table.remove(db.profile.changes,1)
853 end 861 end
862 db.profile.time = lastTime
854 863
855 -- using the trimmed list and the new bases, recreate the working state 864 -- using the trimmed list and the new bases, recreate the working state
856 CreateWorkingStateFromChanges(db.profile.changes) 865 CreateWorkingStateFromChanges(db.profile.changes)
857 end 866 end
858 867