diff options
author | Wuzzy <wuzzy2@mail.ru> | 2020-05-26 00:17:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 00:17:52 +0200 |
commit | 083b285f4319c470f307f0b52f03a2fb68facd38 (patch) | |
tree | bdd02540ad58756a38606f03a995ab837a176709 /games/devtest/mods/testformspec/callbacks.lua | |
parent | b546e8938d41aa9e3101fb9d4d5b02924ed73b60 (diff) | |
download | minetest-083b285f4319c470f307f0b52f03a2fb68facd38.tar.gz minetest-083b285f4319c470f307f0b52f03a2fb68facd38.tar.bz2 minetest-083b285f4319c470f307f0b52f03a2fb68facd38.zip |
Rename “Minimal development test” to “Development Test” (#9928)
Diffstat (limited to 'games/devtest/mods/testformspec/callbacks.lua')
-rw-r--r-- | games/devtest/mods/testformspec/callbacks.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/games/devtest/mods/testformspec/callbacks.lua b/games/devtest/mods/testformspec/callbacks.lua new file mode 100644 index 000000000..559380580 --- /dev/null +++ b/games/devtest/mods/testformspec/callbacks.lua @@ -0,0 +1,51 @@ +local callback_test = 0 + +local out = function(player, formname, fields, number) + local snum = "" + if number then + snum = " "..number + end + local msg = "Formspec callback"..snum..": player="..player:get_player_name()..", formname=\""..tostring(formname).."\", fields="..dump(fields) + minetest.chat_send_player(player:get_player_name(), msg) + minetest.log("action", msg) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 1 then + out(player, formname, fields) + elseif callback_test == 2 then + out(player, formname, fields, 1) + end +end) +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 2 then + out(player, formname, fields, 2) + return true -- Disable the first callback + end +end) +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 2 then + out(player, formname, fields, 3) + end +end) + +minetest.register_chatcommand("test_formspec_callbacks", { + params = "[ 0 | 1 | 2 ]", + description = "Test: Change formspec callbacks testing mode", + func = function(name, param) + local mode = tonumber(param) + if not mode then + callback_test = (callback_test + 1 % 3) + else + callback_test = mode + end + if callback_test == 1 then + minetest.chat_send_player(name, "Formspec callback test mode 1 enabled: Logging only") + elseif callback_test == 2 then + minetest.chat_send_player(name, "Formspec callback test mode 2 enabled: Three callbacks, disable pre-registered callbacks") + else + callback_test = 0 + minetest.chat_send_player(name, "Formspec callback test disabled!") + end + end +}) |