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