2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
|
|
|
-- Some hardcoded settings and constants
|
|
|
|
-----------------------------------------------
|
2016-10-19 08:31:19 +02:00
|
|
|
local defaultmodule = "same_recipe"
|
|
|
|
local print_to_chat = true
|
2016-09-13 00:49:18 +02:00
|
|
|
|
2016-10-19 08:31:19 +02:00
|
|
|
-- constants
|
2016-10-24 23:43:44 +02:00
|
|
|
local modpath = minetest.get_modpath("qa_block")
|
|
|
|
local filepath = modpath.."/checks/"
|
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- Load external libs and other files
|
|
|
|
-----------------------------------------------
|
|
|
|
qa_block = {} -- needed as envroot in tools
|
|
|
|
local thismodpath = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
|
2016-10-25 15:33:39 +02:00
|
|
|
--- temporary provide smartfs as builtin, till the needed changes are upstream
|
|
|
|
dofile(thismodpath.."/smartfs.lua") --3rd party smarfs
|
|
|
|
local smartfs = qa_block.smartfs
|
|
|
|
local smartfsmod = "qa_block"
|
|
|
|
--- temporary end
|
|
|
|
|
|
|
|
--local smartfsmod = minetest.get_modpath("smartfs")
|
2016-10-24 23:43:44 +02:00
|
|
|
if smartfsmod then --smartfs is optional
|
|
|
|
dofile(thismodpath.."/smartfs_forms.lua") --qa_block forms
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - list checks
|
|
|
|
-----------------------------------------------
|
|
|
|
qa_block.get_checks_list = function()
|
2016-11-05 04:57:45 +01:00
|
|
|
local files
|
2016-10-24 23:43:44 +02:00
|
|
|
local out = {}
|
2016-11-05 04:57:45 +01:00
|
|
|
files = minetest.get_dir_list(filepath, false)
|
|
|
|
for f=1, #files do
|
|
|
|
local filename = files[f]
|
|
|
|
local outname, _ext = filename:match("(.*)(.lua)$")
|
|
|
|
table.insert(out, outname)
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
table.sort(out,function(a,b) return a<b end)
|
|
|
|
return out
|
|
|
|
end
|
|
|
|
|
2016-09-13 00:49:18 +02:00
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - redefine print - reroute output to chat window
|
|
|
|
-----------------------------------------------
|
2016-11-05 01:08:01 +01:00
|
|
|
|
2016-10-19 08:31:19 +02:00
|
|
|
if print_to_chat then
|
2016-11-05 01:08:01 +01:00
|
|
|
local old_print = print
|
2016-10-19 08:31:19 +02:00
|
|
|
print = function(...)
|
|
|
|
local outsting = ""
|
|
|
|
local out
|
|
|
|
local x
|
|
|
|
for x, out in ipairs(arg) do
|
|
|
|
outsting = (outsting..tostring(out)..'\t')
|
|
|
|
end
|
|
|
|
old_print(outsting)
|
|
|
|
minetest.chat_send_all(outsting)
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 00:49:18 +02:00
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - execute a module
|
|
|
|
-----------------------------------------------
|
2016-11-06 01:38:44 +01:00
|
|
|
qa_block.do_module = function(check)
|
2016-11-05 18:27:46 +01:00
|
|
|
print("QA checks started.")
|
2016-11-06 01:38:44 +01:00
|
|
|
local file = filepath..check..".lua"
|
2016-09-13 00:49:18 +02:00
|
|
|
|
|
|
|
local f=io.open(file,"r")
|
|
|
|
if not f then
|
2016-11-05 18:27:46 +01:00
|
|
|
print("Error: File “"..file.."” not found.")
|
2016-09-13 00:49:18 +02:00
|
|
|
else
|
|
|
|
io.close(f)
|
|
|
|
local compiled
|
|
|
|
local executed
|
|
|
|
local err
|
|
|
|
local compiled, err = loadfile(file)
|
|
|
|
if not compiled then
|
2016-11-05 18:27:46 +01:00
|
|
|
print("Syntax error in file “"..file.."”")
|
2016-09-13 14:14:32 +02:00
|
|
|
print(err)
|
2016-09-13 00:49:18 +02:00
|
|
|
else
|
|
|
|
executed, err = pcall(compiled)
|
|
|
|
if not executed then
|
2016-11-05 18:27:46 +01:00
|
|
|
print("Runtime error in QA Block check module!")
|
2016-09-13 14:14:32 +02:00
|
|
|
print(err)
|
2016-09-13 00:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-05 18:27:46 +01:00
|
|
|
print("QA checks finished.")
|
2016-09-09 22:49:51 +02:00
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
2016-10-19 08:31:19 +02:00
|
|
|
|
2016-11-06 01:38:44 +01:00
|
|
|
|
|
|
|
function qa_block.get_info(check)
|
|
|
|
local file = filepath..check..".lua"
|
|
|
|
local f=io.open(file,"r")
|
|
|
|
if not f then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
local content = f:read("*all")
|
|
|
|
if not content then
|
|
|
|
return ""
|
|
|
|
else
|
|
|
|
return minetest.formspec_escape(content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
|
|
|
-- Chat command to start checks
|
|
|
|
-----------------------------------------------
|
2016-11-05 20:44:03 +01:00
|
|
|
local command_params, command_description
|
2016-11-05 18:27:46 +01:00
|
|
|
if smartfsmod then
|
|
|
|
command_params = "[<check_module> | ls | sel ]"
|
2016-11-05 18:44:29 +01:00
|
|
|
command_description = "Perform a mod Quality Assurance check. ls = list available check modules; sel = Open form"
|
2016-11-05 18:27:46 +01:00
|
|
|
else
|
|
|
|
command_params = "[<check_module> | ls ]"
|
2016-11-05 18:44:29 +01:00
|
|
|
command_description = "Perform a mod Quality Assurance check. ls = list available check modules"
|
2016-11-05 18:27:46 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_chatcommand("qa", {
|
|
|
|
description = command_description,
|
|
|
|
params = command_params,
|
|
|
|
privs = {server = true},
|
2016-09-13 00:49:18 +02:00
|
|
|
func = function(name, param)
|
2016-10-24 23:43:44 +02:00
|
|
|
if param == "ls" then
|
|
|
|
for idx, file in ipairs(qa_block.get_checks_list()) do
|
|
|
|
print(file)
|
|
|
|
end
|
|
|
|
elseif param == "sel" then
|
|
|
|
if smartfsmod then
|
|
|
|
qa_block.fs:show(name)
|
|
|
|
else
|
|
|
|
print("selection screen not supported without smartfs")
|
|
|
|
end
|
|
|
|
elseif param and param ~= "" then
|
|
|
|
qa_block.do_module(param)
|
|
|
|
else
|
|
|
|
qa_block.do_module(defaultmodule)
|
|
|
|
end
|
|
|
|
return true
|
2016-09-13 00:49:18 +02:00
|
|
|
end
|
2016-09-12 20:59:29 +02:00
|
|
|
})
|
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- Block node definition - with optional smartfs integration
|
|
|
|
-----------------------------------------------
|
2016-09-09 22:49:51 +02:00
|
|
|
minetest.register_node("qa_block:block", {
|
2016-11-05 18:27:46 +01:00
|
|
|
description = "Quality Assurance block",
|
2016-11-04 15:26:48 +01:00
|
|
|
tiles = {"qa_block.png"},
|
2016-11-05 01:08:01 +01:00
|
|
|
groups = {cracky = 3, dig_immediate = 2 },
|
2016-11-04 22:30:37 +01:00
|
|
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
2016-10-24 23:43:44 +02:00
|
|
|
if smartfsmod then
|
|
|
|
qa_block.fs:attach_nodemeta(pos, placer) --(:form, nodepos, params, placer)
|
|
|
|
else --not a smartfs mod selection dialog. Just run the default one
|
|
|
|
qa_block.do_module(defaultmodule)
|
2016-11-04 22:30:37 +01:00
|
|
|
minetest:remove_node(pos)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
if smartfsmod then
|
|
|
|
smartfs.nodemeta_on_receive_fields(pos, formname, fields, sender)
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
2016-10-19 08:31:19 +02:00
|
|
|
end
|
2016-11-04 22:30:37 +01:00
|
|
|
})
|