-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.lua
1 lines (1 loc) · 6.97 KB
/
utils.lua
1
local b,c=...local d={}local _G=_G;local e,f=_G.pairs,_G.ipairs;local g,h=_G.table.insert,_G.table.remove;local i,j,k=_G.select,_G.type,_G.unpack;local l,m=_G.setmetatable,_G.getmetatable;function d.fillTable(n,o)for p,q in e(o)do if n[p]==nil then n[p]=q elseif j(q)=="table"then d.fillTable(q,o[p])end end end;function d.mixTable(n,o)for p,q in e(o)do if n[p]==nil then n[p]=q elseif j(q)=="table"then d.mixTable(q,o[p])else n[p]=q end end end;function d.deepCopy(r)local s={}local function t(r)if j(r)~="table"then return r elseif s[r]then return s[r]end;local u={}s[r]=u;for v,q in e(r)do u[t(v)]=t(q)end;return l(u,m(r))end;return t(r)end;function d.checkEntry(w,x)for p,q in f(w)do if q==x then return true end end;return false end;function d.tableLen(w)local y=0;for b,b in e(w)do y=y+1 end;return y end;function d.isEmpty(w)for b,b in e(w)do return false end;return true end;function string.trim(z)return z:gsub("^%s*(.-)%s*$","%1")end;function d.toggle(A,B)if not A then return elseif A:IsShown()then A:Hide()else A:Show()end;if B and j(B)=="function"then B()end end;function d.showHide(A,C,B)if not A then return elseif C and not A:IsShown()then A:Show()elseif not C and A:IsShown()then A:Hide()end;if B and j(B)=="function"then B()end end;function d.show(A,B)if A and not A:IsShown()then A:Show()if B and j(B)=="function"then B()end end end;function d.showIf(A,C,B)if A and not A:IsShown()and C then A:Show()if B and j(B)=="function"then B()end end end;function d.hide(A,B)if A and A:IsShown()then A:Hide()if B and j(B)=="function"then B()end end end;function d.hideIf(A,C,B)if A and A:IsShown()and C then A:Hide()if B and j(B)=="function"then B()end end end;function d.enableDisable(D,C)if not D then return elseif C and D:IsEnabled()==0 then D:Enable()elseif not C and D:IsEnabled()==1 then D:Disable()end end;function d.highlight(D,C)if not D then return elseif C then D:LockHighlight()else D:UnlockHighlight()end end;function d.setText(A,z)if not A then return end;A:SetText(z)end;function d.setTextIf(A,E,F,C)if not A then return elseif C then A:SetText(E)else A:SetText(F)end end;function d.setTexture(A,G,H,C)if not A then return elseif C then A:SetTexture(G)else A:SetTexture(H)end end;function d.setNormalTexture(A,G,H,C)if not A then return elseif C then A:SetNormalTexture(G)else A:SetNormalTexture(H)end end;function d.update(A,I,J,K)local w=I and A[I]or 0;w=w+K;if w>J then A[I]=0;return true end;A[I]=w;return false end;do local L=_G.GetTime;local M={}function d.schedule(N,O,...)local P={}P.time=L()+N;P.func=O;P.args={}for p=1,i("#",...)do P.args[p]=i(p,...)end;g(M,P)end;function d.reschedule(O,N)for p=1,#M do if M[p].func==O then M[p].time=M[p].time+N;break end end end;function d.unschedule(O)for p,q in e(M)do if O==q.func then h(M,p)break end end end;function d.run()local Q=L()for p=1,#M do local P=M[p]if P and j(P.func)=="function"and P.time<=Q then P.func(k(P.args,0))h(M,p)end end end end;do local R=_G.DEFAULT_CHAT_FRAME;local S=_G.SendChatMessage;local T=_G.table.concat;local U={}local function V(W,...)local X=1;if not U[X]then U[X]="|cff33ff99KTracker|r:"end;for p=1,i("#",...)do X=X+1;U[X]=tostring(i(p,...))end;W:AddMessage(T(U," ",1,X))end;function d.print(...)local W=...if j(W)=="table"and W.AddMessage then return V(W,i(1,...))else return V(R,...)end end;function d.printf(...)local W=...if j(W)=="table"and W.AddMessage then return V(W,format(i(1,...)))else return V(R,format(...))end end;function d.printSuccess(Y)Y="|cff95dd93"..tostring(Y).."|r"return d.print(Y)end;function d.printWarning(Y)Y="|cffff8a00"..tostring(Y).."|r"return d.print(Y)end;function d.printError(Y)Y="|cffff3c00"..tostring(Y).."|r"return d.print(Y)end;function c:Print(...)return d.print(...)end;function c:PrintSuccess(...)return d.printSuccess(...)end;function c:PrintWarning(...)return d.printWarning(...)end;function c:PrintError(...)return d.printError(...)end end;do local Z=_G.HIGHLIGHT_FONT_COLOR;local _=_G.GameTooltip_SetDefaultAnchor;local function a0(W)if not W.tooltip_anchor then _(KTrackerTooltip,W)else KTrackerTooltip:SetOwner(W,W.tooltip_anchor)end;KTrackerTooltip:ClearLines()if W.tooltip_title then KTrackerTooltip:SetText(W.tooltip_title)end;if W.tooltip_text then if j(W.tooltip_text)=="string"then KTrackerTooltip:AddLine(W.tooltip_text,Z.r,Z.g,Z.b,true)elseif j(W.tooltip_text)=="table"then for b,a1 in f(W.tooltip_text)do KTrackerTooltip:AddLine(a1,Z.r,Z.g,Z.b,true)end end end;if W.tooltip_item then KTrackerTooltip:SetHyperlink(W.tooltip_item)end;KTrackerTooltip:Show()end;local function a2()KTrackerTooltip:Hide()end;function d.setTooltip(W,Y,a3,a4)if W then W.tooltip_text=Y and Y or W.tooltip_text;W.tooltip_anchor=a3 and a3 or W.tooltip_anchor;W.tooltip_title=a4 and a4 or W.tooltip_title;if W.tooltip_title or W.tooltip_text or W.tooltip_item then W:SetScript("OnEnter",a0)W:SetScript("OnLeave",a2)end end end;function d.unsetTooltip(W)if W then W:SetScript("OnEnter",nil)W:SetScript("OnLeave",nil)end end end;do local a5,a6=_G.pcall,_G.error;local a7={}function d.registerCallback(x,O)if x and j(O)=="function"then a7[x]=a7[x]or{}g(a7[x],O)return#a7 end;a6("Usage: mod.registerCallback(action,callback)",2)end;function d.triggerEvent(x,...)if a7[x]then for p,q in f(a7[x])do local a8,a9=a5(q,a,...)if not a8 then d.print(format("Error while executing callback %s for event %s: %s",tostring(q),tostring(a),a9))end end end end end;do local aa=_G.GetNumPartyMembers;local ab=_G.GetNumRaidMembers;local ac=_G.GetRaidRosterInfo;local ad,ae=_G.UnitName,_G.UnitGUID;function d.isInParty()return aa()>0 end;function d.isInRaid()return ab()>0 end;function d.getPlayerUnitId(af)af=af or ad("player")local ag="none"local ah=d.isInRaid()and"raid"or"party"local ai=math.max(ab(),aa())for p=0,ai do local aj=p==0 and"player"or ah..p;if af==ad(aj)then ag=aj;break end end;return ag end end;do local ak=CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS;function d.RGB2HEX(al,am,D)return format("%02x%02x%02x",al*255,am*255,D*255)end;function d.classColor(I)I=I=="DEATH KNIGHT"and"DEATHKNIGHT"or I;if not ak[I]then return 1,1,1 end;return ak[I].r,ak[I].g,ak[I].b end;function d.classColorHex(I)local al,am,D=d.classColor(I)return d.RGB2HEX(al,am,D)end end;do local an=_G.IsInInstance;local ao=_G.GetRealNumRaidMembers;local ap=_G.GetRealNumPartyMembers;local aq=_G.SendAddonMessage;if ChatThrottleLib and ChatThrottleLib.SendAddonMessage then aq=function(...)ChatThrottleLib:SendAddonMessage("NORMAL",...)end end;function d.sync(ar,as,at,au)if not at then local av=i(2,an())if av=="pvp"or av=="arena"then at="BATTLEGROUND"elseif ao()>0 then at="RAID"elseif ap()>0 then at="PARTY"end end;if at then aq(ar,as,at,au)end end end;do local aw={}do for ax=48,57 do table.insert(aw,string.char(ax))end;for ax=65,90 do table.insert(aw,string.char(ax))end;for ax=97,122 do table.insert(aw,string.char(ax))end end;function d.randomString(y)if not y or y<=0 then return''end;return d.randomString(y-1)..aw[math.random(1,#aw)]end end;function d.newClass(ay,az)local aA=CreateFrame(ay)aA.mt={__index=aA}if az then aA=l(aA,{__index=az})aA.super=az end;aA.Bind=function(self,aB)return l(aB,self.mt)end;return aA end;c.utils=d