From ba2402c056b6134dd61b1b8d8deb2971ad5dac49 Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:51:55 -0500 Subject: [PATCH] store callbacks in the traditional minetest way, expand tests --- init.lua | 14 ++++++++++---- test.lua | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 8e11cc2..235a3fc 100644 --- a/init.lua +++ b/init.lua @@ -1,19 +1,25 @@ controls = { + --util values modpath = minetest.get_modpath("controls"), - testsmode = minetest.settings:get_bool("controls_enable_tests", false) + testsmode = minetest.settings:get_bool("controls_enable_tests", false), + + --location to store callbacks + registered_on_press = {}, + registered_on_hold = {}, + registered_on_release = {}, } --api functions function controls.register_on_press(callback) - + table.insert(controls.registered_on_press, callback) end function controls.register_on_hold(callback) - + table.insert(controls.registered_on_hold, callback) end function controls.register_on_release(callback) - + table.insert(controls.registered_on_release, callback) end if(controls.testsmode) then diff --git a/test.lua b/test.lua index 6d0be2c..9f74784 100644 --- a/test.lua +++ b/test.lua @@ -8,4 +8,11 @@ end) controls.register_on_release(function(player, key, length) minetest.chat_send_all(player:get_player_name() .. " released " .. key .. " after " .. length .. " seconds") +end) + +minetest.register_on_joinplayer(function(player, _) + local pname = player:get_player_name() + minetest.chat_send_player(pname, #controls.registered_on_press .. " registered_on_press callbacks") + minetest.chat_send_player(pname, #controls.registered_on_hold .. " registered_on_hold callbacks") + minetest.chat_send_player(pname, #controls.registered_on_release .. " registered_on_release callbacks") end) \ No newline at end of file