Skip to content

Commit 65d63be

Browse files
committed
feat(WIP): First implementation of Generic Caller
1 parent 1b0a310 commit 65d63be

6 files changed

Lines changed: 129 additions & 60 deletions

File tree

AzerothCoreAdmin.toc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Libraries\Graph-1.0\Graph-1.0.lua
3131
Locales\enUS.lua
3232
Locales\strings.lua
3333
models.lua
34+
Utils\Consts.lua
35+
Utils\Utils.lua
3436
Commands\Commands_Generics.lua
3537
Commands\Commands_Main.lua
3638
Commands\Commands_Tele.lua
@@ -63,4 +65,4 @@ Frames\MangFrames_SectionServer.lua
6365
Frames\MangFrames_SectionNpc.lua
6466
Frames\MangFrames_SectionGO.lua
6567
Frames\MangFrames_SectionWho.lua
66-
MangFrames.lua
68+
MangFrames.lua

Commands/Commands_Generics.lua

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,31 @@
1515
--
1616
-------------------------------------------------------------------------------------------------------------
1717

18-
COMMAND_TARGET_PLAYERS_SELF_ONLY = 1
19-
20-
commandTargetChecks = {
21-
[COMMAND_TARGET_PLAYERS_SELF_ONLY] = function()
22-
return (MangAdmin:Selection("player") or MangAdmin:Selection("self") or MangAdmin:Selection("none"))
23-
end
24-
}
25-
26-
function commandTargetCheck(checkType)
27-
return commandTargetChecks[checkType]()
28-
end
29-
30-
function getCommandTargetName()
31-
return (UnitName("target") or UnitName("player"))
32-
end
33-
3418
function clearParametersBox(caller)
35-
if(caller == "GM") then
19+
if (caller == "GM") then
3620
ma_gmParametersInput:SetText("")
3721
end
3822
end
3923

4024
function ShowBag(caller)
4125
local player = UnitName("player") or UnitName("target")
4226
local param = nil
43-
if(caller == "GM") then
27+
if (caller == "GM") then
4428
param = ma_gmParametersInput:GetText()
4529
end
4630
MangAdmin:ChatMsg(".character check bag " .. param)
4731
MangAdmin:LogAction(Locale["ma_gmBagOutput"] .. player .. " " .. param)
48-
end
32+
end
4933

34+
function genericCaller(dictionaryID, callID, value)
35+
local dictionary = getCallsDictionary(dictionaryID)
36+
local call = dictionary[callID]
37+
local param = "";
38+
if call[GENERICS_isValueNeeded] then
39+
param = value
40+
elseif call[GENERICS_isParametersNeeded] then
41+
param = dictionary[GENERICS_parametersGet]()
42+
end
43+
MangAdmin:ChatMsg(call[GENERICS_command].. param)
44+
MangAdmin:LogAction(genericLogGenerator(call[GENERICS_message], param))
45+
end

Commands/Commands_Main.lua

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,52 @@
1616
-- Subversion Repository: http://mangadmin.googlecode.com/svn/
1717
--
1818
-------------------------------------------------------------------------------------------------------------
19-
20-
function DisplayAccountLevel()
21-
MangAdmin:ChatMsg(".account")
22-
MangAdmin:LogAction(Locale["ma_displayleveloutput"])
23-
end
19+
-- Generic Command Template
20+
--[[
21+
[COMMAND_NAME_KEY] = {
22+
[GENERICS_isValueNeeded] = false|true,
23+
[GENERICS_isParametersNeeded] = false|true,
24+
[GENERICS_command] = "command",
25+
[GENERICS_message] = "messageID"
26+
}
27+
]]
28+
29+
GM_genericCommands = {
30+
[GENERICS_parametersGet] = function() return ma_gmParametersInput:GetText() end,
31+
[GM_displayAccountGMLevel] = {
32+
[GENERICS_command] = ".account",
33+
[GENERICS_message] = "ma_displayleveloutput"
34+
},
35+
[GM_flyMode] = {
36+
[GENERICS_isValueNeeded] = true,
37+
[GENERICS_command] = ".gm fly ",
38+
[GENERICS_message] = "ma_FlyOnoutput"
39+
},
40+
[GM_godMode] = {
41+
[GENERICS_isValueNeeded] = true,
42+
[GENERICS_command] = ".cheat god ",
43+
[GENERICS_message] = "ma_GodOnoutput"
44+
},
45+
[GM_acceptWhispers] = {
46+
[GENERICS_isValueNeeded] = true,
47+
[GENERICS_command] = ".whispers ",
48+
[GENERICS_message] = "ma_WhisperOnoutput"
49+
},
50+
[GM_visibility] = {
51+
[GENERICS_isValueNeeded] = true,
52+
[GENERICS_command] = ".gm visible ",
53+
[GENERICS_message] = "ma_InvisOnoutput"
54+
}
55+
}
2456

2557
function ToggleGMMode(value)
2658
MangAdmin:ChatMsg(".gm " .. value)
2759
MangAdmin:ChatMsg(".gm chat " .. value)
28-
MangAdmin:LogAction(Locale["ma_GMOnoutput"] .. value)
29-
end
30-
31-
function ToggleFlyMode(value)
32-
MangAdmin:ChatMsg(".gm fly " .. value)
33-
MangAdmin:LogAction(Locale["ma_FlyOnoutput"] .. value)
34-
end
35-
36-
function ToggleGodMode(value)
37-
MangAdmin:ChatMsg(".cheat god " .. value)
38-
MangAdmin:LogAction(Locale["ma_GodOnoutput"] .. value)
39-
end
40-
41-
function ToggleWhisper(value)
42-
MangAdmin:ChatMsg(".whispers " .. value)
43-
MangAdmin:LogAction(Locale["ma_WhisperOnoutput"] .. value)
44-
end
45-
46-
function ToggleVisible(value)
47-
MangAdmin:ChatMsg(".gm visible " .. value)
48-
MangAdmin:LogAction(Locale["ma_InvisOnoutput"] .. value)
60+
MangAdmin:LogAction(genericLogGenerator("ma_GMOnoutput",value))
4961
end
5062

5163
function ToggleTaxicheat(value)
52-
if commandTargetCheck(COMMAND_TARGET_PLAYERS_SELF_ONLY) then
64+
if commandTargetCheck() then
5365
MangAdmin:ChatMsg(".cheat taxi " .. value)
5466
MangAdmin:LogAction(
5567
(value == "on" and Locale["genericEnabledText"] or Locale["genericDisabledText"]) ..
@@ -61,7 +73,7 @@ function ToggleTaxicheat(value)
6173
end
6274

6375
function ToggleMaps(value)
64-
if commandTargetCheck(COMMAND_TARGET_PLAYERS_SELF_ONLY) then
76+
if commandTargetCheck() then
6577
MangAdmin:ChatMsg(".cheat explore " .. value)
6678
MangAdmin:LogAction(
6779
(value == 1 and Locale["genericEnabledText"] or Locale["genericDisabledText"]) ..
@@ -73,7 +85,7 @@ function ToggleMaps(value)
7385
end
7486

7587
function ToggleWaterwalk(value)
76-
if commandTargetCheck(COMMAND_TARGET_PLAYERS_SELF_ONLY) then
88+
if commandTargetCheck() then
7789
MangAdmin:ChatMsg(".cheat waterwalk " .. value)
7890
MangAdmin:LogAction(
7991
(value == "on" and Locale["genericEnabledText"] or Locale["genericDisabledText"]) ..
@@ -419,7 +431,7 @@ end
419431

420432
function SetSpeed()
421433
local value = string.format("%.1f", ma_speedslider:GetValue())
422-
if commandTargetCheck(COMMAND_TARGET_PLAYERS_SELF_ONLY) then
434+
if commandTargetCheck() then
423435
MangAdmin:ChatMsg(".modify speed " .. value)
424436
MangAdmin:LogAction(getCommandTargetName() .. Locale["ma_gmSpeedOutput"] .. value)
425437
else
@@ -430,7 +442,7 @@ end
430442

431443
function SetScale()
432444
local value = string.format("%.1f", ma_scaleslider:GetValue())
433-
if commandTargetCheck(COMMAND_TARGET_PLAYERS_SELF_ONLY) then
445+
if commandTargetCheck() then
434446
MangAdmin:ChatMsg(".modify scale " .. value)
435447
MangAdmin:LogAction(getCommandTargetName() .. Locale["ma_gmScaleOutput"] .. value)
436448
else

FunctionInit.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
function InitControls()
2323
--[[GM Tab]]
24-
MangAdmin:PrepareScript(ma_displaylevelbutton , Locale["ttGM_displayAccountGMLevel"] , function() DisplayAccountLevel() end)
24+
MangAdmin:PrepareScript(ma_displaylevelbutton , Locale["ttGM_displayAccountGMLevel"] , function() genericCaller("GM", GM_displayAccountGMLevel) end)
2525
MangAdmin:PrepareScript(ma_gmonbutton , Locale["ttGM_GMModeOnButton"] , function() ToggleGMMode("on") end)
2626
MangAdmin:PrepareScript(ma_gmoffbutton , Locale["ttGM_GMModeOffButton"] , function() ToggleGMMode("off") end)
27-
MangAdmin:PrepareScript(ma_flyonbutton , Locale["ttGM_flyModeOnButton"] , function() ToggleFlyMode("on") end)
28-
MangAdmin:PrepareScript(ma_flyoffbutton , Locale["ttGM_flyModeOffButton"] , function() ToggleFlyMode("off") end)
29-
MangAdmin:PrepareScript(ma_godonbutton , Locale["tt_GodOnButton"] , function() ToggleGodMode("on") end)
30-
MangAdmin:PrepareScript(ma_godoffbutton , Locale["tt_GodOffButton"] , function() ToggleGodMode("off") end)
31-
MangAdmin:PrepareScript(ma_whisperonbutton , Locale["tt_WhispOnButton"] , function() ToggleWhisper("on") end)
32-
MangAdmin:PrepareScript(ma_whisperoffbutton , Locale["tt_WhispOffButton"] , function() ToggleWhisper("off") end)
33-
MangAdmin:PrepareScript(ma_invisibleonbutton , Locale["tt_InvisOnButton"] , function() ToggleVisible("off") end)
34-
MangAdmin:PrepareScript(ma_invisibleoffbutton , Locale["tt_InvisOffButton"] , function() ToggleVisible("on") end)
27+
MangAdmin:PrepareScript(ma_flyonbutton , Locale["ttGM_flyModeOnButton"] , function() genericCaller("GM", GM_flyMode,"on") end)
28+
MangAdmin:PrepareScript(ma_flyoffbutton , Locale["ttGM_flyModeOffButton"] , function() genericCaller("GM", GM_flyMode,"off") end)
29+
MangAdmin:PrepareScript(ma_godonbutton , Locale["tt_GodOnButton"] , function() genericCaller("GM", GM_godMode, "on") end)
30+
MangAdmin:PrepareScript(ma_godoffbutton , Locale["tt_GodOffButton"] , function() genericCaller("GM", GM_godMode, "off") end)
31+
MangAdmin:PrepareScript(ma_whisperonbutton , Locale["tt_WhispOnButton"] , function() genericCaller("GM", GM_acceptWhispers, "on") end)
32+
MangAdmin:PrepareScript(ma_whisperoffbutton , Locale["tt_WhispOffButton"] , function() genericCaller("GM", GM_acceptWhispers, "off") end)
33+
MangAdmin:PrepareScript(ma_invisibleonbutton , Locale["tt_InvisOnButton"] , function() genericCaller("GM", GM_visibility, "off") end)
34+
MangAdmin:PrepareScript(ma_invisibleoffbutton , Locale["tt_InvisOffButton"] , function() genericCaller("GM", GM_visibility, "on") end)
3535
MangAdmin:PrepareScript(ma_taxicheatonbutton , Locale["tt_TaxiOnButton"] , function() ToggleTaxicheat("on") end)
3636
MangAdmin:PrepareScript(ma_taxicheatoffbutton , Locale["tt_TaxiOffButton"] , function() ToggleTaxicheat("off") end)
3737
MangAdmin:PrepareScript(ma_mapsonbutton , Locale["tt_ShowMapsButton"] , function() ToggleMaps(1) end)

Utils/Consts.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Role identity Keys
2+
GM_KEY = "GM"
3+
4+
-- Generic Spells Action Keys
5+
GENERICS_parametersGet = "parametersGet"
6+
GENERICS_isValueNeeded = "isValueNeeded"
7+
GENERICS_isParametersNeeded = "isParametersNeeded"
8+
GENERICS_command = "command"
9+
GENERICS_message = "message"
10+
11+
-- Spells Keys
12+
GM_displayAccountGMLevel = "displayAccountLevel"
13+
GM_flyMode = "flyMode"
14+
GM_godMode = "godMode"
15+
GM_acceptWhispers = "acceptWhispers"
16+
GM_visibility = "visibility"

Utils/Utils.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-------------------------------------------------------------------------------------------------------------
2+
--
3+
-- AzerothCoreAdmin is a derivative of TrinityAdmin and MangAdmin.
4+
--
5+
-- Copyright (C) 2018 Free Software Foundation, Inc.
6+
-- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
7+
-- This is free software: you are free to change and redistribute it.
8+
-- There is NO WARRANTY, to the extent permitted by law.
9+
--
10+
-- You should have received a copy of the GNU General Public License
11+
-- along with this program; if not, write to the Free Software
12+
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13+
--
14+
-- Official repository: https://github.com/LightDestory/AzerothCoreAdmin
15+
--
16+
-------------------------------------------------------------------------------------------------------------
17+
18+
function commandTargetCheck()
19+
return (MangAdmin:Selection("player") or MangAdmin:Selection("self") or MangAdmin:Selection("none"))
20+
end
21+
22+
function getCommandTargetName()
23+
return (UnitName("target") or UnitName("player"))
24+
end
25+
26+
function genericLogGenerator(textID, values)
27+
local log = Locale[textID]
28+
local params = {}
29+
for w in values:gmatch("%w+") do
30+
table.insert(params, w)
31+
end
32+
for i=#params, 1, -1 do
33+
local pattern = "_V" .. i .. "_"
34+
log = string.gsub(log, pattern, params[i])
35+
end
36+
return log
37+
end
38+
39+
function getCallsDictionary(ID)
40+
if ID == GM_KEY then return GM_genericCommands
41+
else return nil
42+
end
43+
end

0 commit comments

Comments
 (0)