-
Notifications
You must be signed in to change notification settings - Fork 2
/
Commands.lua
102 lines (90 loc) · 3.58 KB
/
Commands.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
--############################################
-- Namespace
--############################################
local SwitchSwitch, L = unpack(select(2, ...))
SwitchSwitch.Commands = {}
local Commands = SwitchSwitch.Commands
--##########################################################################################################################
-- Commands Fnctions
--##########################################################################################################################
function Commands:Help()
SwitchSwitch:Print("--------- |cff00F3FF"..L["List of commands"]..":|r ---------");
SwitchSwitch:Print("|cff188E01/ss help|r - " .. L["Shows all commands"] .. ".");
SwitchSwitch:Print("|cff188E01/ss config|r - " .. L["Shows the config frame"] .. ".");
SwitchSwitch:Print("|cff188E01/ss load <profileName>|r - " .. L["Loads a talent profile"] .. ".");
SwitchSwitch:Print("|cff188E01/ss resetFrame suggestion|r - " .. L["Resets the suggestion frame location"] .. ".");
SwitchSwitch:Print("-------------------------------------");
end
function Commands:LoadProfileCMD(...)
SwitchSwitch:DebugPrint("Changing talents to: " .. ...)
local name = SwitchSwitch:ToLower(CreateAtlasMarkup("gmchat-icon-blizz", 16, 16) .. string.join(" ", tostringall(...)));
local profiles = self:GetProfiles();
for k,v in pairs(profiles) do
if(SwitchSwitch:ToLower(v.name) == name) then
SwitchSwitch:ActivateTalentProfile(k);
break;
end
end
end
function Commands:ResetFrameLocation(frame)
if(frame == "suggestion") then
SwitchSwitch.db.profile.talentsSuggestionFrame.point =
{
["point"] = "CENTER",
["relativePoint"] = "CENTER",
["frameX"] = 0,
["frameY"] = 0
}
end
end
--##########################################################################################################################
-- Commands handling
--##########################################################################################################################
local CommandList =
{
["config"] = SwitchSwitch.ShowMainFrame_Config,
["help"] = Commands.Help,
["load"] = Commands.LoadProfileCMD,
["resetFrame"] = Commands.ResetFrameLocation
}
local function HandleSlashCommands(str)
if (#str == 0) then
Commands:Help()
-- User entered command without any args
return
end
local args = {}
for _, arg in ipairs({ string.split(' ', str) }) do
if (#arg > 0) then
table.insert(args, arg)
end
end
local path = CommandList -- required for updating found table.
for id, arg in ipairs(args) do
if (#arg > 0) then -- if string length is greater than 0.
arg = SwitchSwitch:ToLower(arg)
if (path[arg]) then
if (type(path[arg]) == "function") then
-- all remaining args passed to our function
path[arg](SwitchSwitch, select(id + 1,unpack(args)))
return
elseif (type(path[arg]) == "table") then
path = path[arg] -- another sub-table found!
end
else
-- does not exist!
Commands:Help()
return
end
end
end
end
--##########################################################################################################################
-- Commands Init
--##########################################################################################################################
function Commands:Init()
SLASH_SwitchSwitch1 = "/ss"
SLASH_SwitchSwitch2 = "/sstalent"
SLASH_SwitchSwitch3 = "/switchswitch"
SlashCmdList.SwitchSwitch = HandleSlashCommands
end