-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslashcmd.lua
197 lines (163 loc) · 6.16 KB
/
slashcmd.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
---@type string
local _addonName = select(1, ...);
---@class AddonEnv
local _addon = select(2, ...);
SLASH_SPELLCALC1 = "/sc";
SLASH_SPELLCALC2 = "/spellcalc";
---@type table<string, fun(args: string[]): nil>
local registeredCommands = {};
SlashCmdList["SPELLCALC"] = function(arg)
local args = strsplittable(" ", arg);
if #args > 0 and registeredCommands[args[1]] then
local cmd = table.remove(args, 1);
registeredCommands[cmd](args);
return;
end
InterfaceOptionsFrame_OpenToCategory(_addonName);
InterfaceOptionsFrame_OpenToCategory(_addonName);
--[[ if arg == "ub" then
_addon:UpdateAurasForUnit("player", true);
_addon:UpdateAurasForUnit("player");
_addon:UpdateAurasForUnit("target", true);
_addon:UpdateAurasForUnit("target");
return;
end ]]
--[[ if string.find(arg, "^tt") then
local talentOverride = {};
for tripel in string.gmatch(arg, "%d %d+ %d") do
local tree, talent, rank = strmatch(tripel, "(%d) (%d+) (%d)");
if tree == nil or talent == nil or rank == nil then
_addon.util.PrintWarn("tree, talent or rank nil for tripel: "..tripel);
return;
end
local treen = tonumber(tree);
local talentn = tonumber(talent);
local rankn = tonumber(rank);
local name, _, _, _, _, maxRank = GetTalentInfo(treen, talentn);
if rankn > maxRank then
_addon.util.PrintWarn("Rank " .. rankn .." invalid! Max rank = " .. maxRank);
return;
end
table.insert(talentOverride, {
tree = treen,
talent = talentn,
rank = rankn
});
print("Add talentoverride: "..name.. " "..rankn.."/"..maxRank);
end
if #talentOverride == 0 then
_addon.util.PrintWarn("No talents specified!");
return;
end
_addon:UpdateTalents(talentOverride);
return;
end ]]
if string.find(arg, "ps") then
local spellId = strmatch(arg, "(%d+)");
if spellId == nil then
_addon.util.PrintWarn("spellId is nil!");
return;
end
local calcedSpell = _addon:GetCurrentSpellData(tonumber(spellId)--[[@as integer]]);
if calcedSpell == nil then
_addon.util.PrintWarn("No current data for spell with ID "..spellId);
return;
end
print("=== Data for spell "..spellId.." ===============");
_addon.util.PrintTable(calcedSpell);
print("=========================================");
return;
end
if string.find(arg, "cs") then
local spellId = strmatch(arg, "(%d+)");
if spellId == nil then
_addon.util.PrintWarn("spellId is nil!");
return;
end
local calcedSpell = _addon:GetCalcedSpell(tonumber(spellId)--[[@as integer]]);
if calcedSpell == nil then
_addon.util.PrintWarn("No data for spell with ID "..spellId);
return;
end
print("=== Data for spell "..spellId.." ===============");
_addon.util.PrintTable(calcedSpell);
print("=========================================");
return;
end
if string.find(arg, "dii") then
local iid, slotid = strmatch(arg, "(%d+) (%d+)");
if iid and slotid then
_addon.util.PrintWarn("Debug equip item "..iid.." into slot "..slotid.."!");
_addon:DebugEquipItem(tonumber(iid)--[[@as integer]], tonumber(slotid)--[[@as integer]]);
end
return;
end
if string.find(arg, "dis") then
local slotid, itemLink = strmatch(arg, "(%d+) (.+)");
print(slotid, itemLink);
if itemLink and slotid then
---@type string
local Id = select(5, string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?"));
_addon.util.PrintWarn("Debug equip item "..Id.." into slot "..slotid.."!");
_addon:DebugEquipItem(tonumber(Id)--[[@as integer]], tonumber(slotid)--[[@as integer]]);
end
return;
end
if string.find(arg, "dab") then
local spellId = strmatch(arg, "(%d+)");
if spellId then
_addon:DebugApplyBuff(tonumber(spellId)--[[@as integer]]);
end
return;
end
if string.find(arg, "dsbf") then
local flags = strmatch(arg, "(%d+)");
local remove = string.find(arg, "-");
local flag = tonumber(flags)--[[@as integer]];
if flag then
if remove then
_addon:RemoveAuraEffect("Debug Flag "..flag, {
type = _addon.CONST.EFFECT_TYPE.BOOLEAN_BITFLAG_SET,
value = flag,
}, flag, 1, true);
else
_addon:ApplyAuraEffect("Debug Flag "..flag, {
type = _addon.CONST.EFFECT_TYPE.BOOLEAN_BITFLAG_SET,
value = flag,
}, flag, 1, true);
end
end
return;
end
if string.find(arg, "sval") then
local key = string.sub(arg, 6);
print(key);
if key then
print("Value for ", key, "is", _addon.scripting.GetValue(key));
end
return;
end
end
---Register a slash command.
---@param cmdOrCmds string | string[]
---@param callback fun(args: string[]): nil
function _addon:RegisterSlashCommand(cmdOrCmds, callback)
if type(cmdOrCmds) == "string" then
cmdOrCmds = {cmdOrCmds};
end
for _, cmd in ipairs(cmdOrCmds) do
assert(registeredCommands[cmd] == nil, "Command with that name already exists!");
registeredCommands[cmd] = callback;
end
end
_addon:RegisterSlashCommand("debug", function()
SpellCalc_settings.debug = not SpellCalc_settings.debug;
_addon.util.PrintWarn("Debug "..(SpellCalc_settings.debug and "active" or "disabled"));
end);
_addon:RegisterSlashCommand({"info", "i"}, function()
if SpellCalcStatScreen:IsShown() then
SpellCalcStatScreen:Hide();
else
SpellCalcStatScreen:Show();
end
end);