Change code so that no luacheck warnings are issued

This commit is contained in:
Joachim Stolberg 2024-08-16 17:41:42 +02:00
parent cff00b97fb
commit b6473faed3
21 changed files with 229 additions and 257 deletions

28
.luacheckrc Normal file
View File

@ -0,0 +1,28 @@
unused_args = false
ignore = {
"131", -- Unused global variable
"432", -- Shadowing an upvalue argument
}
read_globals = {
"core",
"minetest",
"default",
"worldedit",
"tubelib2",
"intllib",
"DIR_DELIM",
"techage",
string = {fields = {"split", "trim"}},
vector = {fields = {"add", "equals", "multiply"}},
table = {fields = {"copy", ""}},
}
globals = {
"hyperloop",
"ItemStack",
"screwdriver",
}

View File

@ -13,11 +13,11 @@
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta --local M = minetest.get_meta
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS --local NS = hyperloop.NS
local tBlockingTime = {} local tBlockingTime = {}
local tBookings = {} -- open bookings: tBookings[SP(departure_pos)] = arrival_pos local tBookings = {} -- open bookings: tBookings[SP(departure_pos)] = arrival_pos

View File

@ -18,7 +18,6 @@ local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
-- Used to store the Station list for each booking machine: -- Used to store the Station list for each booking machine:
-- tStationList[SP(pos)] = {pos1, pos2, ...} -- tStationList[SP(pos)] = {pos1, pos2, ...}
@ -95,7 +94,6 @@ end
-- Used to update the station list for booking machine -- Used to update the station list for booking machine
-- and teleport list. -- and teleport list.
local function station_list_as_string(pos, subnet) local function station_list_as_string(pos, subnet)
local meta = M(pos)
-- Generate a name sorted list of all connected stations -- Generate a name sorted list of all connected stations
local sortedList = Stations:station_list(pos, pos, "name") local sortedList = Stations:station_list(pos, pos, "name")
-- remove all junctions from the list -- remove all junctions from the list
@ -108,7 +106,7 @@ local function station_list_as_string(pos, subnet)
return generate_string(sortedList) return generate_string(sortedList)
end end
local naming_formspec = nil local naming_formspec
if hyperloop.subnet_enabled then if hyperloop.subnet_enabled then
naming_formspec = function(pos) naming_formspec = function(pos)

View File

@ -12,30 +12,12 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end --local P = minetest.string_to_pos
local P = minetest.string_to_pos --local M = minetest.get_meta
local M = minetest.get_meta
hyperloop.Stations = hyperloop.Network:new() hyperloop.Stations = hyperloop.Network:new()
hyperloop.Elevators = hyperloop.Network:new() hyperloop.Elevators = hyperloop.Network:new()
-- Check all nodes on the map and delete useless data base entries
local function check_data_base()
-- used for VM get_node
local tube = tubelib2.Tube:new({})
hyperloop.Stations:filter(function(pos)
local _,node = tube:get_node(pos)
return node.name == "hyperloop:station" or node.name == "hyperloop:junction"
end)
hyperloop.Elevators:filter(function(pos)
local _,node = tube:get_node(pos)
return node.name == "hyperloop:elevator_bottom"
end)
end
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
hyperloop.Stations:deserialize(storage:get_string("Stations")) hyperloop.Stations:deserialize(storage:get_string("Stations"))
hyperloop.Elevators:deserialize(storage:get_string("Elevators")) hyperloop.Elevators:deserialize(storage:get_string("Elevators"))

View File

@ -15,13 +15,12 @@
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local tilesL = {"hyperloop_alpsL.png", "hyperloop_seaL.png", "hyperloop_agyptL.png"} local tilesL = {"hyperloop_alpsL.png", "hyperloop_seaL.png", "hyperloop_agyptL.png"}
local tilesR = {"hyperloop_alpsR.png", "hyperloop_seaR.png", "hyperloop_agyptR.png"} local tilesR = {"hyperloop_alpsR.png", "hyperloop_seaR.png", "hyperloop_agyptR.png"}
-- determine facedir and pos on the right hand side from the given pos -- determine facedir and pos on the right hand side from the given pos
function right_hand_side(pos, placer) local function right_hand_side(pos, placer)
local facedir = hyperloop.get_facedir(placer) local facedir = hyperloop.get_facedir(placer)
pos = hyperloop.new_pos(pos, facedir, "1R", 0) pos = hyperloop.new_pos(pos, facedir, "1R", 0)
return facedir,pos return facedir,pos

View File

@ -11,13 +11,12 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end --local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
--- Load support for intllib. --- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
-- Open the door for an emergency -- Open the door for an emergency
local function door_on_punch(pos, node, puncher, pointed_thing) local function door_on_punch(pos, node, puncher, pointed_thing)
@ -40,7 +39,6 @@ local function door_command(door_pos1, facedir, cmnd)
local node1 = minetest.get_node(door_pos1) local node1 = minetest.get_node(door_pos1)
local node2 = minetest.get_node(door_pos2) local node2 = minetest.get_node(door_pos2)
local meta = minetest.get_meta(door_pos1)
if cmnd == "open" then if cmnd == "open" then
minetest.sound_play("door", { minetest.sound_play("door", {
pos = door_pos1, pos = door_pos1,

View File

@ -17,7 +17,6 @@ local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
-- To store elevator floors and formspecs -- To store elevator floors and formspecs
local Cache = {} local Cache = {}
@ -65,8 +64,8 @@ Shaft:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir
-- switch to elevator_bottom node -- switch to elevator_bottom node
pos = Shaft:get_pos(pos, 5) pos = Shaft:get_pos(pos, 5)
elseif peer_pos then elseif peer_pos then
local _,node = Shaft:get_node(peer_pos) local _,node1 = Shaft:get_node(peer_pos)
if node.name == "hyperloop:elevator_top" then if node1.name == "hyperloop:elevator_top" then
peer_pos = Shaft:get_pos(peer_pos, 5) peer_pos = Shaft:get_pos(peer_pos, 5)
end end
end end
@ -463,11 +462,11 @@ minetest.register_node("hyperloop:elevator_bottom", {
-- formspec -- formspec
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local formspec = "size[6,4]".. local fs = "size[6,4]"..
"label[0,0;"..S("Please insert floor name").."]" .. "label[0,0;"..S("Please insert floor name").."]" ..
"field[0.5,1.5;5,1;floor;"..S("Floor name")..";"..S("Base").."]" .. "field[0.5,1.5;5,1;floor;"..S("Floor name")..";"..S("Base").."]" ..
"button_exit[2,3;2,1;exit;"..S("Save").."]" "button_exit[2,3;2,1;exit;"..S("Save").."]"
meta:set_string("formspec", formspec) meta:set_string("formspec", fs)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
-- add upper part of the car -- add upper part of the car

View File

@ -11,13 +11,12 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end --local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Tube = hyperloop.Tube local Tube = hyperloop.Tube
local Stations = hyperloop.Stations local Stations = hyperloop.Stations

View File

@ -12,8 +12,6 @@
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
-- load characters map -- load characters map
local chars_file = io.open(minetest.get_modpath("hyperloop").."/characters.data", "r") local chars_file = io.open(minetest.get_modpath("hyperloop").."/characters.data", "r")

View File

@ -12,12 +12,11 @@
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta --local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Stations = hyperloop.Stations local Stations = hyperloop.Stations

View File

@ -22,7 +22,6 @@ local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Tube = hyperloop.Tube local Tube = hyperloop.Tube
local Shaft = hyperloop.Shaft local Shaft = hyperloop.Shaft
@ -126,7 +125,7 @@ local function convert_legary_nodes(self, pos, dir)
end end
local function convert_line(self, pos, dir) local function convert_line(self, pos, dir)
local fpos,fdir = convert_legary_nodes(self, pos, dir) convert_legary_nodes(self, pos, dir)
self:tool_repair_tube(pos) self:tool_repair_tube(pos)
end end
@ -139,8 +138,8 @@ local function set_pairing(pos, peer_pos)
M(pos):set_int("tube_dir", Tube:get_primary_dir(pos)) M(pos):set_int("tube_dir", Tube:get_primary_dir(pos))
M(peer_pos):set_int("tube_dir", Tube:get_primary_dir(peer_pos)) M(peer_pos):set_int("tube_dir", Tube:get_primary_dir(peer_pos))
local tube_dir1 = Tube:store_teleport_data(pos, peer_pos) Tube:store_teleport_data(pos, peer_pos)
local tube_dir2 = Tube:store_teleport_data(peer_pos, pos) Tube:store_teleport_data(peer_pos, pos)
end end
@ -195,8 +194,8 @@ end
local function search_wifi_node(pos, dir) local function search_wifi_node(pos, dir)
local convert_next_tube = function(pos, dir) local convert_next_tube = function(pos, dir)
local npos, node = Tube:get_node(pos, dir) local npos, _ = Tube:get_node(pos, dir)
local dir1, dir2, num = next_node_on_the_way_to_a_wifi_node(npos) local dir1, dir2, _ = next_node_on_the_way_to_a_wifi_node(npos)
if dir1 then if dir1 then
if tubelib2.Turn180Deg[dir] == dir1 then if tubelib2.Turn180Deg[dir] == dir1 then
return npos, dir2 return npos, dir2
@ -220,7 +219,7 @@ end
local function search_wifi_node_in_all_dirs(pos) local function search_wifi_node_in_all_dirs(pos)
-- check all positions -- check all positions
for dir = 1, 6 do for dir = 1, 6 do
local npos, node = Tube:get_node(pos, dir) local _, node = Tube:get_node(pos, dir)
if node and node.name == "hyperloop:tube1" then if node and node.name == "hyperloop:tube1" then
search_wifi_node(pos, dir) search_wifi_node(pos, dir)
end end
@ -230,7 +229,7 @@ end
local function convert_tube_line(pos) local function convert_tube_line(pos)
-- check all positions -- check all positions
for dir = 1, 6 do for dir = 1, 6 do
local npos, node = Tube:get_node(pos, dir) local _, node = Tube:get_node(pos, dir)
if node and node.name == "hyperloop:tube1" then if node and node.name == "hyperloop:tube1" then
convert_line(Tube, pos, dir) convert_line(Tube, pos, dir)
end end

View File

@ -14,7 +14,7 @@
-- for lazy programmers -- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta --local M = minetest.get_meta
-- Convert to list and add pos based on key string -- Convert to list and add pos based on key string
local function table_to_list(table) local function table_to_list(table)

View File

@ -15,7 +15,6 @@
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
minetest.register_craftitem("hyperloop:hypersteel_ingot", { minetest.register_craftitem("hyperloop:hypersteel_ingot", {
description = S("Hypersteel Ingot"), description = S("Hypersteel Ingot"),

View File

@ -11,16 +11,14 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end --local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local I, _ = dofile( minetest.get_modpath("hyperloop").."/intllib.lua") local I, _ = dofile( minetest.get_modpath("hyperloop").."/intllib.lua")
local Stations = hyperloop.Stations
local PlayerNameTags = {} local PlayerNameTags = {}
local function enter_display(tStation, text) local function enter_display(tStation, text)

View File

@ -12,12 +12,11 @@
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Tube = hyperloop.Tube local Tube = hyperloop.Tube
local Stations = hyperloop.Stations local Stations = hyperloop.Stations
@ -111,7 +110,7 @@ end
local function check_space(pos, facedir, placer) local function check_space(pos, facedir, placer)
for _,item in ipairs(AssemblyPlan) do for _,item in ipairs(AssemblyPlan) do
local y, path, node_name = item[1], item[2], item[4] local y, path, _ = item[1], item[2], item[4]
pos = hyperloop.new_pos(pos, facedir, path, y) pos = hyperloop.new_pos(pos, facedir, path, y)
if minetest.is_protected(pos, placer:get_player_name()) then if minetest.is_protected(pos, placer:get_player_name()) then
hyperloop.chat(placer, S("Area is protected!")) hyperloop.chat(placer, S("Area is protected!"))
@ -229,7 +228,7 @@ local function destroy_station(pos, player_name)
-- remove nodes -- remove nodes
local _pos = table.copy(pos) local _pos = table.copy(pos)
for _,item in ipairs(AssemblyPlan) do for _,item in ipairs(AssemblyPlan) do
local y, path, node_name = item[1], item[2], item[4] local y, path, _ = item[1], item[2], item[4]
_pos = hyperloop.new_pos(_pos, station.facedir, path, y) _pos = hyperloop.new_pos(_pos, station.facedir, path, y)
minetest.remove_node(_pos) minetest.remove_node(_pos)
end end

View File

@ -11,27 +11,11 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta --local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local function station_name(pos)
local dataSet = hyperloop.get_station(pos)
if dataSet then
if dataSet.junction == true then
return S("Junction at ")..SP(pos)
elseif dataSet.name ~= nil then
return S("Station '")..dataSet.name.."' at "..SP(pos)
else
return S("Station at ")..SP(pos)
end
end
return S("Open end at ")..minetest.pos_to_string(pos)
end
function hyperloop.check_network_level(pos, player) function hyperloop.check_network_level(pos, player)
if hyperloop.free_tube_placement_enabled then if hyperloop.free_tube_placement_enabled then

View File

@ -12,12 +12,11 @@
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos --local P = minetest.string_to_pos
local M = minetest.get_meta --local M = minetest.get_meta
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Shaft = hyperloop.Shaft local Shaft = hyperloop.Shaft
local Tube = hyperloop.Tube local Tube = hyperloop.Tube
@ -52,7 +51,7 @@ local function repair_tubes(itemstack, placer, pointed_thing)
max_hear_distance=5, max_hear_distance=5,
loop=false}) loop=false})
else else
local dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 = dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 =
Tube:tool_repair_tube(pos, placer, pointed_thing) Tube:tool_repair_tube(pos, placer, pointed_thing)
if fpos1 and fpos2 then if fpos1 and fpos2 then
if cnt1 + cnt2 >= Shaft.max_tube_length then if cnt1 + cnt2 >= Shaft.max_tube_length then
@ -100,10 +99,6 @@ local function remove_tube(itemstack, placer, pointed_thing)
end end
end end
local function dump_data_base(pos)
print(dump(hyperloop.tDatabase))
end
-- Tool for tube workers to crack a protected tube line -- Tool for tube workers to crack a protected tube line
minetest.register_node("hyperloop:tube_crowbar", { minetest.register_node("hyperloop:tube_crowbar", {
description = S("Hyperloop Tube Crowbar"), description = S("Hyperloop Tube Crowbar"),

View File

@ -14,7 +14,7 @@
local PI = 3.1415926 local PI = 3.1415926
-- for lazy programmers -- for lazy programmers
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end --local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta

View File

@ -17,7 +17,6 @@ local Waypoints = {}
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
minetest.register_node("hyperloop:waypoint", { minetest.register_node("hyperloop:waypoint", {
description = S("Hyperloop Waypoint"), description = S("Hyperloop Waypoint"),

View File

@ -12,7 +12,6 @@
-- Load support for intllib. -- Load support for intllib.
local S = hyperloop.S local S = hyperloop.S
local NS = hyperloop.NS
local Tube = hyperloop.Tube local Tube = hyperloop.Tube