Add the game

This commit is contained in:
a-bad-dev 2025-12-06 11:37:08 -04:00
commit 38caa29558
863 changed files with 36331 additions and 0 deletions

View file

@ -0,0 +1,10 @@
name: luacheck
on: [push, pull_request]
jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Luacheck
uses: lunarmodules/luacheck@master

View file

@ -0,0 +1,8 @@
globals = {
"controls",
}
read_globals = {
"minetest",
}

21
mods/controls/debug.lua Normal file
View file

@ -0,0 +1,21 @@
controls.register_on_press(function(player, key)
local name = player:get_player_name()
minetest.chat_send_player(name, name .. " pressed " .. key)
end)
controls.register_on_hold(function(player, key, length)
local name = player:get_player_name()
minetest.chat_send_player(name, name .. " held " .. key .. " for " .. length .. " seconds")
end)
controls.register_on_release(function(player, key, length)
local name = player:get_player_name()
minetest.chat_send_player(name, name .. " released " .. key .. " after " .. length .. " seconds")
end)
minetest.register_on_joinplayer(function(player)
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_hold .. " registered_on_hold callbacks")
minetest.chat_send_player(name, #controls.registered_on_release .. " registered_on_release callbacks")
end)

67
mods/controls/init.lua Normal file
View file

@ -0,0 +1,67 @@
controls = {
registered_on_press = {},
registered_on_hold = {},
registered_on_release = {},
players = {},
}
function controls.register_on_press(callback)
table.insert(controls.registered_on_press, callback)
end
function controls.register_on_hold(callback)
table.insert(controls.registered_on_hold, callback)
end
function controls.register_on_release(callback)
table.insert(controls.registered_on_release, callback)
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
controls.players[name] = {}
for key in pairs(player:get_player_control()) do
controls.players[name][key] = {false}
end
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
controls.players[name] = nil
end)
local function update_player_controls(player, player_controls)
local time_now = minetest.get_us_time()
for key, pressed in pairs(player:get_player_control()) do
if player_controls[key] then
if pressed and not player_controls[key][1] then
for _, callback in pairs(controls.registered_on_press) do
callback(player, key)
end
player_controls[key] = {true, time_now}
elseif pressed and player_controls[key][1] then
for _, callback in pairs(controls.registered_on_hold) do
callback(player, key, (time_now - player_controls[key][2]) / 1e6)
end
elseif not pressed and player_controls[key][1] then
for _, callback in pairs(controls.registered_on_release) do
callback(player, key, (time_now - player_controls[key][2]) / 1e6)
end
player_controls[key] = {false}
end
end
end
end
minetest.register_globalstep(function()
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if controls.players[name] then
update_player_controls(player, controls.players[name])
end
end
end)
if minetest.settings:get_bool("controls_enable_debug", false) then
dofile(minetest.get_modpath("controls") .. "/debug.lua")
end

24
mods/controls/license Normal file
View file

@ -0,0 +1,24 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (c) 2023 wsor4035(aka wsor)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

3
mods/controls/mod.conf Normal file
View file

@ -0,0 +1,3 @@
name = controls
description = Utility library for control press/hold/release events
min_minetest_version = 5.0.0

35
mods/controls/readme.md Normal file
View file

@ -0,0 +1,35 @@
# Controls [controls]
[![luacheck](https://github.com/mt-mods/controls/workflows/luacheck/badge.svg)](https://github.com/mt-mods/controls/actions)
[![ContentDB](https://content.minetest.net/packages/mt-mods/controls/shields/downloads/)](https://content.minetest.net/packages/mt-mods/controls/)
Utility library for control press/hold/release events.
Rewritten and maintained version of [Arcelmi/minetest-controls](https://github.com/Arcelmi/minetest-controls).
## API
Callbacks are supported for all keys in `player:get_player_control()`.
```lua
controls.register_on_press(function(player, key)
-- Called when a key is pressed
-- player: player object
-- key: key pressed
end)
controls.register_on_hold(function(player, key, length)
-- Called every globalstep while a key is held
-- player: player object
-- key: key pressed
-- length: length of time key has been held in seconds
end)
controls.register_on_release(function(player, key, length)
-- Called when a key is released
-- player: player object
-- key: key pressed
-- length: length of time key was held in seconds
end)
```

View file

@ -0,0 +1,2 @@
# Enable debug mod for player controls. Sends chat messages to the player when callbacks are called.
controls_enable_debug (Enable debug mode) bool false