mirror of
https://github.com/mt-mods/controls.git
synced 2024-11-28 01:23:43 +01:00
initial event loop and callback testing
This commit is contained in:
parent
1839dc8954
commit
efb61512fb
25
init.lua
25
init.lua
@ -25,6 +25,7 @@ function controls.register_on_release(callback)
|
|||||||
table.insert(controls.registered_on_release, callback)
|
table.insert(controls.registered_on_release, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--set up key store on join
|
||||||
minetest.register_on_joinplayer(function(player, _)
|
minetest.register_on_joinplayer(function(player, _)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local controls_names = player:get_player_control()
|
local controls_names = player:get_player_control()
|
||||||
@ -36,6 +37,30 @@ minetest.register_on_joinplayer(function(player, _)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--discard when leaving
|
||||||
|
minetest.register_on_leaveplayer(function(player, _)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
controls.players[pname] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
--event loop
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
local pcontrols = player:get_player_control()
|
||||||
|
|
||||||
|
if not controls.players[pname] then break end --safety check
|
||||||
|
|
||||||
|
for key, key_status in pairs(pcontrols) do
|
||||||
|
if(key_status) then --yes, this is a hold or press event, intial testing
|
||||||
|
for _, callback in pairs(controls.registered_on_press) do
|
||||||
|
callback(player, key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
--tests
|
--tests
|
||||||
if(controls.testsmode) then
|
if(controls.testsmode) then
|
||||||
dofile(controls.modpath .. "/test.lua")
|
dofile(controls.modpath .. "/test.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user