added optional support for smartfs forms and more enhancements

This commit is contained in:
Alexander Weber 2016-10-24 23:43:44 +02:00
parent 931953b5b6
commit ebe2cb8184
8 changed files with 175 additions and 38 deletions

37
README.md Normal file
View File

@ -0,0 +1,37 @@
QA Block to check working together overlaps of mods
=======
License GPL-V3: https://www.gnu.org/licenses/gpl-3.0.html
This is a developer helper mod, allow run any lua code for testing reason. The mod can list and run lua-scripts placed in checks subfolder. some check scrips provided.
# Features
list files on DOS and *NIX OS
redirection of print() output to minetest chat. (can be disabled by changing code line "print_to_chat"
robust call of the scripts trough "pcall" does not crash the game in case of syntax- or runtime errors
run scripts using chat command or the QA-Block node
#Dependencies
default - some default tiles and sounds used on block from default
smartfs - optional, enable GUI for check selection (latest version from my fork https://github.com/bell07/minetest-smartfs till the push request is accepted)
#Available check modules
same_recipe - check installed items for similar recipe
list_spawning_mobs - just list mobs.spawning_mobs variable
own modules can be placed
#How to use:
add the mod to the game you like to test
## Using chat command /qa_block
qa_block ls - list all available check modules
qa_block sel - display and run check using the selection dialog (smartfs only)
qa_block checkname - run check
## Using the block
1. get the QA-Block from creative inventory
2. place the block somewhere
3a - without smartfs - wait till the block disappears
3b - with smartfs - start the check using selection dialog
In all cases - check the debug.txt for test results

View File

@ -1,13 +0,0 @@
QA Block to check working together overlaps of mods
License GPL-V3: https://www.gnu.org/licenses/gpl-3.0.html
Available modules
same_recipe - check installed items for similar recipe
How to use:
1. add the mod to the game you like to test
2. start the game in creative. You should find the QA-Block in inventury
3. place the block somewhere
4. wait till the block disappears
5. look to the debug.txt for test results

View File

@ -0,0 +1,3 @@
for name, def in pairs(mobs.spawning_mobs) do
print(name)
end

View File

@ -1 +1,2 @@
default
smartfs?

116
init.lua
View File

@ -1,13 +1,52 @@
print("initialize Starting QA Block")
-- settings
-----------------------------------------------
-- Some hardcoded settings and constants
-----------------------------------------------
local defaultmodule = "same_recipe"
local print_to_chat = true
-- constants
local filepath = minetest.get_modpath("qa_block").."/checks/"
local modpath = minetest.get_modpath("qa_block")
local filepath = modpath.."/checks/"
-- redefine print, copy all output to chat
-----------------------------------------------
-- Load external libs and other files
-----------------------------------------------
qa_block = {} -- needed as envroot in tools
local thismodpath = minetest.get_modpath(minetest.get_current_modname())
local smartfsmod = minetest.get_modpath("smartfs")
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()
local ls
local out = {}
if os.getenv('HOME')~=nil then
ls = io.popen('ls -a "'..thismodpath..'/checks/"') -- linux/mac native "ls -a"
else
ls = io.popen('dir "'..thismodpath..'\\checks\\*.*" /b') --windows native "dir /b"
end
for filename in ls:lines() do
if filename ~= "." and filename ~= ".." then
local outname, _ext = filename:match("(.*)(.lua)$")
table.insert(out, outname)
end
end
table.sort(out,function(a,b) return a<b end)
return out
end
-----------------------------------------------
-- QA-Block functionality - redefine print - reroute output to chat window
-----------------------------------------------
if print_to_chat then
old_print = print
print = function(...)
@ -22,10 +61,12 @@ if print_to_chat then
end
end
-- execute a module
local function do_module( module )
-----------------------------------------------
-- QA-Block functionality - execute a module
-----------------------------------------------
qa_block.do_module = function(module)
print("QA checks started")
--- TODO: some selectoin of executed check
local file = filepath..module..".lua"
local f=io.open(file,"r")
@ -49,35 +90,62 @@ local function do_module( module )
end
end
print("QA checks finished")
end
-----------------------------------------------
-- Chat command to start checks
-----------------------------------------------
minetest.register_chatcommand("qa_block", {
params = "<checkmodule>",
description = "Perform qa block check",
privs = {interact = true},
func = function(name, param)
if param and param ~= "" then
do_module(param)
else
do_module(defaultmodule)
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
end
return true, "QA checks finished."
end,
})
-----------------------------------------------
-- Block node definition - with optional smartfs integration
-----------------------------------------------
minetest.register_node("qa_block:block", {
description = "Check mods quality starter block",
tiles = {"default_dirt.png","default_stone.png","default_sand.png"},
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults()
tiles = {"default_dirt.png","default_stone.png","default_sand.png"},
groups = {cracky = 3},
sounds = default.node_sound_stone_defaults(),
on_receive_fields = function(pos, formname, fields, sender)
if smartfsmod then
smartfs.nodemeta_on_receive_fields(pos, formname, fields, sender)
end
end
})
minetest.register_on_placenode(function (pos, node)
if node.name == "qa_block:block" then
--- TODO: some selectoin of executed check
do_module(defaultmodule)
minetest.env:add_node(pos, {name="air"})
-----------------------------------------------
-- Block node - start execution trough block placing
-----------------------------------------------
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
if newnode.name == "qa_block:block" then
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)
minetest.env:remove_node(pos)
end
end
end)

View File

@ -1,2 +1 @@
name = qa_block

View File

@ -14,6 +14,7 @@ else
envroot = _G[currentmod]
end
-- framework stuff done. -- Now the tool
----------------------------------------
envroot.modutils = {}

41
smartfs_forms.lua Normal file
View File

@ -0,0 +1,41 @@
-- the smartfs.lua is loaded
qa_block.fs = smartfs.create("qa_block:block", function(state)
state:size(10,7)
state:label(0,0,"header","Please select a qa check and run by doble-click or Run button")
if state.location.type == "nodemeta" then
state:label(0,0.5,"header2", "nodemeta: ".. minetest.pos_to_string(state.location.pos))
else
state:label(0,0.5,"header2", state.location.type..": "..state.location.player:get_player_name())
end
-- Listbox
local listbox = state:listbox(0,1,10,5.5,"fileslist")
for idx, file in ipairs(qa_block.get_checks_list()) do
listbox:addItem(file)
end
listbox:setSelected(state:getparam("check_selected")) --persist selected item
listbox:onClick(function(self, state, index)
state:setparam("check_selected", index)
end)
listbox:onDoubleClick(function(self,state, index)
state:setparam("check_selected", index)
qa_block.do_module(self:getItem(index))
end)
-- Run Button
local runbutton = state:button(1,6.5,2,0.5,"Run","Run")
runbutton:onClick(function(self)
local check = listbox:getSelectedItem()
if check then
qa_block.do_module(check)
else
print("no check selected")
end
end)
state:button(5,6.5,2,0.5,"Cancel","Cancel", true)
return true
end)