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