-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChocoboCommand.lua
306 lines (282 loc) · 9.93 KB
/
ChocoboCommand.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
--[[
Copyright (c) 2010-2020 by Adam Hellberg
This file is part of Chocobo.
Chocobo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Chocobo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Chocobo. If not, see <http://www.gnu.org/licenses/>.
--]]
Chocobo.Command = {
Slash = {
"chocobo"
},
Commands = {}
}
local C = Chocobo
local CC = C.Command
local CLib = ChocoboLib
local L = _G["ChocoboLocale"]
local AddCustomPattern = "\"([%w%p%s]+)\" \"([%w%p%s]+)\""
-- Argument #1 (command) can be either string or a table.
function CC:Register(command, func)
if type(command) == "string" then
command = {command}
end
for _,v in pairs(command) do
if not self:HasCommand(v) then
if v ~= "__DEFAULT__" then v = v:lower() end
self.Commands[v] = func
end
end
end
function CC:HasCommand(command)
return self.Commands[command]
end
function CC:HandleCommand(command, args)
if self:HasCommand(command) then
self.Commands[command](args)
elseif self:HasCommand("__DEFAULT__") then
self.Commands["__DEFAULT__"](args)
else
C:ErrorMsg((L["InvalidCommand"]):format(command))
end
end
CC:Register("__DEFAULT__", function()
C:Msg(L["HelpMessage1"])
C:Msg(L["HelpMessage2"])
C:Msg(L["HelpMessage3"])
C:Msg(L["HelpMessage4"])
C:Msg(L["HelpMessage17"])
C:Msg(L["HelpMessage18"])
C:Msg(L["HelpMessage19"])
C:Msg(L["HelpMessage5"])
C:Msg(L["HelpMessage6"])
C:Msg(L["HelpMessage7"])
C:Msg(L["HelpMessage8"])
C:Msg(L["HelpMessage9"])
C:Msg(L["HelpMessage10"])
C:Msg(L["HelpMessage12"])
C:Msg(L["HelpMessage13"])
C:Msg(L["HelpMessage14"])
C:Msg(L["HelpMessage15"])
C:Msg(L["HelpMessage16"])
C:Msg(L["HelpMessage11"])
end)
CC:Register({"options", "o", "config", "gui"}, function()
Chocobo.SoundControl.Options:Open()
Chocobo.Options:Open()
end)
CC:Register({"allmounts", "am", "all"}, function() C:FilterMount(false) end)
CC:Register({"hawkstrider", "hs", "hawk"}, function() C:FilterMount(true) end)
CC:Register({"modetoggle", "mounttoggle", "mt"}, function() C:FilterMount() end)
CC:Register({"toggle", "t"}, function() C:Toggle() end)
CC:Register({"plainstridertoggle", "plainstrider", "plainstriders", "ps"}, function() C:PlainstriderToggle() end)
CC:Register({"ridingcranetoggle", "ridingcrane", "ridingcranes", "rc"}, function() C:RidingCraneToggle() end)
CC:Register({"ravenlordtoggle", "ravenlord", "rl"}, function() C:RavenLordToggle() end)
CC:Register({"flametalontoggle", "flametalon", "flame", "alysrazor", "alys"}, function() C:FlametalonToggle() end)
CC:Register({"preventdupetoggle", "pdtoggle", "pdt"}, function() C:PreventDupeToggle() end)
CC:Register({"soundcontrol", "sc", "sndctrl", "sound"}, function(args)
local handled = false
if #args > 0 then
local vol = tonumber(args[3])
if args[1] == "gui" or args[1] == "options" then
Chocobo.SoundControl.Options:Open()
handled = true
elseif args[1] == "toggle" or args[1] == "t" then
C.SoundControl:Toggle()
handled = true
elseif args[1] == "default" or args[1] == "d" then
C.SoundControl:ToggleDefault()
handled = true
elseif args[1] == "music" or args[1] == "m" then
if #args > 1 then
if args[2] == "toggle" or args[2] == "t" then
C.SoundControl:ToggleMusic()
handled = true
elseif args[2]:match("^mount") or args[2] == "m" then
C.SoundControl:ToggleMusicMount()
handled = true
elseif args[2]:match("^not?mount") or args[2] == "nm" then
C.SoundControl:ToggleMusicNoMount()
handled = true
elseif args[2] == "volume" or args[2] == "vol" or args[2] == "v" then
if type(vol) == "number" then
C.SoundControl:SetMusicVolume(vol)
handled = true
elseif args[3] == "toggle" or args[3] == "t" then
C.SoundControl:ToggleMusicVolume()
handled = true
else
C.SoundControl:PrintMusicVolume()
handled = true
end
end
end
elseif args[1] == "sfx" or args[1] == "sound" or args[1] == "s" then
if #args > 1 then
if args[2] == "toggle" or args[2] == "t" then
C.SoundControl:ToggleSFX()
handled = true
elseif args[2]:match("^mount") or args[2] == "m" then
C.SoundControl:ToggleSFXMount()
handled = true
elseif args[2]:match("^not?mount") or args[2] == "nm" then
C.SoundControl:ToggleSFXNoMount()
handled = true
elseif args[2] == "volume" or args[2] == "vol" or args[2] == "v" then
if type(vol) == "number" then
C.SoundControl:SetSFXVolume(vol)
handled = true
elseif args[3] == "toggle" or args[3] == "t" then
C.SoundControl:ToggleSFXVolume()
handled = true
else
C.SoundControl:PrintSFXVolume()
handled = true
end
end
end
elseif args[1] == "ambience" or args[1] == "amb" or args[1] == "a" then
if #args > 1 then
if args[2] == "toggle" or args[2] == "t" then
C.SoundControl:ToggleAmbience()
handled = true
elseif args[2]:match("^mount") or args[2] == "m" then
C.SoundControl:ToggleAmbienceMount()
handled = true
elseif args[2]:match("^not?mount") or args[2] == "nm" then
C.SoundControl:ToggleAmbienceNoMount()
handled = true
elseif args[2] == "volume" or args[2] == "vol" or args[2] == "v" then
if type(vol) == "number" then
C.SoundControl:SetAmbienceVolume(vol)
handled = true
elseif args[3] == "toggle" or args[3] == "t" then
C.SoundControl:ToggleAmbienceVolume()
handled = true
else
C.SoundControl:PrintAmbienceVolume()
handled = true
end
end
end
end
end
if not handled then
C:Msg(L["SCSyntax1"])
C:Msg(L["SCSyntax2"])
end
end)
CC:Register({"list", "l", "ls"}, function() C:PrintMusic() end)
CC:Register({"reset", "r"}, function() C:ResetMusic() end)
CC:Register({"listmounts", "lm"}, function() C:PrintMounts() end)
CC:Register({"resetmounts", "rm"}, function() C:ResetMounts() end)
CC:Register({"debug", "d"}, function(args)
if not args[1] then
C:Debug()
else
C:Debug(args[1]:lower())
end
end)
CC:Register({"add", "a"}, function(args)
if #args > 0 then
local song = args[1]
if #args > 1 then
for i=2,#args do
song = song .. " " .. args[i]
end
end
C:AddMusic(song)
else
C:Msg(L["AddSyntax"])
end
end)
CC:Register({"remove", "rem", "delete", "del"}, function(args)
if #args > 0 then
local song = args[1]
if #args > 1 then
for i=2,#args do
song = song .. " " .. args[i]
end
end
C:RemoveMusic(song)
else
C:Msg(L["RemoveSyntax"])
end
end)
CC:Register({"addcustom", "addc", "ac"}, function(args)
if #args < 2 then
C:ErrorMsg(L["AddCustomSyntax"])
return
end
local arg = args[1]
for i=2,#args do
arg = arg .. " " .. args[i]
end
local mount, song = arg:match(AddCustomPattern)
if not mount or not song then
C:ErrorMsg(L["AddCustomSyntax"])
return
end
C:AddCustomMusic(song, mount)
end)
CC:Register({"removecustom", "removec", "remc", "rc"}, function(args)
if #args < 1 then
C:ErrorMsg(L["RemoveCustomSyntax"])
return
end
local arg = args[1]
if #args > 1 then
for i=2,#args do
arg = arg .. " " .. args[i]
end
end
C:RemoveCustomMusic(arg)
end)
CC:Register({"addmount", "addm"}, function(args)
if #args > 0 then
local mount = args[1]
if #args > 1 then
for i=2,#args do
mount = mount .. " " .. args[i]
end
end
C:AddMount(mount)
else
C:Msg(L["AddMountSyntax"])
end
end)
CC:Register({"removemount", "remm", "deletemount", "delmount", "delm"}, function(args)
if #args > 0 then
local mount = args[1]
if #args > 1 then
for i=2,#args do
mount = mount .. " " .. args[i]
end
end
C:RemoveMount(mount)
else
C:Msg(L["RemoveMountSyntax"])
end
end)
for i,v in ipairs(CC.Slash) do
_G["SLASH_" .. C.Name:upper() .. i] = "/" .. v
end
SlashCmdList[C.Name:upper()] = function(msg)
msg = CLib:Trim(msg)
local args = CLib:Split(msg)
local cmd = args[1]
local t = {}
if #args > 1 then
for i=2,#args do
table.insert(t, args[i])
end
end
CC:HandleCommand(cmd, t)
end