mirror of
https://github.com/mt-mods/controls.git
synced 2024-11-24 07:33:43 +01:00
store callbacks in the traditional minetest way, expand tests
This commit is contained in:
parent
6b32442368
commit
af05a85d89
14
init.lua
14
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
|
||||
|
7
test.lua
7
test.lua
@ -9,3 +9,10 @@ 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)
|
Loading…
Reference in New Issue
Block a user