2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
|
|
|
-- Some hardcoded settings and constants
|
|
|
|
-----------------------------------------------
|
2016-11-15 21:39:21 +01:00
|
|
|
local defaultmodule = "empty"
|
2016-10-19 08:31:19 +02:00
|
|
|
local print_to_chat = true
|
2016-09-13 00:49:18 +02:00
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
|
|
|
-- Load external libs and other files
|
|
|
|
-----------------------------------------------
|
2016-11-15 21:39:21 +01:00
|
|
|
qa_block = {}
|
2017-03-19 03:43:45 +01:00
|
|
|
qa_block.modpath = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
local filepath = qa_block.modpath.."/checks/"
|
2016-10-24 23:43:44 +02:00
|
|
|
|
2017-01-21 01:17:27 +01:00
|
|
|
--[[ --temporary buildin usage (again)
|
2016-11-15 21:39:21 +01:00
|
|
|
local smartfs_enabled = false
|
|
|
|
if minetest.get_modpath("smartfs") and
|
|
|
|
smartfs.nodemeta_on_receive_fields then -- nodemeta handling implemented, right version.
|
2017-03-19 03:43:45 +01:00
|
|
|
dofile(qa_block.modpath.."/smartfs_forms.lua")
|
2016-11-15 21:39:21 +01:00
|
|
|
smartfs_enabled = true
|
|
|
|
else
|
|
|
|
print("WARNING: qa_block without (compatible) smartfs is limited functionality")
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
2017-01-21 01:17:27 +01:00
|
|
|
]]
|
2017-03-19 03:43:45 +01:00
|
|
|
|
|
|
|
local smartfs = dofile(qa_block.modpath.."/smartfs.lua")
|
2017-01-21 01:17:27 +01:00
|
|
|
qa_block.smartfs = smartfs
|
2017-03-19 03:43:45 +01:00
|
|
|
dofile(qa_block.modpath.."/smartfs_forms.lua")
|
2020-03-03 16:06:59 +01:00
|
|
|
local smartfs_enabled = true
|
2016-10-24 23:43:44 +02:00
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - list checks
|
|
|
|
-----------------------------------------------
|
|
|
|
qa_block.get_checks_list = function()
|
2017-01-02 20:17:14 +01:00
|
|
|
local out = {}
|
|
|
|
local files
|
|
|
|
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
|
2017-01-02 20:17:14 +01:00
|
|
|
table.sort(out,function(a,b) return a<b end)
|
|
|
|
return out
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - redefine print - reroute output to chat window
|
|
|
|
-----------------------------------------------
|
2016-10-19 08:31:19 +02:00
|
|
|
if print_to_chat then
|
2016-12-21 18:01:24 +01:00
|
|
|
local function do_print_redefinition()
|
|
|
|
local old_print = print
|
|
|
|
print = function(...)
|
|
|
|
local outsting = ""
|
|
|
|
local out
|
|
|
|
local x
|
2017-02-20 09:35:38 +01:00
|
|
|
for x, out in ipairs({...}) do
|
2016-12-21 18:01:24 +01:00
|
|
|
outsting = (outsting..tostring(out)..'\t')
|
|
|
|
end
|
|
|
|
old_print(outsting)
|
|
|
|
minetest.chat_send_all(outsting)
|
2016-10-19 08:31:19 +02:00
|
|
|
end
|
|
|
|
end
|
2016-12-21 18:01:24 +01:00
|
|
|
minetest.after(0, do_print_redefinition)
|
2016-10-19 08:31:19 +02:00
|
|
|
end
|
2016-09-13 00:49:18 +02:00
|
|
|
|
2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
2016-11-06 18:10:56 +01:00
|
|
|
-- QA-Block functionality - get the source of a module
|
2016-10-24 23:43:44 +02:00
|
|
|
-----------------------------------------------
|
2016-11-06 18:10:56 +01:00
|
|
|
function qa_block.get_source(check)
|
2017-01-02 20:17:14 +01:00
|
|
|
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 ""
|
2016-11-06 01:38:44 +01:00
|
|
|
else
|
2017-01-02 20:17:14 +01:00
|
|
|
return content
|
2016-11-06 12:31:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - get the source of a module
|
|
|
|
-----------------------------------------------
|
2016-11-15 21:39:21 +01:00
|
|
|
function qa_block.do_source(source, checkname)
|
|
|
|
print("QA check "..checkname.." started.")
|
2016-11-06 12:31:39 +01:00
|
|
|
local compiled
|
|
|
|
local executed
|
|
|
|
local err
|
2017-01-02 20:17:14 +01:00
|
|
|
local compiled, err = loadstring(source)
|
2016-11-06 12:31:39 +01:00
|
|
|
if not compiled then
|
|
|
|
print("Syntax error in QA Block check module")
|
|
|
|
print(err)
|
|
|
|
else
|
2017-01-02 20:17:14 +01:00
|
|
|
executed, err = pcall(compiled)
|
2016-11-06 12:31:39 +01:00
|
|
|
if not executed then
|
|
|
|
print("Runtime error in QA Block check module!")
|
|
|
|
print(err)
|
|
|
|
end
|
2016-11-06 01:38:44 +01:00
|
|
|
end
|
2016-11-15 21:39:21 +01:00
|
|
|
print("QA check "..checkname.." finished.")
|
2016-11-06 01:38:44 +01:00
|
|
|
end
|
|
|
|
|
2016-11-06 18:10:56 +01:00
|
|
|
-----------------------------------------------
|
|
|
|
-- QA-Block functionality - execute a module
|
|
|
|
-----------------------------------------------
|
|
|
|
qa_block.do_module = function(check)
|
|
|
|
local source = qa_block.get_source(check)
|
|
|
|
if source then
|
2016-11-15 21:39:21 +01:00
|
|
|
qa_block.do_source(source, check)
|
2016-11-06 18:10:56 +01:00
|
|
|
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-15 21:39:21 +01:00
|
|
|
if smartfs_enabled then
|
|
|
|
command_params = "[<check_module> | help | ls | set <check_module> | ui ]"
|
|
|
|
command_description = "Perform a mod Quality Assurance check. see /qa help for details"
|
2016-11-05 18:27:46 +01:00
|
|
|
else
|
2016-11-15 21:39:21 +01:00
|
|
|
command_params = "[<check_module> | help | ls | set <check_module> ]"
|
|
|
|
command_description = "Perform a mod Quality Assurance check. see /qa help for details"
|
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-11-15 21:39:21 +01:00
|
|
|
if param == "help" then
|
|
|
|
print([[
|
|
|
|
- /qa help - print available chat commands
|
|
|
|
- /qa ls - list all available check modules
|
|
|
|
- /qa set checkname - set default check
|
|
|
|
- /qa ui - show selection dialog (smartfs only)
|
|
|
|
- /qa checkname - run check
|
|
|
|
- /qa - run default check
|
|
|
|
]])
|
|
|
|
elseif param == "ls" then
|
2016-10-24 23:43:44 +02:00
|
|
|
for idx, file in ipairs(qa_block.get_checks_list()) do
|
|
|
|
print(file)
|
|
|
|
end
|
2016-11-15 21:39:21 +01:00
|
|
|
elseif param == "ui" then
|
|
|
|
if smartfs_enabled then
|
2016-10-24 23:43:44 +02:00
|
|
|
qa_block.fs:show(name)
|
|
|
|
else
|
|
|
|
print("selection screen not supported without smartfs")
|
|
|
|
end
|
2016-11-15 21:39:21 +01:00
|
|
|
elseif string.sub(param, 1, 3) == "set" then
|
|
|
|
local isvalid = false
|
|
|
|
local option = string.sub(param, 5)
|
|
|
|
for idx, file in ipairs(qa_block.get_checks_list()) do
|
|
|
|
if file == option then
|
|
|
|
isvalid = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if isvalid then
|
|
|
|
defaultmodule = option
|
|
|
|
print("check "..tostring(option).." selected")
|
|
|
|
else
|
|
|
|
print("check "..tostring(option).." is not valid")
|
|
|
|
end
|
2016-10-24 23:43:44 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2017-08-01 21:06:35 +02:00
|
|
|
|
|
|
|
local doc_items_longdesc =
|
2017-08-02 06:18:16 +02:00
|
|
|
[[The QA block is a quality assurance tool for mod and subgame developers.
|
|
|
|
By using the block it is possible to:
|
|
|
|
• Browse trough global Lua variables for deeper insight
|
2017-08-02 13:41:49 +02:00
|
|
|
• Edit global Lua variables
|
2017-08-02 06:18:16 +02:00
|
|
|
• Execute ad-hoc Lua code for testing reasons in development
|
|
|
|
• Run predefined checks for quality assurance
|
2017-08-01 21:06:35 +02:00
|
|
|
]]
|
|
|
|
|
|
|
|
local doc_items_usagehelp =
|
2017-08-02 06:18:16 +02:00
|
|
|
[[Place the block and open the formspec using right mouse click.
|
|
|
|
Use the “Globals” tab for browsing trough global Lua variables.
|
2017-08-02 13:41:49 +02:00
|
|
|
Double-Click to entries to navigate into a table, print long function source or edit numeric or string values
|
2017-08-02 06:18:16 +02:00
|
|
|
Use the “Checks” tab to run Lua code. Editing the code before running is allowed.
|
|
|
|
The checks are read from the $MODPATH/checks directory.
|
|
|
|
It is possible to add new Lua files and run them without restarting the game. Just use the Refresh button.
|
|
|
|
Ususally the print() command is used in checks, so look in debug.txt or the Minetest console output.
|
|
|
|
Some chat commands are defined as shortcuts. See “/qa help” for more information.
|
|
|
|
Please note the “/qa ui” cannot store the current globals navigation, the navigation can be stored in the QA block only.
|
2017-08-01 21:06:35 +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-11-15 21:39:21 +01:00
|
|
|
if smartfs_enabled then
|
2017-01-21 01:17:27 +01:00
|
|
|
qa_block.fs:attach_to_node(pos)
|
2016-10-24 23:43:44 +02:00
|
|
|
else --not a smartfs mod selection dialog. Just run the default one
|
|
|
|
qa_block.do_module(defaultmodule)
|
2016-11-15 21:39:21 +01:00
|
|
|
minetest.remove_node(pos)
|
2016-11-04 22:30:37 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
2016-11-15 21:39:21 +01:00
|
|
|
if smartfs_enabled then
|
2016-11-04 22:30:37 +01:00
|
|
|
smartfs.nodemeta_on_receive_fields(pos, formname, fields, sender)
|
2016-10-24 23:43:44 +02:00
|
|
|
end
|
2017-08-01 21:06:35 +02:00
|
|
|
end,
|
|
|
|
_doc_items_longdesc = doc_items_longdesc,
|
|
|
|
_doc_items_usagehelp = doc_items_usagehelp,
|
2016-11-04 22:30:37 +01:00
|
|
|
})
|