Mercurial > wow > breuesk
comparison Lists.lua @ 12:a6bc3f2d3207
Many corrections to support ID based lists
| author | John@Yosemite-PC |
|---|---|
| date | Wed, 07 Mar 2012 23:01:33 -0500 |
| parents | 433d31ea992a |
| children | e62cbf3a0c07 |
comparison
equal
deleted
inserted
replaced
| 11:99c279ab0b75 | 12:a6bc3f2d3207 |
|---|---|
| 7 -- A separate user list is held - lists index into this | 7 -- A separate user list is held - lists index into this |
| 8 | 8 |
| 9 | 9 |
| 10 -- TODO: rename player | 10 -- TODO: rename player |
| 11 -- TODO: list trimming | 11 -- TODO: list trimming |
| 12 -- TODO: lists allow double-add | |
| 13 -- TODO: collapse slists into delimited strings for space | |
| 12 | 14 |
| 13 -- notes on list storage: | 15 -- notes on list storage: |
| 14 -- Using names as keys as I do now is atrocious. | 16 -- Using names as keys as I do now is atrocious. |
| 15 -- It prevents insertions (twss) to the middle of the list because then it acts | 17 -- It prevents insertions (twss) to the middle of the list because then it acts |
| 16 -- as a side effect onto all the others. ie ABCD -> AXBCD would be phrased as | 18 -- as a side effect onto all the others. ie ABCD -> AXBCD would be phrased as |
| 87 -- Debugging {{{ | 89 -- Debugging {{{ |
| 88 function bsk:PrettyPrintList(listIndex) | 90 function bsk:PrettyPrintList(listIndex) |
| 89 local list = bsk.lists[listIndex] | 91 local list = bsk.lists[listIndex] |
| 90 bsk:Print("List: " .. list.name .. " (" .. list.time .. ")") | 92 bsk:Print("List: " .. list.name .. " (" .. list.time .. ")") |
| 91 for i = 1,#list do | 93 for i = 1,#list do |
| 92 bsk:Print(" " .. i .. " - " .. bsk.persons[list[i]].main) | 94 bsk:Print(" " .. i .. " - " .. bsk.persons[list[i].id].main) |
| 93 end | 95 end |
| 94 end | 96 end |
| 95 function bsk:PrettyPrintLists() | 97 function bsk:PrettyPrintLists() |
| 96 for i,_ in pairs(bsk.lists) do | 98 for i,_ in pairs(bsk.lists) do |
| 97 bsk:PrettyPrintList(i) | 99 bsk:PrettyPrintList(i) |
| 340 function bsk:DoAddPersonToListRandom(change) | 342 function bsk:DoAddPersonToListRandom(change) |
| 341 local list = bsk.lists[change.arg.listIndex] | 343 local list = bsk.lists[change.arg.listIndex] |
| 342 local entry = {index=change.arg.roll, id=change.arg.id} | 344 local entry = {index=change.arg.roll, id=change.arg.id} |
| 343 | 345 |
| 344 tinsert(list,entry) | 346 tinsert(list,entry) |
| 345 table.sort(list,function(a,b) return a.roll < b.roll end) | 347 table.sort(list,function(a,b) return a.index < b.index end) |
| 346 list.time = change.time | 348 list.time = change.time |
| 347 | 349 |
| 348 return true | 350 return true |
| 349 end | 351 end |
| 350 | 352 |
| 351 function bsk:AddPersonToListRandom(name,list) | 353 function bsk:AddPersonToListRandom(name,list) |
| 352 -- require admin | 354 -- require admin |
| 353 local listIndex = bsk:GetListIndex(list) | 355 local listIndex = bsk:GetListIndex(list) |
| 354 if bsk.lists[listIndex].closedRandom then | 356 if bsk.lists[listIndex].closedRandom then |
| 355 self:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred") | 357 self:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred") |
| 358 return false | |
| 356 end | 359 end |
| 357 local id = personsReverse[name] | 360 local id = personsReverse[name] |
| 358 local roll = math.random() | 361 local roll = math.random() |
| 359 bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, list, listIndex, roll)) | 362 bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, list, listIndex, roll)) |
| 360 local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} | 363 local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} |
| 398 | 401 |
| 399 function bsk:SuicidePerson(name,list) | 402 function bsk:SuicidePerson(name,list) |
| 400 -- require admin | 403 -- require admin |
| 401 bsk:PopulateRaidList() | 404 bsk:PopulateRaidList() |
| 402 local listIndex = bsk:GetListIndex(list) | 405 local listIndex = bsk:GetListIndex(list) |
| 403 local slist=bsk:GetSuicideList(name,bsk.lists[listIndex]) | 406 local id = personsReverse[name] |
| 404 local change = {action="SuicidePerson",arg={names=names,list=slist,listIndex=listIndex}} | 407 local slist=bsk:GetSuicideList(id,bsk.lists[listIndex]) |
| 408 local change = {action="SuicidePerson",arg={list=slist,listIndex=listIndex}} | |
| 405 bsk:PrintTable(change) | 409 bsk:PrintTable(change) |
| 406 bsk:StartChange(change) | 410 bsk:StartChange(change) |
| 407 if bsk:DoSuicidePerson(change) then | 411 if bsk:DoSuicidePerson(change) then |
| 408 bsk:CommitChange(change) | 412 bsk:CommitChange(change) |
| 409 end | 413 end |
| 477 | 481 |
| 478 -- "Soft" actions- ie things that cause nonpermanent state {{{ | 482 -- "Soft" actions- ie things that cause nonpermanent state {{{ |
| 479 | 483 |
| 480 -- reserves | 484 -- reserves |
| 481 function bsk:AddReserve(name) | 485 function bsk:AddReserve(name) |
| 482 reserveList[name]=true | 486 reserveList[personsReverse[name]]=true |
| 483 -- TODO: communicate to others. don't store this in any way. | 487 -- TODO: communicate to others. don't store this in any way. |
| 484 end | 488 end |
| 485 | 489 |
| 486 function bsk:RemoveReserve(name) | 490 function bsk:RemoveReserve(name) |
| 487 reserveList[name]=false | 491 reserveList[personsReverse[name]]=false |
| 488 -- TODO: communicate to others. don't store this in any way. | 492 -- TODO: communicate to others. don't store this in any way. |
| 489 end | 493 end |
| 490 | 494 |
| 491 | 495 |
| 492 --function bsk:GetActiveList() | 496 --function bsk:GetActiveList() |
| 510 local inRaid = GetNumRaidMembers() | 514 local inRaid = GetNumRaidMembers() |
| 511 | 515 |
| 512 wipe(raidList) | 516 wipe(raidList) |
| 513 if inRaid > 0 then | 517 if inRaid > 0 then |
| 514 for i = 1, inRaid do | 518 for i = 1, inRaid do |
| 515 raidList[UnitName(rID[i])]=true | 519 raidList[personsReverse[UnitName(rID[i])]]=true |
| 516 end | 520 end |
| 517 elseif inParty > 0 then | 521 elseif inParty > 0 then |
| 518 for i = 1, inParty do | 522 for i = 1, inParty do |
| 519 raidList[UnitName(pID[i])]=true | 523 raidList[personsReverse[UnitName(pID[i])]]=true |
| 520 end | 524 end |
| 521 -- Now add yourself as the last party member | 525 -- Now add yourself as the last party member |
| 522 raidList[UnitName("player")]=true | 526 raidList[personsReverse[UnitName("player")]]=true |
| 523 else | 527 else |
| 524 -- You're alone | 528 -- You're alone |
| 525 raidList[UnitName("player")]=true | 529 raidList[personsReverse[UnitName("player")]]=true |
| 526 end | 530 end |
| 527 end | 531 end |
| 528 | 532 |
| 529 -- undo rules! | 533 -- undo rules! |
| 530 -- only the most recent event can be undone | 534 -- only the most recent event can be undone |
| 533 -- just find A,B,C in the list and replace in order from the s message | 537 -- just find A,B,C in the list and replace in order from the s message |
| 534 -- while undo is allowed *per-list*, certain events in the stream will | 538 -- while undo is allowed *per-list*, certain events in the stream will |
| 535 -- prevent proper undo, such as add/delete player or add/delete list | 539 -- prevent proper undo, such as add/delete player or add/delete list |
| 536 | 540 |
| 537 | 541 |
| 538 function bsk:GetSuicideList(name,list) | 542 function bsk:GetSuicideList(id,list) |
| 539 --self:Print("Calculating changeset for "..name.." from list -") | 543 --self:Print("Calculating changeset for "..name.." from list -") |
| 540 --self:PrintTable(list) | 544 --self:PrintTable(list) |
| 541 local t = {} | 545 local t = {} |
| 542 local ret = {} | 546 local ret = {} |
| 543 local pushing = false | 547 local pushing = false |
| 544 for i = 1, #list do | 548 for i = 1, #list do |
| 545 if list[i] == name then | 549 if list[i].id == id then |
| 546 pushing = true | 550 pushing = true |
| 547 end | 551 end |
| 548 if pushing and (raidList[list[i]] or reserveList[list[i]]) then | 552 if pushing and (raidList[list[i].id] or reserveList[list[i].id]) then |
| 549 tinsert(ret,list[i].id) | 553 tinsert(ret,list[i].id) |
| 550 end | 554 end |
| 551 end | 555 end |
| 556 bsk:Print("GSL") | |
| 557 bsk:PrintTable(ret) | |
| 558 bsk:Print("GSL") | |
| 552 return ret | 559 return ret |
| 553 end | 560 end |
| 554 | 561 |
| 555 -- returns true if the events in the list are in time order | 562 -- returns true if the events in the list are in time order |
| 556 function bsk:CheckListCausality() | 563 function bsk:CheckListCausality() |
