Mercurial > wow > turok
comparison Turok/Modules/Timer/Timer.lua @ 9:9400a0ff8540
Ugh
Timer:
- container update directionality
- talent update iterates over a non-volatile table to carry out updates
- index management steps organized
- talentRow status implemented, returns the spell associated with the talent chosen from that row
CombatLog:
- sort out font controls and unbork arguments
| author | Nenue |
|---|---|
| date | Sun, 21 Feb 2016 13:08:30 -0500 |
| parents | a9b8b0866ece |
| children |
comparison
equal
deleted
inserted
replaced
| 8:7790dff0fe13 | 9:9400a0ff8540 |
|---|---|
| 3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 --- Defines common elements for the various timer HUDs | 5 --- Defines common elements for the various timer HUDs |
| 6 local ADDON, _A = ... | 6 local ADDON, _A = ... |
| 7 local _G, CreateFrame, tconcat, GetInventoryItemsForSlot, GetInventoryItemID = _G, CreateFrame, table.concat, GetInventoryItemsForSlot, GetInventoryItemID | 7 local _G, CreateFrame, tconcat, GetInventoryItemsForSlot, GetInventoryItemID = _G, CreateFrame, table.concat, GetInventoryItemsForSlot, GetInventoryItemID |
| 8 local T, F, tostring, type, max, tinsert, unpack, UIParent, loadstring = _A.Addon, _A.LibFog, tostring, type, max, table.insert, unpack, _G.UIParent, loadstring | 8 local T, F, tostring, type, max, tinsert, unpack, UIParent, loadstring, rawset = _A.Addon, _A.LibFog, tostring, type, max, table.insert, unpack, _G.UIParent, loadstring, rawset |
| 9 local mod = T.modules.TimerControl | 9 local mod = T.modules.TimerControl |
| 10 local P = mod.prototype | 10 local P = mod.prototype |
| 11 local db | 11 local db |
| 12 | 12 |
| 13 local pairs, ipairs, gsub, sub, setmetatable = pairs, ipairs, string.gsub, string.sub, setmetatable | 13 local pairs, ipairs, gsub, sub, setmetatable, wipe = pairs, ipairs, string.gsub, string.sub, setmetatable, wipe |
| 14 local INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 = | 14 local INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 = |
| 15 INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 | 15 INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 |
| 16 --@debug@ | 16 --@debug@ |
| 17 local DEBUG = true | 17 local DEBUG = true |
| 18 --@end-debug@ | 18 --@end-debug@ |
| 21 if not DEBUG then return end | 21 if not DEBUG then return end |
| 22 if _G.Devian and _G.DevianDB.workspace ~= 1 then | 22 if _G.Devian and _G.DevianDB.workspace ~= 1 then |
| 23 _G.print('Timer', ...) | 23 _G.print('Timer', ...) |
| 24 end | 24 end |
| 25 end | 25 end |
| 26 local teprint = function(...) | |
| 27 if not DEBUG then return end | |
| 28 if _G.Devian and _G.DevianDB.workspace ~= 1 then | |
| 29 _G.print('TimerEvent',...) | |
| 30 end | |
| 31 end | |
| 32 local tfprint = function(...) | |
| 33 if not DEBUG then return end | |
| 34 if _G.Devian and _G.DevianDB.workspace ~= 1 then | |
| 35 _G.print('TimerFocus',...) | |
| 36 end | |
| 37 end | |
| 26 | 38 |
| 27 local Timer_GetPrintHandler = function(self) | 39 local Timer_GetPrintHandler = function(self) |
| 28 if self.trace then | 40 if self.trace then |
| 29 return function(...) | 41 return function(...) |
| 30 print(...) | 42 print(...) |
| 31 _G.print('TimerFocus', ...) | 43 tfprint(...) |
| 32 end else | 44 end else |
| 33 return print | 45 return print |
| 34 end | 46 end |
| 35 end | 47 end |
| 36 local pb_suppressed = {} | 48 local pb_suppressed = {} |
| 65 | 77 |
| 66 local mt_single = { | 78 local mt_single = { |
| 67 __mode = "v", | 79 __mode = "v", |
| 68 __newindex = function(t,k,v) | 80 __newindex = function(t,k,v) |
| 69 rawset(t,k,v) | 81 rawset(t,k,v) |
| 70 _G.print('DB', 'TCMeta: adding leaf', k, '=', v) | 82 --_G.print('DB', 'TCMeta: adding leaf', k, '=', v) |
| 71 end} | 83 end} |
| 72 local mt_double = { | 84 local mt_double = { |
| 73 __index = function(t,k) | 85 __index = function(t,k) |
| 74 t[k] = setmetatable({}, mt_single) | 86 t[k] = setmetatable({}, mt_single) |
| 75 _G.print('DB', 'TCMeta: add layer', k, '=', t[k]) | 87 --_G.print('DB', 'TCMeta: add layer', k, '=', t[k]) |
| 76 return t[k] | 88 return t[k] |
| 77 end, | 89 end, |
| 78 __newindex = function(t,k,v) | 90 __newindex = function(t,k,v) |
| 79 rawset(t,k,v) | 91 rawset(t,k,v) |
| 80 _G.print('DB', 'TCMeta: adding to top layer', k, '=', v) | 92 --_G.print('DB', 'TCMeta: adding to top layer', k, '=', v) |
| 81 end | 93 end |
| 82 } | 94 } |
| 83 local mt_error = { | 95 local mt_error = { |
| 84 __call =function (t, txt) | 96 __call =function (t, txt) |
| 85 t.disable = true | 97 t.disable = true |
| 326 | 338 |
| 327 return mod.timers[id], newFrame | 339 return mod.timers[id], newFrame |
| 328 end | 340 end |
| 329 | 341 |
| 330 function mod.InitTimers() | 342 function mod.InitTimers() |
| 331 local print = function(...) _G.print('TimerEvent', ...) end | 343 teprint('INIT TIMERS ====================') |
| 332 print('INIT TIMERS ====================') | |
| 333 for id, spirit in pairs(mod.timers) do | 344 for id, spirit in pairs(mod.timers) do |
| 334 if spirit.disable then | 345 if spirit.disable then |
| 335 print(id, 'disabled:', tconcat(spirit.debug_info or {}, ', ')) | 346 teprint(id, 'disabled:', tconcat(spirit.debug_info or {}, ', ')) |
| 336 else | 347 else |
| 337 | 348 |
| 338 print(cText('init'), cNum(id), cWord(spirit.name)) | 349 teprint(cText('init'), cNum(id), cWord(spirit.name)) |
| 339 --- Throw a dry event to initialize values | 350 --- Throw a dry event to initialize values |
| 340 print(cText(' *'), cWord('prototype.'..cKey(spirit.dvars.type)..'.'..cWord('Load'))) | 351 teprint(cText(' *'), cWord('prototype.'..cKey(spirit.dvars.type)..'.'..cWord('Load'))) |
| 341 P.trigger[spirit.dvars.type].Event(spirit) | 352 P.trigger[spirit.dvars.type].Event(spirit) |
| 342 | 353 |
| 343 --- Set loose | 354 --- Set loose |
| 344 print(cText(' *'), cWord('prototype')..'.'..cKey('events')..'.'..cWord('Load')) | 355 teprint(cText(' *'), cWord('prototype')..'.'..cKey('events')..'.'..cWord('Load')) |
| 345 mod.UpdateEvents(spirit, P.trigger[spirit.dvars.type].events) | 356 mod.UpdateEvents(spirit, P.trigger[spirit.dvars.type].events) |
| 346 end | 357 end |
| 347 end | 358 end |
| 348 print('INIT DONE =========================') | 359 teprint('INIT DONE =========================') |
| 349 end | 360 end |
| 350 | 361 |
| 351 function mod:DisableTimer(name, timer) | 362 function mod:DisableTimer(name, timer) |
| 352 local timer_frame = mod.db.timers[name] | 363 local timer_frame = mod.db.timers[name] |
| 353 if timer_frame and not timer_frame.disable then | 364 if timer_frame and not timer_frame.disable then |
| 385 end | 396 end |
| 386 | 397 |
| 387 local match_sub = { | 398 local match_sub = { |
| 388 {'%%c', "' .. tostring(t.caster).. '"}, | 399 {'%%c', "' .. tostring(t.caster).. '"}, |
| 389 {'%%h', "' .. tostring((t.valueFull >= 60) and (math.floor(t.valueFull/60)) or t.value) .. '"}, | 400 {'%%h', "' .. tostring((t.valueFull >= 60) and (math.floor(t.valueFull/60)) or t.value) .. '"}, |
| 390 {'%%i', "' .. tostring((t.valueFull >= 60) and (t.value % 60) or ((t.valueFull < 6) and math.floor((t.ValueFull * 100) % 100) or '')) .. '"}, | 401 {'%%i', "' .. tostring((t.valueFull >= 60) and (math.floor(t.valueFull/60) .. ':' .. ((t.value %% 60) < 10 and '0' or '').. (t.value %% 60)) or ((t.valueFull < 6) and (t.value .. '.' .. math.floor((t.valueFull * 10) %% 10)) or t.value)) .. '"}, |
| 391 {'%%n', "' .. tostring(t.spellName) .. '"}, | 402 {'%%n', "' .. tostring(t.spellName) .. '"}, |
| 392 {'%%p', "' .. tostring(t.value) .. '"}, | 403 {'%%p', "' .. tostring(t.value) .. '"}, |
| 393 {'%%d', "' .. tostring(t.chargeDuration or t.duration) .. '"}, | 404 {'%%d', "' .. tostring(t.chargeDuration or t.duration) .. '"}, |
| 394 {'%%%.p', "' .. string.sub(tostring((t.valueFull %% 1) * 100),0,1) .. '"}, | 405 {'%%%.p', "' .. string.sub(tostring((t.valueFull %% 1) * 100),0,1) .. '"}, |
| 395 {"%%s", "' .. (t.stacks or t.charges or '') .. '"}, | 406 {"%%s", "' .. (t.stacks or t.charges or '') .. '"}, |
| 514 v:Event(nil, 'target') | 525 v:Event(nil, 'target') |
| 515 end | 526 end |
| 516 end | 527 end |
| 517 | 528 |
| 518 --- Same thing but for talent/spec-driven | 529 --- Same thing but for talent/spec-driven |
| 530 local update_queue = {} | |
| 531 function mod.ResetTimers(heading) | |
| 532 print(cText('*** Flushing update queue for'), cWord(heading)) | |
| 533 for id, frame in pairs(update_queue) do | |
| 534 print(' ', cNum(id), cKey(frame.timerName)) | |
| 535 frame.disable = nil | |
| 536 wipe(frame.debug_info) | |
| 537 local res, msg = mod:EnableTimer(id, frame.dvars) | |
| 538 end | |
| 539 wipe(update_queue) | |
| 540 end | |
| 541 | |
| 519 function mod:PLAYER_TALENT_UPDATE(e, unit) | 542 function mod:PLAYER_TALENT_UPDATE(e, unit) |
| 520 print('') | 543 print('') |
| 521 print('') | 544 print('') |
| 522 print(cText(e), T.specPage, T.specName) | 545 print(cText(e), T.specPage, T.specName) |
| 523 | 546 |
| 524 local update_queue = {} | |
| 525 for _, k in ipairs({'talentID', 'talentRow', 'specPage'}) do | 547 for _, k in ipairs({'talentID', 'talentRow', 'specPage'}) do |
| 526 for value, frameSet in pairs(mod.frames.talentID) do | 548 for value, frameSet in pairs(mod.frames.talentID) do |
| 527 for id, frame in ipairs(frameSet) do | 549 for id, frame in ipairs(frameSet) do |
| 528 print(frame.timerID, frame.timerName) | 550 print(frame.timerID, frame.timerName) |
| 529 update_queue[frame.timerID] = frame | 551 update_queue[frame.timerID] = frame |
| 530 end | 552 end |
| 531 end | 553 end |
| 532 end | 554 end |
| 533 | 555 mod.resetTimers('Talent') |
| 534 for id, frame in pairs(update_queue) do | |
| 535 print('Refreshing spec-related frames', id, frame.timerName) | |
| 536 frame.disable = nil | |
| 537 table.wipe(frame.debug_info) | |
| 538 local res, msg = mod:EnableTimer(id, frame.dvars) | |
| 539 end | |
| 540 | |
| 541 end | 556 end |
| 542 | 557 |
| 543 function mod:PLAYER_EQUIPMENT_CHANGED(e, slot, hasItem) | 558 function mod:PLAYER_EQUIPMENT_CHANGED(e, slot, hasItem) |
| 544 print(e, slot, hasItem) | 559 print(e, slot, hasItem) |
| 545 local itemCheckList | 560 if mod.frames.inventoryID and mod.frames.inventoryID[slot] then |
| 546 if mod.frames.inventoryID and mod.frames.inventoryID[slot] then | 561 print(' Inventory slot:', cNum(slot)) |
| 547 print(' Inventory Frames:') | 562 for i, slotFrame in ipairs(mod.frames.inventoryID[slot]) do |
| 548 itemCheckList = GetInventoryItemsForSlot(slot, {}, false) | 563 print(' ', cNum(i), cText(slotFrame.timerName)) |
| 549 for id, slotFrame in pairs(mod.frames.inventoryID[slot]) do | 564 update_queue[slotFrame.timerID] = slotFrame |
| 550 print(' * Updating', cNum(id), cWord(slotFrame.timerName)) | 565 if mod.frames.itemID then |
| 551 local res, msg = mod:EnableTimer(slotFrame.timerID, slotFrame.dvars) | 566 local itemsForSlot = GetInventoryItemsForSlot(slot, {}, false) |
| 552 print(' ', cBool(res), cText(msg)) | 567 for _, itemID in pairs(itemsForSlot) do |
| 553 end | 568 if mod.frames.itemID[itemID] then |
| 554 end | 569 print(' Frames for equippable item:', cNum(itemID)) |
| 555 if itemCheckList then | 570 for j, itemFrame in ipairs(mod.frames.itemID[itemID]) do |
| 556 print(unpack(itemCheckList)) | 571 print(' ', cNum(j), cText(itemFrame.timerName)) |
| 557 end | 572 update_queue[itemFrame.timerID] = itemFrame |
| 558 local itemID = GetInventoryItemID('player', slot) | 573 end |
| 559 if itemID and mod.frames.itemID[itemID] then | 574 end |
| 560 print(' Item ID Frames:') | 575 end |
| 561 for id, itemFrame in pairs(mod.frames.itemID[itemID]) do | 576 end |
| 562 print(' * Updating', cNum(id), cWord(itemFrame.timerName)) | 577 end |
| 563 | 578 end |
| 564 local res, msg = mod:EnableTimer(itemFrame.timerID, itemFrame.dvars) | 579 mod.ResetTimers('Equipment') |
| 565 print(' ', cBool(res), cText(msg)) | |
| 566 end | |
| 567 end | |
| 568 end | 580 end |
| 569 function mod:PET_BATTLE_OPENING_START () | 581 function mod:PET_BATTLE_OPENING_START () |
| 570 for i, v in pairs(mod.timers) do | 582 for i, v in pairs(mod.timers) do |
| 571 if not v.disable then | 583 if not v.disable then |
| 572 print('suppressing', v:GetName()) | 584 print('suppressing', v:GetName()) |
