comparison Lists.lua @ 37:6362fe301d43

Storing class name in the persons so we can color them in later Exposing some data lists, but this will likely be retracted later in favor of interface functions
author John@Yosemite-PC
date Tue, 13 Mar 2012 23:17:18 -0400
parents ecd37523ae04
children ecef0cba2913
comparison
equal deleted inserted replaced
36:cc25a1a51291 37:6362fe301d43
66 -- leads to a raidIdP 66 -- leads to a raidIdP
67 67
68 bsk.lists = {} 68 bsk.lists = {}
69 bsk.persons = {} 69 bsk.persons = {}
70 70
71 local raidNameP = {} -- "name" is present in raid 71 bsk.raidNameP = {} -- "name" is present in raid
72 local raidIdP = {} -- "id" is present in raid 72 bsk.raidIdP = {} -- "id" is present in raid
73 local reserveIdP = {} -- "reserve id present" 73 bsk.reserveIdP = {} -- "reserve id present"
74 local activeListKey = 1 -- temporary 74 local activeListKey = 1 -- temporary
75 local personName2id = {} -- given "name" get that person's id 75 local personName2id = {} -- given "name" get that person's id
76 76
77 local tinsert = table.insert 77 local tinsert = table.insert
78 local sformat = string.format 78 local sformat = string.format
82 bsk.lists = {} 82 bsk.lists = {}
83 bsk.persons = {} 83 bsk.persons = {}
84 bsk.db.profile.persons = {} 84 bsk.db.profile.persons = {}
85 bsk.db.profile.changes = {} 85 bsk.db.profile.changes = {}
86 bsk.db.profile.lists = {} 86 bsk.db.profile.lists = {}
87 raidNameP = {} 87 bsk.raidNameP = {}
88 raidIdP = {} 88 bsk.raidIdP = {}
89 reserveIdP = {} 89 bsk.reserveIdP = {}
90 personName2id = {} 90 personName2id = {}
91 end 91 end
92 function bsk:tcopy(to, from) 92 function bsk:tcopy(to, from)
93 for k,v in pairs(from) do 93 for k,v in pairs(from) do
94 if(type(v)=="table") then 94 if(type(v)=="table") then
128 bsk:PrintTable(bsk.persons) 128 bsk:PrintTable(bsk.persons)
129 end 129 end
130 function bsk:PrintTable(table, depth) 130 function bsk:PrintTable(table, depth)
131 depth = depth or "" 131 depth = depth or ""
132 if not table then return end 132 if not table then return end
133 if #depth > 3*5 then self:Print(depth.."Recursion too deep - stopping"); return end
133 for i,v in pairs(table) do 134 for i,v in pairs(table) do
134 if( type(v) == "string" ) then 135 if( type(v) == "string" ) then
135 self:Print(depth .. i .. " - " .. v) 136 self:Print(depth .. i .. " - " .. v)
136 elseif( type(v) == "number" ) then 137 elseif( type(v) == "number" ) then
137 self:Print(depth .. i .. " - " .. tostring(v)) 138 self:Print(depth .. i .. " - " .. tostring(v))
138 elseif( type(v) == "table" ) then 139 elseif( type(v) == "table" ) then
139 self:Print(depth .. i .." - ") 140 self:Print(depth .. i .." - ")
140 self:PrintTable(v,depth.." ") 141 self:PrintTable(v,depth.." ")
141 elseif( type(v) == "boolean" ) then 142 elseif( type(v) == "boolean" ) then
142 self:Print(depth .. i .. " - " .. tostring(v)) 143 self:Print(depth .. i .. " - " .. tostring(v))
144 elseif( type(v) == "function" ) then
145 self:Print(depth .. "function " .. i .. "()")
143 else 146 else
144 self:Print(depth .. i .. " - not sure how to print type: " .. type(v) ) 147 self:Print(depth .. i .. " - not sure how to print type: " .. type(v) )
145 end 148 end
146 end 149 end
147 end 150 end
148 151
149 function bsk:PrintRaidAndReserve() 152 function bsk:PrintRaidAndReserve()
150 bsk:Print("RaidNameP") 153 bsk:Print("RaidNameP")
151 bsk:PrintTable(raidNameP) 154 bsk:PrintTable(bsk.raidNameP)
152 bsk:Print("RaidIdP") 155 bsk:Print("RaidIdP")
153 bsk:PrintTable(raidIdP) 156 bsk:PrintTable(bsk.raidIdP)
154 bsk:Print("ReserveP") 157 bsk:Print("ReserveP")
155 bsk:PrintTable(reserveIdP) 158 bsk:PrintTable(bsk.reserveIdP)
156 bsk:Print("personName2id") 159 bsk:Print("personName2id")
157 bsk:PrintTable(personName2id) 160 bsk:PrintTable(personName2id)
158 end 161 end
159 --}}} 162 --}}}
160 163
291 -- Note that "undo" has no special voodoo to it. It's basically a change that 294 -- Note that "undo" has no special voodoo to it. It's basically a change that
292 -- reverses the prior change on the stack.--}}} 295 -- reverses the prior change on the stack.--}}}
293 function bsk:DoAddPerson(change)--{{{ 296 function bsk:DoAddPerson(change)--{{{
294 assert(change) 297 assert(change)
295 assert(change.arg.id) 298 assert(change.arg.id)
296 local arg = change.arg
297 -- require admin 299 -- require admin
298 local persons = bsk.persons 300 local persons = bsk.persons
299 local name = arg.name 301 local name = change.arg.name
300 local id = arg.id 302 local id = change.arg.id
301 assert(persons[id]==nil) 303 assert(persons[id]==nil)
302 persons[id] = {main=name} 304 persons[id] = {main=name,class=change.arg.class}
303 persons.time=change.time 305 persons.time=change.time
304 personName2id[name] = id 306 personName2id[name] = id
305 return true 307 return true
306 end--}}} 308 end--}}}
307 function bsk:AddPerson(name)--{{{ 309 function bsk:AddPerson(name)--{{{
310 -- TODO: check guid to be sure it's a player 312 -- TODO: check guid to be sure it's a player
311 if not guid then 313 if not guid then
312 self:Print(sformat("Could not add player %s - they must be in range or group",name)) 314 self:Print(sformat("Could not add player %s - they must be in range or group",name))
313 return 315 return
314 end 316 end
317 local _,englishClass = UnitClass(name)
318 --bsk:Print("Person " .. name .. " is class " .. englishClass)
315 local id = string.sub(guid,6) -- skip at least 0x0580 ... 319 local id = string.sub(guid,6) -- skip at least 0x0580 ...
316 id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining 320 id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining
317 321
318 if persons[id] and persons[id] ~= name then 322 if persons[id] and persons[id] ~= name then
319 self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name)) 323 self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name))
321 end 325 end
322 if persons[id] ~= nil then 326 if persons[id] ~= nil then
323 self:Print(sformat("%s is already in the persons list; disregarding", name)) 327 self:Print(sformat("%s is already in the persons list; disregarding", name))
324 return 328 return
325 end 329 end
326 local change = {action="AddPerson",arg={name=name,id=id}} 330 local change = {action="AddPerson",arg={name=name,id=id,class=englishClass}}
327 if bsk:DoAddPerson(change) then 331 if bsk:DoAddPerson(change) then
328 bsk:CreateChange(change) 332 bsk:CreateChange(change)
329 end 333 end
330 end--}}} 334 end--}}}
331 function bsk:DoCreateList(change)--{{{ 335 function bsk:DoCreateList(change)--{{{
563 bsk:PopulateRaidList() 567 bsk:PopulateRaidList()
564 local t = {} 568 local t = {}
565 for id,_ in pairs(bsk.persons) do 569 for id,_ in pairs(bsk.persons) do
566 t[id] = true 570 t[id] = true
567 end 571 end
568 for name,_ in pairs(raidNameP) do 572 for name,_ in pairs(bsk.raidNameP) do
569 if personName2id[name] == nil then 573 if personName2id[name] == nil then
570 bsk:Print(sformat("Person %s is missing from the persons list - adding",name)) 574 bsk:Print(sformat("Person %s is missing from the persons list - adding",name))
571 bsk:AddPerson(name) 575 bsk:AddPerson(name)
572 end 576 end
573 end 577 end
578 -- difference (raid+reserve)-list, then random shuffle that, then add 582 -- difference (raid+reserve)-list, then random shuffle that, then add
579 bsk:PopulateRaidList() 583 bsk:PopulateRaidList()
580 local list = bsk.lists[listIndex] 584 local list = bsk.lists[listIndex]
581 585
582 local t = {} -- after loops, contains intersection of IDs present between raid and reserve 586 local t = {} -- after loops, contains intersection of IDs present between raid and reserve
583 for i,v in pairs(raidIdP) do 587 for i,v in pairs(bsk.raidIdP) do
584 if v then t[i] = true end 588 if v then t[i] = true end
585 end 589 end
586 for i,v in pairs(reserveIdP) do 590 for i,v in pairs(bsk.reserveIdP) do
587 if v then t[i] = true end 591 if v then t[i] = true end
588 end 592 end
589 593
590 -- now remove from t all of the people already present on the list 594 -- now remove from t all of the people already present on the list
591 if list then 595 if list then
614 --}}} 618 --}}}
615 -- "Soft" actions- ie things that cause nonpermanent state {{{ 619 -- "Soft" actions- ie things that cause nonpermanent state {{{
616 620
617 -- reserves 621 -- reserves
618 function bsk:AddReserve(name) 622 function bsk:AddReserve(name)
619 reserveIdP[personName2id[name]]=true 623 bsk.reserveIdP[personName2id[name]]=true
620 -- TODO: communicate to others. don't store this in any way. 624 -- TODO: communicate to others. don't store this in any way.
621 end 625 end
622 626
623 function bsk:RemoveReserve(name) 627 function bsk:RemoveReserve(name)
624 reserveIdP[personName2id[name]]=false 628 bsk.reserveIdP[personName2id[name]]=false
625 -- TODO: communicate to others. don't store this in any way. 629 -- TODO: communicate to others. don't store this in any way.
626 end 630 end
627 631
628 632
629 --function bsk:GetActiveList() 633 --function bsk:GetActiveList()
645 function bsk:PopulateRaidList() 649 function bsk:PopulateRaidList()
646 local inParty = GetNumPartyMembers() 650 local inParty = GetNumPartyMembers()
647 local inRaid = GetNumRaidMembers() 651 local inRaid = GetNumRaidMembers()
648 local add = function(unitNameArg) 652 local add = function(unitNameArg)
649 local name = UnitName(unitNameArg) 653 local name = UnitName(unitNameArg)
650 raidNameP[name]=true 654 bsk.raidNameP[name]=true
651 if personName2id[name] ~= nil then 655 if personName2id[name] ~= nil then
652 raidIdP[personName2id[name]]=true 656 bsk.raidIdP[personName2id[name]]=true
653 end 657 end
654 end 658 end
655 659
656 wipe(raidNameP) 660 wipe(bsk.raidNameP)
657 wipe(raidIdP) 661 wipe(bsk.raidIdP)
658 if inRaid > 0 then 662 if inRaid > 0 then
659 for i = 1, inRaid do 663 for i = 1, inRaid do
660 add(rID[i]) 664 add(rID[i])
661 end 665 end
662 elseif inParty > 0 then 666 elseif inParty > 0 then
667 add("player") 671 add("player")
668 else 672 else
669 -- You're alone 673 -- You're alone
670 add("player") 674 add("player")
671 end 675 end
672 --bsk:PrintTable(raidNameP) 676 --bsk:PrintTable(bsk.raidNameP)
673 end 677 end
674 678
675 -- undo rules! 679 -- undo rules!
676 -- only the most recent event can be undone 680 -- only the most recent event can be undone
677 -- ^^^ on a given list? 681 -- ^^^ on a given list?
689 local pushing = false 693 local pushing = false
690 for i = 1, #list do 694 for i = 1, #list do
691 if list[i].id == id then 695 if list[i].id == id then
692 pushing = true 696 pushing = true
693 end 697 end
694 if pushing and (raidIdP[list[i].id] or reserveIdP[list[i].id]) then 698 if pushing and (bsk.raidIdP[list[i].id] or bsk.reserveIdP[list[i].id]) then
695 tinsert(ret,list[i].id) 699 tinsert(ret,list[i].id)
696 end 700 end
697 end 701 end
698 --bsk:Print("GSL") 702 --bsk:Print("GSL")
699 --bsk:PrintTable(ret) 703 --bsk:PrintTable(ret)