aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <wuzzy2@mail.ru>2021-03-16 17:37:24 +0000
committerGitHub <noreply@github.com>2021-03-16 18:37:24 +0100
commit91135381421f646e0f6a8d9201b5cdc7e42605e1 (patch)
treec208de82e645da4564c533fad3ce46a5f0343acf
parent88f514ad7a849eb4a67b5ee2c41c93856cf3808f (diff)
downloadminetest-91135381421f646e0f6a8d9201b5cdc7e42605e1.tar.gz
minetest-91135381421f646e0f6a8d9201b5cdc7e42605e1.tar.bz2
minetest-91135381421f646e0f6a8d9201b5cdc7e42605e1.zip
DevTest: Formspec tests, children getter, better lighttool (#10918)
-rw-r--r--games/devtest/mods/testformspec/formspec.lua37
-rw-r--r--games/devtest/mods/testtools/README.md21
-rw-r--r--games/devtest/mods/testtools/init.lua196
-rw-r--r--games/devtest/mods/testtools/light.lua31
-rw-r--r--games/devtest/mods/testtools/textures/testtools_children_getter.pngbin0 -> 281 bytes
-rw-r--r--games/devtest/mods/testtools/textures/testtools_node_meta_editor.pngbin0 -> 135 bytes
6 files changed, 253 insertions, 32 deletions
diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua
index 2a2bdad60..501b5e354 100644
--- a/games/devtest/mods/testformspec/formspec.lua
+++ b/games/devtest/mods/testformspec/formspec.lua
@@ -362,20 +362,51 @@ Number]
animated_image[5.5,0.5;5,2;;testformspec_animation.png;4;100]
animated_image[5.5,2.75;5,2;;testformspec_animation.jpg;4;100]
+ ]],
+
+ -- Model
+ [[
+ formspec_version[3]
+ size[12,13]
style[m1;bgcolor=black]
- model[0.5,6;4,4;m1;testformspec_character.b3d;testformspec_character.png]
- model[5,6;4,4;m2;testformspec_chest.obj;default_chest_top.png,default_chest_top.png,default_chest_side.png,default_chest_side.png,default_chest_front.png,default_chest_inside.png;30,1;true;true]
+ style[m2;bgcolor=black]
+ label[5,1;all defaults]
+ label[5,5.1;angle = 0, 180
+continuous = false
+mouse control = false
+frame loop range = 0,30]
+ label[5,9.2;continuous = true
+mouse control = true]
+ model[0.5,0.1;4,4;m1;testformspec_character.b3d;testformspec_character.png]
+ model[0.5,4.2;4,4;m2;testformspec_character.b3d;testformspec_character.png;0,180;false;false;0,30]
+ model[0.5,8.3;4,4;m3;testformspec_chest.obj;default_chest_top.png,default_chest_top.png,default_chest_side.png,default_chest_side.png,default_chest_front.png,default_chest_inside.png;30,1;true;true]
]],
-- Scroll containers
"formspec_version[3]size[12,13]" ..
scroll_fs,
+
+ -- Sound
+ [[
+ formspec_version[3]
+ size[12,13]
+ style[snd_btn;sound=soundstuff_mono]
+ style[snd_ibtn;sound=soundstuff_mono]
+ style[snd_drp;sound=soundstuff_mono]
+ style[snd_chk;sound=soundstuff_mono]
+ style[snd_tab;sound=soundstuff_mono]
+ button[0.5,0.5;2,1;snd_btn;Sound]
+ image_button[0.5,2;2,1;testformspec_item.png;snd_ibtn;Sound]
+ dropdown[0.5,4;4;snd_drp;Sound,Two,Three;]
+ checkbox[0.5,5.5.5;snd_chk;Sound;]
+ tabheader[0.5,7;8,0.65;snd_tab;Soundtab1,Soundtab2,Soundtab3;1;false;false]
+ ]],
}
local function show_test_formspec(pname, page_id)
page_id = page_id or 2
- local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,ScrollC;" .. page_id .. ";false;false]"
+ local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Invs,Anim,Model,ScrollC,Sound;" .. page_id .. ";false;false]"
minetest.show_formspec(pname, "testformspec:formspec", fs)
end
diff --git a/games/devtest/mods/testtools/README.md b/games/devtest/mods/testtools/README.md
index 9cfe29ea4..a1eb95ed7 100644
--- a/games/devtest/mods/testtools/README.md
+++ b/games/devtest/mods/testtools/README.md
@@ -33,6 +33,13 @@ Usage:
* Punch node: Make it fall
* Place: Try to teleport up to 2 units upwards, then make it fall
+## Node Meta Editor
+Edit and view metadata of nodes.
+
+Usage:
+
+* Punch: Open node metadata editor
+
## Entity Rotator
Changes the entity rotation (with `set_rotation`).
@@ -90,6 +97,13 @@ Usage:
* Place: Increase move distance
* Sneak+place: Decrease move distance
+## Children Getter
+Shows list of objects that are attached to an object (aka "children") in chat.
+
+Usage:
+* Punch object: Show children of punched object
+* Punch air: Show your own children
+
## Entity Visual Scaler
Change visual size of entities
@@ -97,3 +111,10 @@ Usage:
* Punch entity to increase visual size
* Sneak+punch entity to decrease visual size
+
+## Light Tool
+Show light level of node.
+
+Usage:
+* Punch: Show light info of node in front of the punched node's side
+* Place: Show light info of the node that you touched
diff --git a/games/devtest/mods/testtools/init.lua b/games/devtest/mods/testtools/init.lua
index d578b264a..1041acdeb 100644
--- a/games/devtest/mods/testtools/init.lua
+++ b/games/devtest/mods/testtools/init.lua
@@ -3,8 +3,6 @@ local F = minetest.formspec_escape
dofile(minetest.get_modpath("testtools") .. "/light.lua")
--- TODO: Add a Node Metadata tool
-
minetest.register_tool("testtools:param2tool", {
description = S("Param2 Tool") .."\n"..
S("Modify param2 value of nodes") .."\n"..
@@ -111,25 +109,6 @@ minetest.register_tool("testtools:node_setter", {
end,
})
-minetest.register_on_player_receive_fields(function(player, formname, fields)
- if formname == "testtools:node_setter" then
- local playername = player:get_player_name()
- local witem = player:get_wielded_item()
- if witem:get_name() == "testtools:node_setter" then
- if fields.nodename and fields.param2 then
- local param2 = tonumber(fields.param2)
- if not param2 then
- return
- end
- local meta = witem:get_meta()
- meta:set_string("node", fields.nodename)
- meta:set_int("node_param2", param2)
- player:set_wielded_item(witem)
- end
- end
- end
-end)
-
minetest.register_tool("testtools:remover", {
description = S("Remover") .."\n"..
S("Punch: Remove pointed node or object"),
@@ -634,6 +613,54 @@ minetest.register_tool("testtools:object_attacher", {
end,
})
+local function print_object(obj)
+ if obj:is_player() then
+ return "player '"..obj:get_player_name().."'"
+ elseif obj:get_luaentity() then
+ return "LuaEntity '"..obj:get_luaentity().name.."'"
+ else
+ return "object"
+ end
+end
+
+minetest.register_tool("testtools:children_getter", {
+ description = S("Children Getter") .."\n"..
+ S("Shows list of objects attached to object") .."\n"..
+ S("Punch object to show its 'children'") .."\n"..
+ S("Punch air to show your own 'children'"),
+ inventory_image = "testtools_children_getter.png",
+ groups = { testtool = 1, disable_repair = 1 },
+ on_use = function(itemstack, user, pointed_thing)
+ if user and user:is_player() then
+ local name = user:get_player_name()
+ local selected_object
+ local self_name
+ if pointed_thing.type == "object" then
+ selected_object = pointed_thing.ref
+ elseif pointed_thing.type == "nothing" then
+ selected_object = user
+ else
+ return
+ end
+ self_name = print_object(selected_object)
+ local children = selected_object:get_children()
+ local ret = ""
+ for c=1, #children do
+ ret = ret .. "* " .. print_object(children[c])
+ if c < #children then
+ ret = ret .. "\n"
+ end
+ end
+ if ret == "" then
+ ret = S("No children attached to @1.", self_name)
+ else
+ ret = S("Children of @1:", self_name) .. "\n" .. ret
+ end
+ minetest.chat_send_player(user:get_player_name(), ret)
+ end
+ end,
+})
+
-- Use loadstring to parse param as a Lua value
local function use_loadstring(param, player)
-- For security reasons, require 'server' priv, just in case
@@ -666,6 +693,68 @@ local function use_loadstring(param, player)
return true, errOrResult
end
+-- Node Meta Editor
+local node_meta_posses = {}
+local node_meta_latest_keylist = {}
+
+local function show_node_meta_formspec(user, pos, key, value, keylist)
+ local textlist
+ if keylist then
+ textlist = "textlist[0,0.5;2.5,6.5;keylist;"..keylist.."]"
+ else
+ textlist = ""
+ end
+ minetest.show_formspec(user:get_player_name(),
+ "testtools:node_meta_editor",
+ "size[15,9]"..
+ "label[0,0;"..F(S("Current keys:")).."]"..
+ textlist..
+ "field[3,0.5;12,1;key;"..F(S("Key"))..";"..F(key).."]"..
+ "textarea[3,1.5;12,6;value;"..F(S("Value (use empty value to delete key)"))..";"..F(value).."]"..
+ "button[0,8;3,1;get;"..F(S("Get value")).."]"..
+ "button[4,8;3,1;set;"..F(S("Set value")).."]"..
+ "label[0,7.2;"..F(S("pos = @1", minetest.pos_to_string(pos))).."]")
+end
+
+local function get_node_meta_keylist(meta, playername, escaped)
+ local keys = {}
+ local ekeys = {}
+ local mtable = meta:to_table()
+ for k,_ in pairs(mtable.fields) do
+ table.insert(keys, k)
+ if escaped then
+ table.insert(ekeys, F(k))
+ else
+ table.insert(ekeys, k)
+ end
+ end
+ if playername then
+ node_meta_latest_keylist[playername] = keys
+ end
+ return table.concat(ekeys, ",")
+end
+
+minetest.register_tool("testtools:node_meta_editor", {
+ description = S("Node Meta Editor") .. "\n" ..
+ S("Place: Edit node metadata"),
+ inventory_image = "testtools_node_meta_editor.png",
+ groups = { testtool = 1, disable_repair = 1 },
+ on_place = function(itemstack, user, pointed_thing)
+ if pointed_thing.type ~= "node" then
+ return itemstack
+ end
+ if not user:is_player() then
+ return itemstack
+ end
+ local pos = pointed_thing.under
+ node_meta_posses[user:get_player_name()] = pos
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ show_node_meta_formspec(user, pos, "", "", get_node_meta_keylist(meta, user:get_player_name(), true))
+ return itemstack
+ end,
+})
+
minetest.register_on_player_receive_fields(function(player, formname, fields)
if not (player and player:is_player()) then
return
@@ -728,5 +817,70 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
editor_formspec(name, selected_objects[name], prop_to_string(props[key]), sel)
return
end
+ elseif formname == "testtools:node_setter" then
+ local playername = player:get_player_name()
+ local witem = player:get_wielded_item()
+ if witem:get_name() == "testtools:node_setter" then
+ if fields.nodename and fields.param2 then
+ local param2 = tonumber(fields.param2)
+ if not param2 then
+ return
+ end
+ local meta = witem:get_meta()
+ meta:set_string("node", fields.nodename)
+ meta:set_int("node_param2", param2)
+ player:set_wielded_item(witem)
+ end
+ end
+ elseif formname == "testtools:node_meta_editor" then
+ local name = player:get_player_name()
+ local pos = node_meta_posses[name]
+ if fields.keylist then
+ local evnt = minetest.explode_textlist_event(fields.keylist)
+ if evnt.type == "DCL" or evnt.type == "CHG" then
+ local keylist_table = node_meta_latest_keylist[name]
+ if not pos then
+ return
+ end
+ local meta = minetest.get_meta(pos)
+ if not keylist_table then
+ return
+ end
+ if #keylist_table == 0 then
+ return
+ end
+ local key = keylist_table[evnt.index]
+ local value = meta:get_string(key)
+ local keylist_escaped = {}
+ for k,v in pairs(keylist_table) do
+ keylist_escaped[k] = F(v)
+ end
+ local keylist = table.concat(keylist_escaped, ",")
+ show_node_meta_formspec(player, pos, key, value, keylist)
+ return
+ end
+ elseif fields.key and fields.key ~= "" and fields.value then
+ if not pos then
+ return
+ end
+ local meta = minetest.get_meta(pos)
+ if fields.get then
+ local value = meta:get_string(fields.key)
+ show_node_meta_formspec(player, pos, fields.key, value,
+ get_node_meta_keylist(meta, name, true))
+ return
+ elseif fields.set then
+ meta:set_string(fields.key, fields.value)
+ show_node_meta_formspec(player, pos, fields.key, fields.value,
+ get_node_meta_keylist(meta, name, true))
+ return
+ end
+ end
end
end)
+
+minetest.register_on_leaveplayer(function(player)
+ local name = player:get_player_name()
+ node_meta_latest_keylist[name] = nil
+ node_meta_posses[name] = nil
+end)
diff --git a/games/devtest/mods/testtools/light.lua b/games/devtest/mods/testtools/light.lua
index a9458ca6b..afca9a489 100644
--- a/games/devtest/mods/testtools/light.lua
+++ b/games/devtest/mods/testtools/light.lua
@@ -1,22 +1,37 @@
local S = minetest.get_translator("testtools")
-minetest.register_tool("testtools:lighttool", {
- description = S("Light tool"),
- inventory_image = "testtools_lighttool.png",
- groups = { testtool = 1, disable_repair = 1 },
- on_use = function(itemstack, user, pointed_thing)
- local pos = pointed_thing.above
+local function get_func(is_place)
+ return function(itemstack, user, pointed_thing)
+ local pos
+ if is_place then
+ pos = pointed_thing.under
+ else
+ pos = pointed_thing.above
+ end
if pointed_thing.type ~= "node" or not pos then
return
end
local node = minetest.get_node(pos)
+ local pstr = minetest.pos_to_string(pos)
local time = minetest.get_timeofday()
local sunlight = minetest.get_natural_light(pos)
local artificial = minetest.get_artificial_light(node.param1)
- local message = ("param1 0x%02x | time %.5f | sunlight %d | artificial %d")
- :format(node.param1, time, sunlight, artificial)
+ local message = ("pos=%s | param1=0x%02x | " ..
+ "sunlight=%d | artificial=%d | timeofday=%.5f" )
+ :format(pstr, node.param1, sunlight, artificial, time)
minetest.chat_send_player(user:get_player_name(), message)
end
+end
+
+minetest.register_tool("testtools:lighttool", {
+ description = S("Light Tool") .. "\n" ..
+ S("Show light values of node") .. "\n" ..
+ S("Punch: Light of node above touched node") .. "\n" ..
+ S("Place: Light of touched node itself"),
+ inventory_image = "testtools_lighttool.png",
+ groups = { testtool = 1, disable_repair = 1 },
+ on_use = get_func(false),
+ on_place = get_func(true),
})
diff --git a/games/devtest/mods/testtools/textures/testtools_children_getter.png b/games/devtest/mods/testtools/textures/testtools_children_getter.png
new file mode 100644
index 000000000..b7fa34025
--- /dev/null
+++ b/games/devtest/mods/testtools/textures/testtools_children_getter.png
Binary files differ
diff --git a/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png b/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png
new file mode 100644
index 000000000..89eafd65c
--- /dev/null
+++ b/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png
Binary files differ