diff --git a/.luacheckrc b/.luacheckrc index 830ebfd..d9b2fbe 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -7,7 +7,7 @@ globals = { "minetest", "core", --mod provided - + "controls", } read_globals = { diff --git a/init.lua b/init.lua index e69de29..8e11cc2 100644 --- a/init.lua +++ b/init.lua @@ -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 \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..68a05d8 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1 @@ +controls_enable_tests (enable testing mode for player controls) bool false \ No newline at end of file diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..6d0be2c --- /dev/null +++ b/test.lua @@ -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) \ No newline at end of file