From 3a17818e34993199858930452ad28de3d05ccf39 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Sat, 24 Apr 2021 12:33:01 +0200 Subject: [PATCH] Add luacheck --- .github/workflows/luacheck.yml | 17 +++++++++++++++++ .gitignore | 2 ++ .luacheckrc | 22 ++++++++++++++++++++++ hud.lua | 4 ++-- internal.lua | 1 - protector.lua | 9 +++++---- 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/luacheck.yml create mode 100644 .gitignore create mode 100644 .luacheckrc diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..4077f41 --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,17 @@ +name: luacheck + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - 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 ./ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5236e1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ + diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..d7f5e44 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,22 @@ +unused_args = false + +read_globals = { + "DIR_DELIM", + "core", + "dump", + "vector", "nodeupdate", + "VoxelManip", "VoxelArea", + "PseudoRandom", "ItemStack", + "AreaStore", + "default", + "intllib", + "hud", + "mesecon", + table = { fields = { "copy", "getn", "indexof" } } +} + +globals = { + "minetest", + -- mod namespace + "areas" +} diff --git a/hud.lua b/hud.lua index bd3fb6b..124ab24 100644 --- a/hud.lua +++ b/hud.lua @@ -22,12 +22,12 @@ minetest.register_playerstep(function(_, playernames) if minetest.is_valid_pos(pos) then local areaStrings = {} - for id, area in pairs(areas:getAreasAtPos(pos)) do + for id, area in pairs(areas:getAreasAtPos(pos)) do areaStrings[#areaStrings+1] = ("%s [%u] (%s%s)") :format(area.name, id, area.owner, area.open and ":open" or "") end - + local str = "" for _, area in pairs(areas:getExternalHudEntries(pos)) do if area.name then str = area.name .. " " end diff --git a/internal.lua b/internal.lua index 01a672d..4f313de 100644 --- a/internal.lua +++ b/internal.lua @@ -34,7 +34,6 @@ function areas:load() return err end local data = file:read("*a") - local err if data:sub(1, 1) == "[" then self.areas, err = minetest.parse_json(data) else diff --git a/protector.lua b/protector.lua index 4d5ae8a..97b048f 100644 --- a/protector.lua +++ b/protector.lua @@ -39,7 +39,7 @@ minetest.register_node("areas:protector", { minetest.chat_send_player(name, red(S("You have already protected this area."))) return itemstack end - + local id = areas:add(name, S("Protector Block"), pos1, pos2) areas:save() minetest.chat_send_player(name, @@ -69,7 +69,8 @@ minetest.register_node("areas:protector", { end, on_punch = function(pos) - local objs = minetest.get_objects_inside_radius(pos, 0.5) -- a radius of 0.5 since the entity serialization seems to be not that precise + -- a radius of 0.5 since the entity serialization seems to be not that precise + local objs = minetest.get_objects_inside_radius(pos, 0.5) local displayed = false for _, o in pairs(objs) do if not o:is_player() and o:get_luaentity().name == "areas:display" then @@ -84,12 +85,12 @@ minetest.register_node("areas:protector", { }) -- entities code below (and above) mostly copied-pasted from Zeg9's protector mod - minetest.register_entity("areas:display", { physical = false, collisionbox = {0}, visual = "wielditem", - visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, -- wielditem seems to be scaled to 1.5 times original node size + -- wielditem seems to be scaled to 1.5 times original node size + visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5}, textures = {"areas:display_node"}, timer = 0, on_step = function(self, dtime)