Mercurial > wow > breuesk
comparison Lists.lua @ 43:4109683c3172
Kept AceConsole embedded - it handily disables the chat commands when the addon is disabled
Did a little passthrough to properly set the self param for commands like Print()
author | John@Yosemite-PC |
---|---|
date | Thu, 15 Mar 2012 22:27:51 -0400 |
parents | 72055fc7e115 |
children | 8913e7d79cad |
comparison
equal
deleted
inserted
replaced
42:72055fc7e115 | 43:4109683c3172 |
---|---|
122 end | 122 end |
123 | 123 |
124 -- Debugging {{{ | 124 -- Debugging {{{ |
125 function PrettyPrintList(listIndex) | 125 function PrettyPrintList(listIndex) |
126 local list = lists[listIndex] | 126 local list = lists[listIndex] |
127 bsk:Print("List: " .. list.name .. " (" .. listIndex .. ") - last modified " .. date("%m/%d/%y %H:%M:%S", list.time) .. " (",list.time,")" ) | 127 print("List: " .. list.name .. " (" .. listIndex .. ") - last modified " .. date("%m/%d/%y %H:%M:%S", list.time) .. " (",list.time,")" ) |
128 for i = 1,#list do | 128 for i = 1,#list do |
129 bsk:Print(" " .. i .. " - " .. persons[list[i].id].main) | 129 print(" " .. i .. " - " .. persons[list[i].id].main) |
130 end | 130 end |
131 end | 131 end |
132 function PrettyPrintLists() | 132 function PrettyPrintLists() |
133 for i,_ in pairs(lists) do | 133 for i,_ in pairs(lists) do |
134 PrettyPrintList(i) | 134 PrettyPrintList(i) |
144 PrintTable(persons) | 144 PrintTable(persons) |
145 end | 145 end |
146 function PrintAPI(object) | 146 function PrintAPI(object) |
147 for i,v in pairs(object) do | 147 for i,v in pairs(object) do |
148 if type(v) == "function" then | 148 if type(v) == "function" then |
149 bsk:Print("function "..i.."()") | 149 print("function "..i.."()") |
150 end | 150 end |
151 end | 151 end |
152 end | 152 end |
153 function PrintTable(table, depth) | 153 function PrintTable(table, depth) |
154 depth = depth or "" | 154 depth = depth or "" |
155 if not table then return end | 155 if not table then return end |
156 if #depth > 3*5 then bsk:Print(depth.."Recursion too deep - stopping"); return end | 156 if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end |
157 for i,v in pairs(table) do | 157 for i,v in pairs(table) do |
158 if( type(v) == "string" ) then | 158 if( type(v) == "string" ) then |
159 bsk:Print(depth .. i .. " - " .. v) | 159 print(depth .. i .. " - " .. v) |
160 elseif( type(v) == "number" ) then | 160 elseif( type(v) == "number" ) then |
161 bsk:Print(depth .. i .. " - " .. tostring(v)) | 161 print(depth .. i .. " - " .. tostring(v)) |
162 elseif( type(v) == "table" ) then | 162 elseif( type(v) == "table" ) then |
163 bsk:Print(depth .. i .." - ") | 163 print(depth .. i .." - ") |
164 PrintTable(v,depth.." ") | 164 PrintTable(v,depth.." ") |
165 elseif( type(v) == "boolean" ) then | 165 elseif( type(v) == "boolean" ) then |
166 bsk:Print(depth .. i .. " - " .. tostring(v)) | 166 print(depth .. i .. " - " .. tostring(v)) |
167 elseif( type(v) == "function" ) then | 167 elseif( type(v) == "function" ) then |
168 bsk:Print(depth .. "function " .. i .. "()") | 168 print(depth .. "function " .. i .. "()") |
169 else | 169 else |
170 bsk:Print(depth .. i .. " - not sure how to print type: " .. type(v) ) | 170 print(depth .. i .. " - not sure how to print type: " .. type(v) ) |
171 end | 171 end |
172 end | 172 end |
173 end | 173 end |
174 | 174 |
175 function PrintRaidAndReserve() | 175 function PrintRaidAndReserve() |
176 bsk:Print("RaidNameP") | 176 print("RaidNameP") |
177 PrintTable(raidNameP) | 177 PrintTable(raidNameP) |
178 bsk:Print("RaidIdP") | 178 print("RaidIdP") |
179 PrintTable(raidIdP) | 179 PrintTable(raidIdP) |
180 bsk:Print("ReserveP") | 180 print("ReserveP") |
181 PrintTable(reserveIdP) | 181 PrintTable(reserveIdP) |
182 bsk:Print("personName2id") | 182 print("personName2id") |
183 PrintTable(personName2id) | 183 PrintTable(personName2id) |
184 end | 184 end |
185 --}}} | 185 --}}} |
186 | 186 |
187 function UpdatePersonsReverse() | 187 function UpdatePersonsReverse() |
190 personName2id[v.main] = i | 190 personName2id[v.main] = i |
191 end | 191 end |
192 end | 192 end |
193 end | 193 end |
194 | 194 |
195 -- Czohange processing {{{ | 195 -- Change processing {{{ |
196 function CreateWorkingStateFromChanges(changes) | 196 function CreateWorkingStateFromChanges(changes) |
197 local personsBase = db.profile.persons | 197 local personsBase = db.profile.persons |
198 local lists = db.profile.lists | 198 local lists = db.profile.lists |
199 | 199 |
200 -- copy the base to the working state | 200 -- copy the base to the working state |
259 elseif change.action == "RemovePersonFromList" then | 259 elseif change.action == "RemovePersonFromList" then |
260 DoRemovePersonFromList(change) | 260 DoRemovePersonFromList(change) |
261 elseif change.action == "SuicidePerson" then | 261 elseif change.action == "SuicidePerson" then |
262 DoSuicidePerson(change) | 262 DoSuicidePerson(change) |
263 else | 263 else |
264 bsk:Print("Unknown message encountered") | 264 print("Unknown message encountered") |
265 PrintTable(change) | 265 PrintTable(change) |
266 assert(false) | 266 assert(false) |
267 end | 267 end |
268 end | 268 end |
269 | 269 |
333 function AddPerson(name)--{{{ | 333 function AddPerson(name)--{{{ |
334 local persons = persons | 334 local persons = persons |
335 local guid = _G.UnitGUID(name) | 335 local guid = _G.UnitGUID(name) |
336 -- TODO: check guid to be sure it's a player | 336 -- TODO: check guid to be sure it's a player |
337 if not guid then | 337 if not guid then |
338 bsk:Print(sformat("Could not add player %s - they must be in range or group",name)) | 338 printf("Could not add player %s - they must be in range or group",name) |
339 return | 339 return |
340 end | 340 end |
341 local _,englishClass = _G.UnitClass(name) | 341 local _,englishClass = _G.UnitClass(name) |
342 --bsk:Print("Person " .. name .. " is class " .. englishClass) | 342 --print("Person " .. name .. " is class " .. englishClass) |
343 local id = string.sub(guid,6) -- skip at least 0x0580 ... | 343 local id = string.sub(guid,6) -- skip at least 0x0580 ... |
344 id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining | 344 id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining |
345 | 345 |
346 if persons[id] and persons[id] ~= name then | 346 if persons[id] and persons[id] ~= name then |
347 bsk:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name)) | 347 printf("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name) |
348 return | 348 return |
349 end | 349 end |
350 if persons[id] ~= nil then | 350 if persons[id] ~= nil then |
351 bsk:Print(sformat("%s is already in the persons list; disregarding", name)) | 351 printf("%s is already in the persons list; disregarding", name) |
352 return | 352 return |
353 end | 353 end |
354 local change = {action="AddPerson",arg={name=name,id=id,class=englishClass}} | 354 local change = {action="AddPerson",arg={name=name,id=id,class=englishClass}} |
355 if DoAddPerson(change) then | 355 if DoAddPerson(change) then |
356 CreateChange(change) | 356 CreateChange(change) |
357 end | 357 end |
358 end--}}} | 358 end--}}} |
359 function DoCreateList(change)--{{{ | 359 function DoCreateList(change)--{{{ |
360 --if GetListIndex(change.arg.name) then | 360 --if GetListIndex(change.arg.name) then |
361 -- bsk:Print(sformat("List %s already exists",v.name)) | 361 -- rintf(("List %s already exists",v.name) |
362 -- return false | 362 -- return false |
363 --end | 363 --end |
364 lists[change.arg.id]={name=change.arg.name,time=change.time} | 364 lists[change.arg.id]={name=change.arg.name,time=change.time} |
365 return true | 365 return true |
366 end--}}} | 366 end--}}} |
367 function CreateList(name)--{{{ | 367 function CreateList(name)--{{{ |
368 -- require admin | 368 -- require admin |
369 local change={action="CreateList",arg={name=name}} | 369 local change={action="CreateList",arg={name=name}} |
370 StartChange(change) | 370 StartChange(change) |
371 change.arg.id=change.time -- use the creation timestamp as the list's index. it's as unique as anything... | 371 change.arg.id=change.time -- use the creation timestamp as the list's index. it's as unique as anything... |
372 bsk:Print("Creating ... " .. name) | 372 print("Creating ... " .. name) |
373 if DoCreateList(change) then | 373 if DoCreateList(change) then |
374 CommitChange(change) | 374 CommitChange(change) |
375 end | 375 end |
376 end--}}} | 376 end--}}} |
377 function DoAddPersonToListEnd(change)--{{{ | 377 function DoAddPersonToListEnd(change)--{{{ |
393 function AddPersonToListEnd(name,listName)--{{{ | 393 function AddPersonToListEnd(name,listName)--{{{ |
394 -- require admin | 394 -- require admin |
395 local listIndex = GetListIndex(listName) | 395 local listIndex = GetListIndex(listName) |
396 local id = personName2id[name] | 396 local id = personName2id[name] |
397 if IdIsInList(id,lists[listIndex]) then | 397 if IdIsInList(id,lists[listIndex]) then |
398 bsk:Print(sformat("Person %s is already on the reqeuested list",name)) | 398 printf("Person %s is already on the reqeuested list",name) |
399 return false | 399 return false |
400 end | 400 end |
401 bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex)) | 401 printf("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex) |
402 local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}} | 402 local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}} |
403 StartChange(change) | 403 StartChange(change) |
404 if DoAddPersonToListEnd(change) then | 404 if DoAddPersonToListEnd(change) then |
405 CommitChange(change) | 405 CommitChange(change) |
406 end | 406 end |
417 end--}}} | 417 end--}}} |
418 function AddPersonToListRandom(name,listName)--{{{ | 418 function AddPersonToListRandom(name,listName)--{{{ |
419 -- require admin | 419 -- require admin |
420 local listIndex = GetListIndex(listName) | 420 local listIndex = GetListIndex(listName) |
421 if lists[listIndex].closedRandom then | 421 if lists[listIndex].closedRandom then |
422 bsk:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred") | 422 print("Cannot add person to list by random roll because an add-to-end operation has already occurred") |
423 return false | 423 return false |
424 end | 424 end |
425 local id = personName2id[name] | 425 local id = personName2id[name] |
426 if IdIsInList(id,lists[listIndex]) then | 426 if IdIsInList(id,lists[listIndex]) then |
427 bsk:Print(sformat("Person %s is already on the reqeuested list",name)) | 427 printf("Person %s is already on the reqeuested list",name) |
428 return false | 428 return false |
429 end | 429 end |
430 local roll = math.random() | 430 local roll = math.random() |
431 bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll)) | 431 printf("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll) |
432 local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} | 432 local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} |
433 StartChange(change) | 433 StartChange(change) |
434 if DoAddPersonToListRandom(change) then | 434 if DoAddPersonToListRandom(change) then |
435 CommitChange(change) | 435 CommitChange(change) |
436 end | 436 end |
443 return true | 443 return true |
444 end--}}} | 444 end--}}} |
445 function RemovePerson(name)--{{{ | 445 function RemovePerson(name)--{{{ |
446 local id = personName2id[name] | 446 local id = personName2id[name] |
447 if not id then | 447 if not id then |
448 bsk:Print(sformat("%s is not in the persons list, please check your spelling", name)) | 448 printf("%s is not in the persons list, please check your spelling", name) |
449 return false | 449 return false |
450 end | 450 end |
451 local listsTheyreOn = {} | 451 local listsTheyreOn = {} |
452 -- check if they're active on any loot list | 452 -- check if they're active on any loot list |
453 for i,v in pairs(lists) do | 453 for i,v in pairs(lists) do |
455 tinsert(listsTheyreOn,v.name) | 455 tinsert(listsTheyreOn,v.name) |
456 break | 456 break |
457 end | 457 end |
458 end | 458 end |
459 if getn(listsTheyreOn) > 0 then | 459 if getn(listsTheyreOn) > 0 then |
460 bsk:Print(sformat("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", "))) | 460 printf("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", ")) |
461 return false | 461 return false |
462 end | 462 end |
463 local change = {action="RemovePerson",arg={id=id}} | 463 local change = {action="RemovePerson",arg={id=id}} |
464 StartChange(change) | 464 StartChange(change) |
465 if DoRemovePerson(change) then | 465 if DoRemovePerson(change) then |
474 -- list and the working copy | 474 -- list and the working copy |
475 | 475 |
476 local replacement = shallowCopy(change.arg.affect) | 476 local replacement = shallowCopy(change.arg.affect) |
477 local temp = table.remove(replacement,1) -- pop | 477 local temp = table.remove(replacement,1) -- pop |
478 tinsert(replacement,temp) -- push_back | 478 tinsert(replacement,temp) -- push_back |
479 --bsk:Print(sformat("Before suicide of %s on list %s",slist[1],list.name)) | 479 --rintf(("Before suicide of %s on list %s",slist[1],list.name) |
480 --PrintTable(list) | 480 --PrintTable(list) |
481 for i = 1, #list do | 481 for i = 1, #list do |
482 if list[i].id == affected[1] then | 482 if list[i].id == affected[1] then |
483 table.remove(affected,1) | 483 table.remove(affected,1) |
484 list[i].id = replacement[1] | 484 list[i].id = replacement[1] |
553 --}}} | 553 --}}} |
554 -- Higher order actions (ie calls other standard actions){{{ | 554 -- Higher order actions (ie calls other standard actions){{{ |
555 | 555 |
556 function TrimLists(time) | 556 function TrimLists(time) |
557 if not CheckListCausality() then | 557 if not CheckListCausality() then |
558 bsk:Print("Unable to trim changelist due to violated causality") | 558 print("Unable to trim changelist due to violated causality") |
559 return false | 559 return false |
560 end | 560 end |
561 | 561 |
562 if type(time) ~= "number" then | 562 if type(time) ~= "number" then |
563 time = tonumber(time) | 563 time = tonumber(time) |
593 for id,_ in pairs(persons) do | 593 for id,_ in pairs(persons) do |
594 t[id] = true | 594 t[id] = true |
595 end | 595 end |
596 for name,_ in pairs(raidNameP) do | 596 for name,_ in pairs(raidNameP) do |
597 if personName2id[name] == nil then | 597 if personName2id[name] == nil then |
598 bsk:Print(sformat("Person %s is missing from the persons list - adding",name)) | 598 printf("Person %s is missing from the persons list - adding",name) |
599 AddPerson(name) | 599 AddPerson(name) |
600 end | 600 end |
601 end | 601 end |
602 -- TODO: batch into a single op - no need to spam 25 messages in a row | 602 -- TODO: batch into a single op - no need to spam 25 messages in a row |
603 end | 603 end |
642 --}}} | 642 --}}} |
643 -- "Soft" actions- ie things that cause nonpermanent state {{{ | 643 -- "Soft" actions- ie things that cause nonpermanent state {{{ |
644 | 644 |
645 -- reserves | 645 -- reserves |
646 function AddReserve(name) | 646 function AddReserve(name) |
647 bsk:Print("Reserving" .. name) | 647 print("Reserving" .. name) |
648 reserveIdP[personName2id[name]]=true | 648 reserveIdP[personName2id[name]]=true |
649 -- TODO: communicate to others. don't store this in any way. | 649 -- TODO: communicate to others. don't store this in any way. |
650 end | 650 end |
651 | 651 |
652 function RemoveReserve(name) | 652 function RemoveReserve(name) |
709 -- while undo is allowed *per-list*, certain events in the stream will | 709 -- while undo is allowed *per-list*, certain events in the stream will |
710 -- prevent proper undo, such as add/delete player or add/delete list | 710 -- prevent proper undo, such as add/delete player or add/delete list |
711 | 711 |
712 | 712 |
713 function GetSuicideList(id,list) | 713 function GetSuicideList(id,list) |
714 --bsk:Print("Calculating changeset for "..name.." from list -") | 714 --print("Calculating changeset for "..name.." from list -") |
715 --PrintTable(list) | 715 --PrintTable(list) |
716 local t = {} | 716 local t = {} |
717 local ret = {} | 717 local ret = {} |
718 local pushing = false | 718 local pushing = false |
719 for i = 1, #list do | 719 for i = 1, #list do |
722 end | 722 end |
723 if pushing and (raidIdP[list[i].id] or reserveIdP[list[i].id]) then | 723 if pushing and (raidIdP[list[i].id] or reserveIdP[list[i].id]) then |
724 tinsert(ret,list[i].id) | 724 tinsert(ret,list[i].id) |
725 end | 725 end |
726 end | 726 end |
727 --bsk:Print("GSL") | 727 --print("GSL") |
728 --PrintTable(ret) | 728 --PrintTable(ret) |
729 --bsk:Print("GSL") | 729 --print("GSL") |
730 return ret | 730 return ret |
731 end | 731 end |
732 | 732 |
733 function IdIsInList(id,listRef) | 733 function IdIsInList(id,listRef) |
734 for i = 1,#listRef do | 734 for i = 1,#listRef do |