mirror of
https://github.com/mt-mods/controls.git
synced 2024-11-28 01:23:43 +01:00
tabs not spaces
This commit is contained in:
parent
1d3d25dc66
commit
776e527663
20
debug.lua
20
debug.lua
@ -1,21 +1,21 @@
|
|||||||
controls.register_on_press(function(player, key)
|
controls.register_on_press(function(player, key)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, name .. " pressed " .. key)
|
minetest.chat_send_player(name, name .. " pressed " .. key)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
controls.register_on_hold(function(player, key, length)
|
controls.register_on_hold(function(player, key, length)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, name .. " held " .. key .. " for " .. length .. " seconds")
|
minetest.chat_send_player(name, name .. " held " .. key .. " for " .. length .. " seconds")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
controls.register_on_release(function(player, key, length)
|
controls.register_on_release(function(player, key, length)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, name .. " released " .. key .. " after " .. length .. " seconds")
|
minetest.chat_send_player(name, name .. " released " .. key .. " after " .. length .. " seconds")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.chat_send_player(name, #controls.registered_on_press .. " registered_on_press callbacks")
|
minetest.chat_send_player(name, #controls.registered_on_press .. " registered_on_press callbacks")
|
||||||
minetest.chat_send_player(name, #controls.registered_on_hold .. " registered_on_hold callbacks")
|
minetest.chat_send_player(name, #controls.registered_on_hold .. " registered_on_hold callbacks")
|
||||||
minetest.chat_send_player(name, #controls.registered_on_release .. " registered_on_release callbacks")
|
minetest.chat_send_player(name, #controls.registered_on_release .. " registered_on_release callbacks")
|
||||||
end)
|
end)
|
||||||
|
38
init.lua
38
init.lua
@ -1,33 +1,33 @@
|
|||||||
controls = {
|
controls = {
|
||||||
registered_on_press = {},
|
registered_on_press = {},
|
||||||
registered_on_hold = {},
|
registered_on_hold = {},
|
||||||
registered_on_release = {},
|
registered_on_release = {},
|
||||||
players = {},
|
players = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
function controls.register_on_press(callback)
|
function controls.register_on_press(callback)
|
||||||
table.insert(controls.registered_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)
|
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)
|
table.insert(controls.registered_on_release, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
controls.players[name] = {}
|
controls.players[name] = {}
|
||||||
for key in pairs(player:get_player_control()) do
|
for key in pairs(player:get_player_control()) do
|
||||||
controls.players[name][key] = {false}
|
controls.players[name][key] = {false}
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
controls.players[name] = nil
|
controls.players[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function update_player_controls(player, player_controls)
|
local function update_player_controls(player, player_controls)
|
||||||
@ -52,14 +52,14 @@ local function update_player_controls(player, player_controls)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
minetest.register_globalstep(function()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if controls.players[name] then
|
if controls.players[name] then
|
||||||
update_player_controls(player, controls.players[name])
|
update_player_controls(player, controls.players[name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if minetest.settings:get_bool("controls_enable_debug", false) then
|
if minetest.settings:get_bool("controls_enable_debug", false) then
|
||||||
dofile(minetest.get_modpath("controls") .. "/debug.lua")
|
dofile(minetest.get_modpath("controls") .. "/debug.lua")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user