Skip to content

Commit

Permalink
add luacheck and integration test workflows / fix luacheck errors
Browse files Browse the repository at this point in the history
partially attends to pandorabox-io/pandorabox.io#444 (the ObjectRef issue)
  • Loading branch information
BuckarooBanzay committed Feb 13, 2020
1 parent f3ad7ec commit f81cb10
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 28 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: integration-test

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: integration-test
run: ./integration-test.sh
17 changes: 17 additions & 0 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: luacheck

on: [push]

jobs:
build:

runs-on: ubuntu-latest

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 ./
34 changes: 34 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

unused_args = false

globals = {
"wieldview",
"armor",
"armor_i18n",
"inventory_plus"
}

read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},

-- Minetest
"vector", "ItemStack",
"dump", "VoxelArea",

-- deps
"default",
"minetest",
"unified_inventory",
"intllib",
"wardrobe",
"player_monoids",
"armor_monoid",
"sfinv",
"ARMOR_MATERIALS",
"ARMOR_FIRE_NODES",
"pova",
"skins",
"u_skins"
}
7 changes: 3 additions & 4 deletions 3d_armor/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ armor.set_player_armor = function(self, player)
local material = {count=1}
local preview = armor:get_preview(name)
local texture = "3d_armor_trans.png"
local textures = {}
local physics = {}
local attributes = {}
local levels = {}
Expand Down Expand Up @@ -324,8 +323,8 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
local list = armor_inv:get_list("armor")
for i, stack in pairs(list) do
if stack:get_count() == 1 then
local name = stack:get_name()
local use = minetest.get_item_group(name, "armor_use") or 0
local itemname = stack:get_name()
local use = minetest.get_item_group(itemname, "armor_use") or 0
local damage = use > 0
local def = stack:get_definition() or {}
if type(def.on_punched) == "function" then
Expand Down Expand Up @@ -373,7 +372,7 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
end
end
if damage == true and hitter == "fire" then
damage = minetest.get_item_group(name, "flammable") > 0
damage = minetest.get_item_group(itemname, "flammable") > 0
end
if damage == true then
self:damage(player, i, stack, use)
Expand Down
49 changes: 30 additions & 19 deletions 3d_armor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ local F = minetest.formspec_escape

dofile(modpath.."/api.lua")

-- integration test
if minetest.settings:get_bool("enable_3d_armor_integration_test") then
dofile(modpath.."/integration_test.lua")
end


-- Legacy Config Support

local input = io.open(modpath.."/armor.conf", "r")
if input then
dofile(modpath.."/armor.conf")
input:close()
input = nil
end
input = io.open(worldpath.."/armor.conf", "r")
if input then
dofile(worldpath.."/armor.conf")
input:close()
input = nil
end
for name, _ in pairs(armor.config) do
local global = "ARMOR_"..name:upper()
Expand Down Expand Up @@ -169,9 +173,9 @@ local function validate_armor_inventory(player)
end
end

local function init_player_armor(player)
local name = player:get_player_name()
local pos = player:get_pos()
local function init_player_armor(initplayer)
local name = initplayer:get_player_name()
local pos = initplayer:get_pos()
if not name or not pos then
return false
end
Expand Down Expand Up @@ -214,20 +218,20 @@ local function init_player_armor(player)
end,
}, name)
armor_inv:set_size("armor", 6)
if not armor:load_armor_inventory(player) and armor.migrate_old_inventory then
local player_inv = player:get_inventory()
if not armor:load_armor_inventory(initplayer) and armor.migrate_old_inventory then
local player_inv = initplayer:get_inventory()
player_inv:set_size("armor", 6)
for i=1, 6 do
local stack = player_inv:get_stack("armor", i)
armor_inv:set_stack("armor", i, stack)
end
armor:save_armor_inventory(player)
armor:save_armor_inventory(initplayer)
player_inv:set_size("armor", 0)
end
for i=1, 6 do
local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then
armor:run_callbacks("on_equip", player, i, stack)
armor:run_callbacks("on_equip", initplayer, i, stack)
end
end
armor.def[name] = {
Expand Down Expand Up @@ -263,7 +267,7 @@ local function init_player_armor(player)
end
end
end
armor:set_player_armor(player)
armor:set_player_armor(initplayer)
return true
end

Expand Down Expand Up @@ -291,24 +295,31 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if not name then
return
end
local player_name = player:get_player_name()
for field, _ in pairs(fields) do
if string.find(field, "skins_set") then
minetest.after(0, function(player)
local skin = armor:get_player_skin(name)
armor.textures[name].skin = skin
armor:set_player_armor(player)
end, player)
minetest.after(0, function()
local pplayer = minetest.get_player_by_name(player_name)
if player then
local skin = armor:get_player_skin(name)
armor.textures[name].skin = skin
armor:set_player_armor(pplayer)
end
end)
end
end
end)

minetest.register_on_joinplayer(function(player)
default.player_set_model(player, "3d_armor_character.b3d")
minetest.after(0, function(player)
if init_player_armor(player) == false then
pending_players[player] = 0
local player_name = player:get_player_name()

minetest.after(0, function()
local pplayer = minetest.get_player_by_name(player_name)
if pplayer and init_player_armor(pplayer) == false then
pending_players[pplayer] = 0
end
end, player)
end)
end)

minetest.register_on_leaveplayer(function(player)
Expand Down
25 changes: 25 additions & 0 deletions 3d_armor/integration_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

minetest.log("warning", "[TEST] integration-test enabled!")

minetest.register_on_mods_loaded(function()
minetest.after(1, function()

local data = minetest.write_json({ success = true }, true);
local file = io.open(minetest.get_worldpath().."/integration_test.json", "w" );
if file then
file:write(data)
file:close()
end

file = io.open(minetest.get_worldpath().."/registered_nodes.txt", "w" );
if file then
for name in pairs(minetest.registered_nodes) do
file:write(name .. '\n')
end
file:close()
end

minetest.log("warning", "[TEST] integration tests done!")
minetest.request_shutdown("success")
end)
end)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Modpack - 3d Armor [0.4.13]
===========================

![](https://github.com/mt-mods/3d_armor/workflows/luacheck/badge.svg)
![](https://github.com/mt-mods/3d_armor/workflows/integration-test/badge.svg)

### Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down
20 changes: 20 additions & 0 deletions integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# simple integration test

CFG=/tmp/minetest.conf
MTDIR=/tmp/mt
WORLDDIR=${MTDIR}/worlds/world

cat <<EOF > ${CFG}
enable_3d_armor_integration_test = true
EOF

mkdir -p ${WORLDDIR}
chmod 777 ${MTDIR} -R
docker run --rm -i \
-v ${CFG}:/etc/minetest/minetest.conf:ro \
-v ${MTDIR}:/var/lib/minetest/.minetest \
-v $(pwd):/var/lib/minetest/.minetest/worlds/world/worldmods/3d_armor \
registry.gitlab.com/minetest/minetest/server:5.0.1

test -f ${WORLDDIR}/integration_test.json && exit 0 || exit 1
1 change: 0 additions & 1 deletion shields/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
local S = armor_i18n.gettext

local disable_sounds = minetest.settings:get_bool("shields_disable_sounds")
local use_moreores = minetest.get_modpath("moreores")
local function play_sound_effect(player, name)
if not disable_sounds and player then
local pos = player:get_pos()
Expand Down
10 changes: 6 additions & 4 deletions wieldview/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
wieldview.wielded_item[name] = ""
minetest.after(0, function(player)
wieldview:update_wielded_item(player)
end, player)
minetest.after(0, function()
local pplayer = minetest.get_player_by_name(name)
if player then
wieldview:update_wielded_item(pplayer)
end
end)
end)

minetest.register_globalstep(function(dtime)
Expand All @@ -80,4 +83,3 @@ minetest.register_globalstep(function(dtime)
time = 0
end
end)

0 comments on commit f81cb10

Please sign in to comment.