1
0
mirror of https://github.com/minetest-mods/3d_armor.git synced 2024-12-27 03:00:40 +01:00

Merge pull request #2 from mt-mods/code-quality

add luacheck and integration test workflows / fix luacheck errors
This commit is contained in:
Thomas Rudin 2020-02-17 17:36:52 +01:00 committed by GitHub
commit 4c99049600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 152 additions and 28 deletions

14
.github/workflows/integration-test.yml vendored Normal file
View File

@ -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
.github/workflows/luacheck.yml vendored Normal file
View File

@ -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
.luacheckrc Normal file
View File

@ -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"
}

View File

@ -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 = {}
@ -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
@ -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)

View File

@ -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()
@ -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
@ -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] = {
@ -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
@ -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)
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(player)
end, player)
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)

View File

@ -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)

View File

@ -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 -->

20
integration-test.sh Executable file
View File

@ -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

View File

@ -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()

View File

@ -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)
@ -80,4 +83,3 @@ minetest.register_globalstep(function(dtime)
time = 0
end
end)