]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
DevTest: Formspec tests, children getter, better lighttool (#10918)
authorWuzzy <wuzzy2@mail.ru>
Tue, 16 Mar 2021 17:37:24 +0000 (17:37 +0000)
committerGitHub <noreply@github.com>
Tue, 16 Mar 2021 17:37:24 +0000 (18:37 +0100)
games/devtest/mods/testformspec/formspec.lua
games/devtest/mods/testtools/README.md
games/devtest/mods/testtools/init.lua
games/devtest/mods/testtools/light.lua
games/devtest/mods/testtools/textures/testtools_children_getter.png [new file with mode: 0644]
games/devtest/mods/testtools/textures/testtools_node_meta_editor.png [new file with mode: 0644]

index 2a2bdad60995514910a68c768b5e3b7d3c42abb6..501b5e35436a9a75d82b343d56fd615f4f919a62 100644 (file)
@@ -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
index 9cfe29ea44f176d3af2129f9a1c690d4cec42758..a1eb95ed72f3d8eacceeea05ed808a2b508bcfa1 100644 (file)
@@ -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
index d578b264a7d8e4f097da3262993e9e3ff53ac196..1041acdeb5580887df01c18f0990f34bd7445e28 100644 (file)
@@ -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)
index a9458ca6bf5fc7ed54a11f5cd0bb1bc9507bb056..afca9a48985806f37c073930c05b00c6179dd2b6 100644 (file)
@@ -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 (file)
index 0000000..b7fa340
Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_children_getter.png 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 (file)
index 0000000..89eafd6
Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_node_meta_editor.png differ