add luacheck and fix common errors

also fixes https://github.com/pandorabox-io/pandorabox.io/issues/493
This commit is contained in:
BuckarooBanzay 2020-04-27 10:44:56 +02:00
parent e2d8721a52
commit c01518913b
3 changed files with 57 additions and 16 deletions

18
.github/workflows/luacheck.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: luacheck
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt-get install -y luarocks
- name: luacheck install
run: luarocks install --local luacheck
- name: luacheck run
run: $HOME/.luarocks/bin/luacheck ./

21
.luacheckrc Normal file
View File

@ -0,0 +1,21 @@
globals = {
"hangglider",
"areas"
}
read_globals = {
-- Stdlib
string = {fields = {"split", "trim"}},
table = {fields = {"copy", "getn"}},
-- Minetest
"minetest",
"vector", "ItemStack",
"dump", "dump2",
"VoxelArea",
-- deps
"wardzones",
"minetestd",
"player_monoids"
}

View File

@ -54,7 +54,8 @@
local HUD_Overlay = true --show glider struts as overlay on HUD
local debug = false --show debug info in top-center of hud
local moveModelUp = false
if tonumber(string.sub(minetest.get_version().string, 1, 1)) and tonumber(string.sub(minetest.get_version().string, 1, 1)) > 4 then
if tonumber(string.sub(minetest.get_version().string, 1, 1)) and
tonumber(string.sub(minetest.get_version().string, 1, 1)) > 4 then
moveModelUp = true
end
hangglider = {} --Make this global, so other mods can tell if hangglider exists.
@ -99,7 +100,7 @@ minetest.register_entity("hangglider:airstopper", { --A one-instant entity that
end
})]]
if core.global_exists("areas") then
if minetest.global_exists("areas") then
hangglider.flak = true
-- chat command definition essentially copied from areas mod.
minetest.register_chatcommand("area_flak",{
@ -124,14 +125,13 @@ if core.global_exists("areas") then
})
end
if core.global_exists("minetestd") and minetestd.services.physicsctl.enabled then
if minetest.global_exists("minetestd") and minetestd.services.physicsctl.enabled then
minetestd.physicsctl.register_physics_effect("hangglider",
function(player) -- check
return hangglider.use[player:get_player_name()]
end,
function(phys, player) -- blend
local vel_y = player:get_player_velocity().y
if debug then player:hud_change(hangglider.debug[pname].id, "text", vel_y..', '..player:get_physics_override().gravity..', '..tostring(hangglider.airbreak[pname])) end
phys.gravity = phys.gravity*((vel_y + 3)/20)
if vel_y < 0 and vel_y > -3 then
phys.speed = (math.abs(vel_y/2) + 0.75)
@ -149,11 +149,12 @@ hangglider.can_fly = function (pname, pos)
if wardzones then
local zone = wardzones.getZone(pos)
if zone then
return (minetest.check_player_privs(pname, {protection_bypass=true}) or wardzones.checkPlayerZoneAccess(pname, zone) or not zone["data"]["no_fly"])
return (minetest.check_player_privs(pname, {protection_bypass=true}) or
wardzones.checkPlayerZoneAccess(pname, zone) or not zone["data"]["no_fly"])
end
end
if areas and hangglider.flak then
for id, area in pairs(areas:getAreasAtPos(pos)) do
for _, area in pairs(areas:getAreasAtPos(pos)) do
if area.flak then
return false
end
@ -186,7 +187,7 @@ end
local function remove_physics_override(player, overrides)
for _, attr in pairs(physics_attrs) do
if overrides[attr] then
if core.global_exists("player_monoids") then
if minetest.global_exists("player_monoids") then
player_monoids[attr]:del_change(player, "hangglider:glider")
else
player:set_physics_override({[attr] = 1})
@ -226,14 +227,13 @@ minetest.register_entity("hangglider:glider", {
else
remove_physics_override(player, {speed=1})
end
if debug then player:hud_change(hangglider.debug[pname].id, "text", step_v..', '..player:get_physics_override().gravity..', '..tostring(hangglider.airbreak[pname])) end
if debug then
player:hud_change(hangglider.debug[pname].id, "text", step_v..', '..
player:get_physics_override().gravity..', '..tostring(hangglider.airbreak[pname]))
end
apply_physics_override(player, {gravity=((step_v + 3)/20)})
end
--[[local vel = player:get_player_velocity()
if debug then player:hud_change(hangglider.debug[pname].id, "text", vel.y..', '..grav..', '..tostring(hangglider.airbreak[pname])) end
player:set_physics_override({gravity = (vel.y + 2.0)/20})
]]end
end
end
end
if not hangglider.can_fly(pname,pos) then
@ -321,7 +321,7 @@ minetest.register_tool("hangglider:hangglider", {
description = "Glider",
inventory_image = "glider_item.png",
stack_max=1,
on_use = function(itemstack, player, pointed_thing)
on_use = function(itemstack, player)
if not player then
return
end
@ -331,7 +331,6 @@ minetest.register_tool("hangglider:hangglider", {
minetest.sound_play("bedsheet", {pos=pos, max_hear_distance = 8, gain = 1.0})
if HUD_Overlay then player:hud_change(hangglider.id[pname], "text", "glider_struts.png") end
local airbreak = false
local vel = player:get_player_velocity().y
--[[if vel < -1.5 then -- engage mid-air, falling fast, so stop but ramp velocity more quickly
--hangglider.airbreak[pname] = true
airbreak = true
@ -368,7 +367,10 @@ minetest.register_tool("hangglider:hangglider", {
minetest.register_craft({
type = "shapeless",
output = "hangglider:hangglider",
recipe = {"default:paper", "default:paper", "default:paper", "default:paper", "hangglider:hangglider", "default:paper", "default:paper", "default:paper", "default:paper"},
recipe = {"default:paper", "default:paper", "default:paper",
"default:paper", "hangglider:hangglider", "default:paper",
"default:paper", "default:paper", "default:paper"
},
})
minetest.register_craft({