add luacheck / fix some issues

This commit is contained in:
BuckarooBanzay 2022-08-09 17:59:31 +02:00
parent 664eec36e6
commit 9a9808703e
5 changed files with 49 additions and 11 deletions

11
.github/workflows/luacheck.yml vendored Normal file

@ -0,0 +1,11 @@
on: [push, pull_request]
name: luacheck
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: lint
uses: Roang-zero1/factorio-mod-luacheck@master
with:
luacheckrc_url: ""

21
.luacheckrc Normal file

@ -0,0 +1,21 @@
unused = false
globals = {
"currency", "barter",
"default"
}
read_globals = {
-- Lua
string = {fields = {"split", "trim"}},
table = {fields = {"copy", "getn"}},
-- Minetest
"minetest",
"PseudoRandom", "ItemStack",
"VoxelArea", "VoxelManip",
"Settings", "vector",
-- Mods
"loot", "pipeworks"
}

@ -47,8 +47,8 @@ barter.chest.check_privilege = function(listname,playername,meta)
end
barter.chest.update_formspec = function(meta)
formspec = barter.chest.formspec.main
pl_formspec = function (n)
local formspec = barter.chest.formspec.main
local pl_formspec = function (n)
if meta:get_int(n.."step")==0 then
formspec = formspec .. barter.chest.formspec[n].start
else
@ -65,9 +65,9 @@ barter.chest.update_formspec = function(meta)
end
barter.chest.give_inventory = function(inv,list,playername)
player = minetest.get_player_by_name(playername)
local player = minetest.get_player_by_name(playername)
if player then
for k,v in ipairs(inv:get_list(list)) do
for _,v in ipairs(inv:get_list(list)) do
if player:get_inventory():room_for_item("main",v) then
player:get_inventory():add_item("main",v)
else
@ -144,7 +144,7 @@ minetest.register_node("currency:barter", {
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
barter.chest.start_timer(pos, meta)
pl_receive_fields = function(n)
local pl_receive_fields = function(n)
if fields[n.."_start"] and meta:get_string(n) == "" then
meta:set_string(n,sender:get_player_name())
end

@ -41,10 +41,10 @@ if income_enabled then
if not player or player.is_fake_player then return end
local name = player:get_player_name()
local income_count = players_income[name]
if income_count and income_count > 0 then
local ic = players_income[name]
if ic and ic > 0 then
local inv = player:get_inventory()
inv:add_item("main", {name=income_item, count=income_count})
inv:add_item("main", {name=income_item, count=ic})
players_income[name] = nil
minetest.log("info", "[Currency] added basic income for "..name.." to inventory")
end

@ -61,7 +61,7 @@ end
currency.shop.give_inventory = function(inv,list,playername)
player = minetest.get_player_by_name(playername)
local player = minetest.get_player_by_name(playername)
if player then
for k,v in ipairs(inv:get_list(list)) do
player:get_inventory():add_item("main",v)
@ -238,7 +238,10 @@ minetest.register_node("currency:shop", {
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives")
return inv:is_empty("stock") and
inv:is_empty("customers_gave") and
inv:is_empty("owner_wants") and
inv:is_empty("owner_gives")
end
})
@ -305,7 +308,10 @@ minetest.register_node("currency:shop_empty", {
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives")
return inv:is_empty("stock") and
inv:is_empty("customers_gave") and
inv:is_empty("owner_wants") and
inv:is_empty("owner_gives")
end
})