mirror of
https://github.com/mt-mods/controls.git
synced 2024-11-28 01:23:43 +01:00
store callbacks in the traditional minetest way, expand tests
This commit is contained in:
parent
a1e857fff0
commit
ba2402c056
14
init.lua
14
init.lua
@ -1,19 +1,25 @@
|
|||||||
controls = {
|
controls = {
|
||||||
|
--util values
|
||||||
modpath = minetest.get_modpath("controls"),
|
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
|
--api functions
|
||||||
function controls.register_on_press(callback)
|
function controls.register_on_press(callback)
|
||||||
|
table.insert(controls.registered_on_press, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
function controls.register_on_hold(callback)
|
function controls.register_on_hold(callback)
|
||||||
|
table.insert(controls.registered_on_hold, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
function controls.register_on_release(callback)
|
function controls.register_on_release(callback)
|
||||||
|
table.insert(controls.registered_on_release, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
if(controls.testsmode) then
|
if(controls.testsmode) then
|
||||||
|
7
test.lua
7
test.lua
@ -9,3 +9,10 @@ end)
|
|||||||
controls.register_on_release(function(player, key, length)
|
controls.register_on_release(function(player, key, length)
|
||||||
minetest.chat_send_all(player:get_player_name() .. " released " .. key .. " after " .. length .. " seconds")
|
minetest.chat_send_all(player:get_player_name() .. " released " .. key .. " after " .. length .. " seconds")
|
||||||
end)
|
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