Nenue@6: --- ${PACKAGE_NAME} Nenue@6: -- @file-author@ Nenue@6: -- @project-revision@ @project-hash@ Nenue@6: -- @file-revision@ @file-hash@ Nenue@6: -- Created: 12/28/2015 6:40 AM Nenue@6: --- Core load sequence goes here. Nenue@6: --@debug@ Nenue@6: local ADDON, TurokEnv = ... Nenue@6: local _G = _G Nenue@6: --@end-debug@ Nenue@6: --GLOBALS: Turok, LibStub, GetAddOnMetadata Nenue@6: local setmetatable, rawset, rawget, pairs, type, unpack, tostring, tinsert = setmetatable, rawset, rawget, pairs, type, unpack, tostring, table.insert Nenue@6: Turok = LibStub("AceAddon-3.0"):NewAddon('Turok', 'AceEvent-3.0', 'AceTimer-3.0', 'AceConsole-3.0') Nenue@6: Turok:SetDefaultModuleState(true) Nenue@6: TurokEnv.Addon = Turok Nenue@6: TurokEnv.LSM = LibStub("LibSharedMedia-3.0") Nenue@6: TurokEnv.LGIST = LibStub("LibGroupInSpecT-1.1") Nenue@6: local T = Turok Nenue@6: --@debug@ Nenue@6: local print = function(...) Nenue@6: if _G.Devian and _G.DevianDB.workspace ~= 1 then Nenue@6: _G.print('DB', ...) Nenue@6: end Nenue@6: end Nenue@6: local cTypes = { ['function'] = 'FF9922', ['table'] = '00FFAA', ['number'] = '77FF00', ['string'] = '00AAFF', ['hl'] = 'FF0088', ['field'] = '00FFFF', Nenue@6: ['boolean'] = 'CC88FF', ['false'] = 'FF7700', ['true'] = '44FF66', ['nil'] = 'FFFF00',} Nenue@6: Nenue@6: local Debuggers = { Nenue@6: cType = function(s) return '|cFF' .. tostring(cTypes[type(s)]) .. tostring(s) .. '|r' end, Nenue@6: cText = function(s) return '|cFF'..cTypes.string..tostring(s)..'|r' end, Nenue@6: cNum = function(n) return '|cFF'..cTypes.number .. tostring(n) .. '|r' end, Nenue@6: cWord = function(w) return '|cFF'..cTypes.table .. tostring(w) .. '|r' end, Nenue@6: cKey = function(k) return '|cFF'..cTypes.field .. tostring(k) .. '|r' end, Nenue@6: cPink = function(s) return '|cFF'..cTypes.hl .. tostring(s) .. '|r' end, Nenue@6: cBool = function(s) return '|cFF'..cTypes[tostring((not not s))] .. tostring(s) .. '|r' end, Nenue@6: } Nenue@6: for fname, func in pairs(Debuggers) do Nenue@6: _G[fname] = func Nenue@6: end Nenue@6: local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool Nenue@6: --@end-debug@ Nenue@6: Nenue@6: T.db = {} Nenue@6: T.versionString = GetAddOnMetadata("Turok", "Version") Nenue@6: Nenue@6: function T:OnModuleCreated(mod) Nenue@6: if mod.events then Nenue@6: print('Module', unpack(mod.events)) Nenue@6: end Nenue@6: end Nenue@6: --- RegisterEvent embedded to module tables Nenue@6: function T:RegisterCallback(event, func, ...) Nenue@6: if not T.dispatchQueue[event] then Nenue@6: T.dispatchQueue[event] = {} Nenue@6: end Nenue@6: Nenue@6: if not T.dispatchQueue[event][T.ID] then Nenue@6: T.dispatchQueue[event][T.ID] = T:GetName() Nenue@6: end Nenue@6: Nenue@6: if (type(func) == 'function') then Nenue@6: if type(T[event]) == 'function' then Nenue@6: local oldfunc = T[event] Nenue@6: T[event] = function(...) Nenue@6: oldfunc(...) Nenue@6: return func(...) Nenue@6: end Nenue@6: else Nenue@6: T[event] = func Nenue@6: end Nenue@6: end Nenue@6: --@debug@ Nenue@6: print(cText('Adding listener for'), cKey(self:GetName()), cText('on'), cKey(event))--@end-debug@ Nenue@6: end Nenue@6: Nenue@6: --- Default settings base Nenue@6: T.defaults = { Nenue@6: char = {}, Nenue@6: Nenue@6: lefttext = { Nenue@6: parent = 2, -- in an overlay frame Nenue@6: anchor = 'LEFT', Nenue@6: anchorTo = 'LEFT', Nenue@6: size = 18, Nenue@6: x = 5, y = 0, Nenue@6: justifyH = 'LEFT', Nenue@6: justifyV = 'MIDDLE', Nenue@6: }, Nenue@6: Nenue@6: righttext = { Nenue@6: parent = 2, -- in an overlay frame Nenue@6: anchor = 'RIGHT', Nenue@6: anchorTo = 'RIGHT', Nenue@6: x = -5, Nenue@6: y = 0, Nenue@6: size = 18, Nenue@6: justifyH = 'RIGHT', Nenue@6: justifyV = 'MIDDLE', Nenue@6: }, Nenue@6: Nenue@6: alpha = 1, Nenue@6: alpha_ooc = 1, Nenue@6: alpha_fade_in = 0.2, Nenue@6: alpha_fade_out = 0.2, Nenue@6: border_color = {0,0,0,1}, Nenue@6: Nenue@6: background_color = {0,.0,0,1}, Nenue@6: background_blend = 'BLEND', Nenue@6: Nenue@6: foreground_texture = [[Interface\Addons\Turok\Media\statusbar\Minimalist.tga]], Nenue@6: foreground_color = {0,.475,.95,1}, Nenue@6: foreground_blend = 'BLEND', Nenue@6: Nenue@6: foreground_inset = 0, Nenue@6: padding = 2, Nenue@6: spacing = 0, Nenue@6: fill_direction = 'RIGHT', Nenue@6: Nenue@6: anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER', Nenue@6: x = 0, y = 0, Nenue@6: inset = -3, Nenue@6: width = 250, Nenue@6: height = 100, Nenue@6: strata = 'LOW', Nenue@6: font = "Interface\\Addons\\Turok\\Media\\font\\ArchivoNarrow-Regular.ttf", Nenue@6: size = 14, Nenue@6: text_color = {1, 1, 1, 1}, Nenue@6: justifyH = 'LEFT', Nenue@6: outline = 'OUTLINE', Nenue@6: combatFade = true, Nenue@6: Nenue@6: battle_noise_start = [[Interface\Addons\Turok\Media\sound\Low_Beep-Public_D-136_hifi.mp3]], Nenue@6: battle_noise_end = [[Interface\Addons\Turok\Media\sound\Electro_-S_Bainbr-7955_hifi.mp3]], Nenue@6: } Nenue@6: Nenue@6: Nenue@6: T.events = { Nenue@6: 'PLAY_MOVIE', Nenue@6: 'PLAYER_TARGET_CHANGED', Nenue@6: 'PLAYER_FOCUS_CHANGED', Nenue@6: 'PLAYER_EQUIPMENT_CHANGED', Nenue@6: 'PLAYER_REGEN_DISABLED', Nenue@6: 'PLAYER_REGEN_ENABLED', Nenue@6: 'SPELL_UDPATE_COOLDOWN', Nenue@6: 'SPELL_UPDATE_USABLE', Nenue@6: 'UNIT_AURA', Nenue@6: 'UNIT_PET', Nenue@6: 'UNIT_POWER_FREQUENT', Nenue@6: 'UNIT_SPELL_HASTE', Nenue@6: 'UNIT_SPELLCAST_SENT', Nenue@6: 'UNIT_SPELLCAST_START', Nenue@6: 'UNIT_SPELLCAST_DELAYED', Nenue@6: 'UNIT_SPELLCAST_STOP', Nenue@6: 'UNIT_SPELLCAST_CHANNEL_START', Nenue@6: 'UNIT_SPELLCAST_CHANNEL_UPDATE', Nenue@6: 'UNIT_SPELLCAST_CHANNEL_STOP', Nenue@6: 'UNIT_SPELLCAST_FAILED', Nenue@6: 'UNIT_SPELLCAST_INTERRUPTED', Nenue@6: 'UNIT_SPELLCAST_INTERRUPTIBLE', Nenue@6: 'UNIT_SPELLCAST_SUCCEEDED', Nenue@6: 'UNIT_SPELLCAST_UNINTERRUPTIBLE', Nenue@6: } Nenue@6: T.previousSpec = {} Nenue@6: T.talents = { {}, {}} Nenue@6: T.changedTalents = {{}, {} } Nenue@6: T.talentInfo = {} Nenue@6: T.auras = {} Nenue@6: T.spells = {} Nenue@6: T.spellevent = {} Nenue@6: T.channeling = {} Nenue@6: T.casting = {} Nenue@6: T.sent = {} Nenue@6: T.prototype = {} Nenue@6: T.spellBook = {} Nenue@6: T.equipped = {} Nenue@6: Nenue@6: --- player-restricted unit info and text representations Nenue@6: T.player = {} Nenue@6: T.playertext = {} Nenue@6: T.pet = {} Nenue@6: Nenue@6: --- holds non-restricted unit information Nenue@6: T.unit = { Nenue@6: player = {}, Nenue@6: target = {}, Nenue@6: focus = {}, Nenue@6: pet = {}, Nenue@6: } Nenue@6: Nenue@6: -- index of frames with conditional visual properties Nenue@6: T.control_regions = {} Nenue@6: Nenue@6: -- index of frames generated by the lua Nenue@6: T.frames = {} Nenue@6: Nenue@6: -- units Nenue@6: T.units = {} Nenue@6: T.unitsBySlot = {} Nenue@6: setmetatable(T.unitsBySlot, {__mode="v"}) Nenue@6: Nenue@6: Nenue@6: Nenue@6: T.TrueVal = function (self,k) Nenue@6: return rawget(self,k) Nenue@6: end Nenue@6: --- Sets an index hierarchy for db vars and propagates config dialog info Nenue@6: T.LinkTable = function (over, under, pname, cname) Nenue@6: local mt = { Nenue@6: __index = function(t,k) Nenue@6: if type(over[k]) ~= nil then Nenue@6: --t[k] = over[k] Nenue@6: --@debug@ Nenue@6: --print('up-referencing '.. STACK_COLOR2 .. pname ..'|r.'.. STACK_COLOR3.. tostring(k)..'|r -> '.. STACK_COLOR3.. pname ..'.' .. cname .. '|r.'..STACK_COLORN.. tostring(k) ..'|r', over[k])--@end-debug@ Nenue@6: end Nenue@6: return over[k] Nenue@6: end, Nenue@6: __newindex = function (t, k, v) Nenue@6: rawset(t,k,v) Nenue@6: if type(v) == 'table' then Nenue@6: --@debug@ Nenue@6: --print('parenting '.. STACK_COLOR2.. pname ..'|r to created table '.. STACK_COLOR3.. cname ..'|r')--@end-debug@ Nenue@6: T.LinkTable(under, v, pname, k) Nenue@6: end Nenue@6: end Nenue@6: } Nenue@6: --under.TrueVal = T.TrueVal Nenue@6: setmetatable(under, mt) Nenue@6: for k, v in pairs(under) do Nenue@6: if type(v) == 'table' then Nenue@6: --@debug@ Nenue@6: --print('linking '..STACK_COLOR1.. pname ..'|r to '..STACK_COLOR2.. cname ..'|r')--@end-debug@ Nenue@6: T.LinkTable(under, v, pname ..'.'.. cname, k) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@6: --- Merges values of table B into table A, and copies over nested values of tables matching the keywords list Nenue@6: local masked = {name = true, virtual = true} Nenue@6: T.Config_Push = function(cvars, push , root, rkey) Nenue@6: local results = {} Nenue@6: root = root or cvars Nenue@6: for k, v in pairs(push) do Nenue@6: if not masked[k] then Nenue@6: if type(v) == 'table' and v ~= root then Nenue@6: cvars[k] = {} Nenue@6: T.Config_Push(cvars[k], v, root) Nenue@6: else Nenue@6: print(' |cFFFF0088B|r ', tostring(rkey)..'.'..cKey(k)) Nenue@6: cvars[k] = v Nenue@6: tinsert(results, ' |cFFFF0088B|r '.. tostring(rkey)..'.'..cKey(k)) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: return cvars, results Nenue@6: end Nenue@6: T.Config_Merge = function(cvars, merge, root, rkey) Nenue@6: local diff = {} Nenue@6: root = root or cvars Nenue@6: rkey = rkey or '0' Nenue@6: for k, v in pairs(merge) do Nenue@6: if masked[k] or cvars[k] then Nenue@6: tinsert(diff, ' |cFF00FF00A|r '.. tostring(rkey)..'.'..cWord(k)) Nenue@6: print(' |cFF00FF00A|r ', tostring(rkey)..'.'..cText(k), '=', cvars[k]) Nenue@6: --cvars[k] = cvars[k] Nenue@6: else Nenue@6: if type(v) == 'table' then Nenue@6: if type(cvars[k]) == 'nil' then Nenue@6: cvars[k] = {} Nenue@6: end Nenue@6: if type(cvars[k]) == 'table' then Nenue@6: print(' |cFFFFFF00A+B|r '.. tostring(rkey)..'.'..cWord(k)) Nenue@6: cvars[k] = T.Config_Merge(cvars[k], v, root, tostring(rkey)..'.'..tostring(k)) Nenue@6: end Nenue@6: elseif cvars[k] == nil then Nenue@6: tinsert(diff, ' |cFFFF0088B|r '.. tostring(rkey)..'.'..cKey(k)) Nenue@6: print(' |cFFFF0088B|r ', tostring(rkey)..'.'..cKey(k)) Nenue@6: cvars[k] = v Nenue@6: else Nenue@6: tinsert(diff, ' |cFF00FF00A|r '.. tostring(rkey)..'.'..cWord(k)) Nenue@6: print(' |cFF00FF00A|r ', tostring(rkey)..'.'..cWord(k)) Nenue@6: --cvars[k] = cvars[k] Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: return cvars, diff Nenue@6: end