add intial api layout and a test mode

This commit is contained in:
wsor4035 2023-12-03 14:44:29 -05:00
parent 04e65a249f
commit a1e857fff0
4 changed files with 34 additions and 1 deletions

@ -7,7 +7,7 @@ globals = {
"minetest", "core",
--mod provided
"controls",
}
read_globals = {

@ -0,0 +1,21 @@
controls = {
modpath = minetest.get_modpath("controls"),
testsmode = minetest.settings:get_bool("controls_enable_tests", false)
}
--api functions
function controls.register_on_press(callback)
end
function controls.register_on_hold(callback)
end
function controls.register_on_release(callback)
end
if(controls.testsmode) then
dofile(controls.modpath .. "/test.lua")
end

1
settingtypes.txt Normal file

@ -0,0 +1 @@
controls_enable_tests (enable testing mode for player controls) bool false

11
test.lua Normal file

@ -0,0 +1,11 @@
controls.register_on_press(function(player, key)
minetest.chat_send_all(player:get_player_name() .. " pressed " .. key)
end)
controls.register_on_hold(function(player, key, length)
minetest.chat_send_all(player:get_player_name() .. " held " .. key .. " for " .. length .. " seconds")
end)
controls.register_on_release(function(player, key, length)
minetest.chat_send_all(player:get_player_name() .. " released " .. key .. " after " .. length .. " seconds")
end)