Skip to content

Commit 823899b

Browse files
committed
refactor(GM): Convert cheatTaxi into genericCall
1 parent 043e331 commit 823899b

6 files changed

Lines changed: 39 additions & 27 deletions

File tree

Commands/Commands_Generics.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ end
3434
function genericCaller(dictionaryID, callID, value)
3535
local dictionary = getCallsDictionary(dictionaryID)
3636
local call = dictionary[callID]
37-
local param = "";
37+
local data = {
38+
["value"] = "",
39+
["target"] = nil
40+
}
3841
if call[GENERICS_isValueNeeded] then
39-
param = value
42+
data['value'] = value
4043
elseif call[GENERICS_isParametersNeeded] then
41-
param = dictionary[GENERICS_parametersGet]()
44+
data['value'] = dictionary[GENERICS_parametersGet]()
4245
end
43-
MangAdmin:ChatMsg(call[GENERICS_command].. param)
44-
MangAdmin:LogAction(genericLogGenerator(call[GENERICS_message], param))
46+
if call[GENERICS_isTargetCheckNeeded] then
47+
if commandTargetCheck() then
48+
data['target'] = getCommandTargetName()
49+
else
50+
MangAdmin:Print(Locale["selectionError"])
51+
return
52+
end
53+
end
54+
MangAdmin:ChatMsg(call[GENERICS_command].. data['value'])
55+
MangAdmin:LogAction(genericLogGenerator(call[GENERICS_message], data))
4556
end

Commands/Commands_Main.lua

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ GM_genericCommands = {
5151
[GENERICS_isValueNeeded] = true,
5252
[GENERICS_command] = ".gm visible ",
5353
[GENERICS_message] = "ma_InvisOnoutput"
54+
},
55+
[GM_cheatTaxi] = {
56+
[GENERICS_isValueNeeded] = true,
57+
[GENERICS_isTargetCheckNeeded] = true,
58+
[GENERICS_command] = ".cheat taxi ",
59+
[GENERICS_message] = "ma_TaxiOnoutput"
5460
}
5561
}
5662

@@ -60,18 +66,6 @@ function ToggleGMMode(value)
6066
MangAdmin:LogAction(genericLogGenerator("ma_GMOnoutput",value))
6167
end
6268

63-
function ToggleTaxicheat(value)
64-
if commandTargetCheck() then
65-
MangAdmin:ChatMsg(".cheat taxi " .. value)
66-
MangAdmin:LogAction(
67-
(value == "on" and Locale["genericEnabledText"] or Locale["genericDisabledText"]) ..
68-
Locale["ma_TaxiOnoutput"] .. getCommandTargetName()
69-
)
70-
else
71-
MangAdmin:Print(Locale["selectionError"])
72-
end
73-
end
74-
7569
function ToggleMaps(value)
7670
if commandTargetCheck() then
7771
MangAdmin:ChatMsg(".cheat explore " .. value)

FunctionInit.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function InitControls()
3232
MangAdmin:PrepareScript(ma_whisperoffbutton , Locale["tt_WhispOffButton"] , function() genericCaller("GM", GM_acceptWhispers, "off") end)
3333
MangAdmin:PrepareScript(ma_invisibleonbutton , Locale["tt_InvisOnButton"] , function() genericCaller("GM", GM_visibility, "off") end)
3434
MangAdmin:PrepareScript(ma_invisibleoffbutton , Locale["tt_InvisOffButton"] , function() genericCaller("GM", GM_visibility, "on") end)
35-
MangAdmin:PrepareScript(ma_taxicheatonbutton , Locale["tt_TaxiOnButton"] , function() ToggleTaxicheat("on") end)
36-
MangAdmin:PrepareScript(ma_taxicheatoffbutton , Locale["tt_TaxiOffButton"] , function() ToggleTaxicheat("off") end)
35+
MangAdmin:PrepareScript(ma_taxicheatonbutton , Locale["tt_TaxiOnButton"] , function() genericCaller("GM", GM_cheatTaxi, "on") end)
36+
MangAdmin:PrepareScript(ma_taxicheatoffbutton , Locale["tt_TaxiOffButton"] , function() genericCaller("GM", GM_cheatTaxi, "off") end)
3737
MangAdmin:PrepareScript(ma_mapsonbutton , Locale["tt_ShowMapsButton"] , function() ToggleMaps(1) end)
3838
MangAdmin:PrepareScript(ma_mapsoffbutton , Locale["tt_HideMapsButton"] , function() ToggleMaps(0) end)
3939
MangAdmin:PrepareScript(ma_instantkillbutton , Locale["tt_instakill"] , function() InstantKill() end)

Locales/enUS.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function Return_enUS()
224224
["ma_GodOnoutput"] = "Turned God-mode to _V1_",
225225
["ma_WhisperOnoutput"] = "Turned accepting whispers to _V1_",
226226
["ma_InvisOnoutput"] = "Turned your visibility to _V1_",
227-
["ma_TaxiOnoutput"] = " taxi cheat to ",
227+
["ma_TaxiOnoutput"] = "Taxi chat for _T_ has been set to _V1_",
228228
["ma_mapsoutput"] = " discover all maps cheat to ",
229229
["ma_waterwalkoutput"] = " waterwalk cheat to",
230230
["ma_NoCastTimeOnoutput"] = "Turned NoCastTime to ",

Utils/Consts.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GM_KEY = "GM"
55
GENERICS_parametersGet = "parametersGet"
66
GENERICS_isValueNeeded = "isValueNeeded"
77
GENERICS_isParametersNeeded = "isParametersNeeded"
8+
GENERICS_isTargetCheckNeeded = "isTargetCheckNeeded"
89
GENERICS_command = "command"
910
GENERICS_message = "message"
1011

@@ -14,3 +15,4 @@ GM_flyMode = "flyMode"
1415
GM_godMode = "godMode"
1516
GM_acceptWhispers = "acceptWhispers"
1617
GM_visibility = "visibility"
18+
GM_cheatTaxi = "cheatTaxi"

Utils/Utils.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,26 @@ function getCommandTargetName()
2323
return (UnitName("target") or UnitName("player"))
2424
end
2525

26-
function genericLogGenerator(textID, values)
26+
function genericLogGenerator(textID, data)
2727
local log = Locale[textID]
2828
local params = {}
29-
for w in values:gmatch("%w+") do
29+
for w in data['value']:gmatch("%w+") do
3030
table.insert(params, w)
31-
end
32-
for i=#params, 1, -1 do
31+
end
32+
for i = #params, 1, -1 do
3333
local pattern = "_V" .. i .. "_"
3434
log = string.gsub(log, pattern, params[i])
3535
end
36+
if data['target'] ~=nil then
37+
log = string.gsub(log, "_T_", data['target'])
38+
end
3639
return log
3740
end
3841

3942
function getCallsDictionary(ID)
40-
if ID == GM_KEY then return GM_genericCommands
41-
else return nil
43+
if ID == GM_KEY then
44+
return GM_genericCommands
45+
else
46+
return nil
4247
end
43-
end
48+
end

0 commit comments

Comments
 (0)