-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhelper.lua
145 lines (129 loc) · 3.43 KB
/
helper.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---@type string
local _addonName = select(1, ...);
---@type AddonEnv
local _addon = select(2, ...);
--- Helper to remove a single table entry
---@param ttable table @The table to remove from
---@param entry any @The entry (value) to remove
function _addon:RemoveTableEntry(ttable, entry)
for k,v in ipairs(ttable) do
if v == entry then
table.remove(ttable, k);
return;
end
end
end
--- Print msg to chat, replacing default color
---@param msg string @The message to print
---@param defColor string @The color to use as default given as color esc sequence
local function PrintToChat(msg, defColor)
msg = msg:gsub("|r", defColor);
print(defColor .. _addonName .. ": " .. msg);
end
local SHAPESHIFTS = {
[768] = "cat",
[5487] = "bear",
[9634] = "bear",
[1066] = "aquatic",
[783] = "travel",
[24858] = "moonkin",
[2457] = "battle",
[71] = "defensive",
[2458] = "berserker"
}
--- Return a string naming the shapeshift currently in, nil if no shapeshift
---@return string
function _addon:GetShapeshiftName()
local index = GetShapeshiftForm();
if index > 0 then
local _, _, _, spellId = GetShapeshiftFormInfo(index);
if SHAPESHIFTS[spellId] then
return SHAPESHIFTS[spellId];
end
end
end
--- Print success message (green)
---@param msg string
function _addon:PrintSuccess(msg)
PrintToChat(msg, "|cFF33FF33");
end
--- Print error message (red)
---@param msg string
function _addon:PrintError(msg)
PrintToChat(msg, "|cFFFF3333");
end
--- Print warning message (orange)
---@param msg string
function _addon:PrintWarn(msg)
PrintToChat(msg, "|cFFFFAA22");
end
--- Helper for printing tables
---@param t table
---@param depth number
function _addon:PrintTable(t, depth)
if not depth then
depth = 1;
end
for k,v in pairs(t) do
print(string.rep("--", depth) .. " " .. k .. ": " .. tostring(v));
if type(v) == "table" then
self:PrintTable(v, depth+1);
end
end
end
--- Print message or table if debug output is on
---@param o any
function _addon:PrintDebug(o)
if not SpellCalc_settings.debug then
return;
end
if type(o) == "table" then
local count = 0;
for _ in pairs(o) do
count = count + 1;
end
print(tostring(o) .. " size: " .. count);
self:PrintTable(o, 1);
return;
end
print(o);
end
--[[ local HT4ID = 5188;
local NSID = 17116;
local currentCastTime = 0;
local hasNS = false;
local frame = CreateFrame("Frame");
local dstart = debugprofilestop();
local function getts()
return debugprofilestop() - dstart;
end
frame:SetScript("OnUpdate", function(self, d)
local spellName, _, _, castTime = GetSpellInfo(HT4ID);
if castTime ~= currentCastTime then
print(getts() .. ": CT change -> "..castTime);
currentCastTime = castTime;
end
end);
frame:SetScript("OnEvent", function(self, ev, arg)
if ev == "UNIT_AURA" and arg == "player" then
local nspresent = false;
for i = 1, 40 do
local name, _, _, _, _, _, _, _, _, spellId = UnitBuff("player", i);
if name == nil then
break;
end
if spellId == NSID then
nspresent = true;
break;
end
end
if nspresent and not hasNS then
hasNS = true;
print(getts() .. ": NS applied");
elseif not nspresent and hasNS then
hasNS = false;
print(getts() .. ": NS removed");
end
end
end);
frame:RegisterEvent("UNIT_AURA"); ]]