From a1e857fff0e1fb524e3cdc9c86204bf0ae89b468 Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:44:29 -0500 Subject: [PATCH] add intial api layout and a test mode --- .luacheckrc | 2 +- init.lua | 21 +++++++++++++++++++++ settingtypes.txt | 1 + test.lua | 11 +++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 settingtypes.txt create mode 100644 test.lua 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