Skip to content

Commit

Permalink
Fix LuaCheck warnings (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panquesito7 committed Jul 26, 2023
1 parent 1b181c5 commit f680091
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [push, pull_request]
name: build
jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run LuaCheck
uses: Roang-zero1/factorio-mod-luacheck@master
with:
luacheckrc_url: ""
5 changes: 5 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
unused_args = false
max_line_length = false

globals = {
"vkore", "player_stats", "hb", "players", "gold",
"party", "nodes", "mapgen", "spawners", "pathfinder",
"mobkit", "mobkit_custom", "swords", "vk_quests", "vk_quest",
"rhotator", "matrix", "dungeons"
}

read_globals = {
Expand All @@ -23,4 +27,5 @@ exclude_files = {
"mods/sfinv/",
"mods/screwdriver2/",
"mods/creative/",
"mods/luamatrix/"
}
18 changes: 9 additions & 9 deletions mods/luamatrix/matrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
LUA MODULE
matrix v$(_VERSION) - matrix functions implemented with Lua tables
SYNOPSIS
local matrix = require 'matrix'
m1 = matrix{{8,4,1},{6,8,3}}
m2 = matrix{{-8,1,3},{5,2,1}}
assert(m1 + m2 == matrix{{0,5,4},{11,10,4}})
DESCRIPTION
With simple matrices this script is quite useful, though for more
exact calculations, one would probably use a program like Matlab instead.
Matrices of size 100x100 can still be handled very well.
The error for the determinant and the inverted matrix is around 10^-9
with a 100x100 matrix and an element range from -100 to 100.
Characteristics:
- functions called via matrix.<function> should be able to handle
any table matrix of structure t[i][j] = value
- can handle a type of complex matrix
Expand All @@ -39,7 +39,7 @@ DESCRIPTION
or use num = vec1:scalar( vec2 ), where num is a number
API
matrix function list:
matrix.add
Expand Down Expand Up @@ -83,7 +83,7 @@ API
matrix.tostring
matrix.transpose
matrix.type
See code and test_matrix.lua.
DEPENDENCIES
Expand All @@ -100,11 +100,11 @@ DOWNLOAD/INSTALL
./util.mk
cd tmp/*
luarocks make
LICENSE
Licensed under the same terms as Lua itself.
Developers:
Michael Lutz (chillcode) - original author
David Manura http://lua-users.org/wiki/DavidManura
Expand Down
40 changes: 17 additions & 23 deletions mods/rhotator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local function get_multi_action(playername, primary, sneak)
if not logic_sneak then
return {"memory", "Cycles through memory modes"}
else
return {"copy", "Copies rotation from pointed-to node"}
return {"copy", "Copies rotation from pointed-to node"}
end
end
end
Expand Down Expand Up @@ -160,10 +160,6 @@ local function extract_unit_vectors(player, pointed_thing)
local abs_face_pos = minetest.pointed_thing_to_face_pos(player, pointed_thing)
local pos = pointed_thing.under
local f = vector.subtract(abs_face_pos, pos)
local facedir = 0
local primary = 0

local m1, m2

local unit_direction = vector.new()
local unit_rotation = vector.new()
Expand Down Expand Up @@ -264,10 +260,9 @@ end

local function rotate_main(param2_rotation, player, pointed_thing, click, rot_index, sneak)
local unit = extract_unit_vectors(player, pointed_thing)
local current_pos = pointed_thing.under

local message
local transform = false
local transform
local rotation = rot_matrices[rot_index]

if click == PRIMARY_BTN then
Expand Down Expand Up @@ -400,7 +395,7 @@ local function rhotator_on_placenode(pos, newnode, player, oldnode, itemstack, p
if not copy_rotation_callback(true, player, pointed_thing) then return end
memory = ON
end

local new_rotation = facedir_memory[playername]
if memory == ON and not new_rotation then
notify(player, "Default placement (no stored rotation)")
Expand All @@ -412,22 +407,22 @@ local function rhotator_on_placenode(pos, newnode, player, oldnode, itemstack, p
notify.warning(player, "Unregistered node placed")
return
end

local paramtype2 = nodedef.paramtype2

if paramtype2 ~= "facedir" and paramtype2 ~= "colorfacedir" then
notify.warning(player, "Default placement (can't rotate nodes of this type)")
return
end

local old_rotation = newnode.param2 % 32 -- get first 5 bits
local remaining = newnode.param2 - old_rotation
local new_param2 = new_rotation + remaining

local click = SECONDARY_BTN

if not rhotator.check_on_rotate_handler(pos, newnode, nodedef, player, click, new_param2) then return end

newnode.param2 = new_param2
minetest.swap_node(pos, newnode)
minetest.check_for_falling(pos)
Expand Down Expand Up @@ -512,9 +507,9 @@ local function interact(player, pointed_thing, click, sneak)
end

local new_param2, handler_message = handler(node, player, pointed_thing, click, sneak)

if not rhotator.check_on_rotate_handler(pos, node, nodedef, player, click, new_param2) then return end

node.param2 = new_param2
minetest.swap_node(pos, node)
minetest.check_for_falling(pos)
Expand Down Expand Up @@ -572,18 +567,17 @@ copy_rotation_callback = function(itemstack, player, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
local pos = pointed_thing.under
local node = minetest.get_node(pointed_thing.under)
local nodedef = minetest.registered_nodes[node.name]

if not nodedef then
notify.error(player, "Unsupported node type: " .. node.name)
return
end

local paramtype2 = nodedef.paramtype2

if paramtype2 ~= "facedir" and paramtype2 ~= "colorfacedir" then
if paramtype2 ~= "facedir" and paramtype2 ~= "colorfacedir" then
notify.warning(player, "Unsupported node type: " .. node.name .. " - cannot copy rotation")
return
end
Expand Down Expand Up @@ -618,19 +612,19 @@ minetest.register_tool("rhotator:memory", {
local function multi_callback(itemstack, player, pointed_thing, button)
local playername = player and player:get_player_name() or ""
local primary = button == PRIMARY_BTN
local sneak = player and player:get_player_control().sneak
local sneak = player and player:get_player_control().sneak
local action = get_multi_action(playername, primary, sneak)[1]

if action == "memory" then
toggle_memory_callback(itemstack, player, pointed_thing)
toggle_memory_callback(itemstack, player, pointed_thing)
elseif action == "copy" then
copy_rotation_callback(itemstack, player, pointed_thing)
elseif action == "rotate" then
interact(player, pointed_thing, SECONDARY_BTN, false)
elseif action == "push" then
interact(player, pointed_thing, PRIMARY_BTN, false)
interact(player, pointed_thing, PRIMARY_BTN, false)
else
notify.error(playername, "Get a better developer")
notify.error(playername, "Get a better developer")
end
end

Expand Down
6 changes: 3 additions & 3 deletions mods/vk_enemies/pathfinder/astar_core.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- LUALOCALS < ---------------------------------------------------------
local next, pairs
local _, pairs
= next, pairs
-- LUALOCALS > ---------------------------------------------------------

Expand All @@ -22,7 +22,7 @@ Returns:
Nil if pathfinding failed entirely, or already at goal.
- Truthy if a real solution was found, falsey if path is a
partial estimated solution based on heuristic.
- Total real cost of solution path given.
- Total real cost of solution path given.
- Number of maxpts NOT consumed by the search.
--]]

Expand Down Expand Up @@ -78,7 +78,7 @@ local function astar(start, heur, maxpts, edgecost, neigh)

local curptcost = costs[curpt]
for n in neigh(curpt) do
repeat
repeat
if closed[n] then break end
local newcost = curptcost + edgecost(curpt, n)
local oldcost = costs[n]
Expand Down

0 comments on commit f680091

Please sign in to comment.