From e5f7423c7146369c8b47f336d8408c3ebbd636bc Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Tue, 12 May 2015 21:51:18 +0200 Subject: [PATCH] Early implementation of table handler - Added basic feature for tables. Might be removed later - Updated TodoList --- README.md | 5 +++-- init.lua | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67a8d81..b1e57a8 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ stratum. "metatools_stick.png" by Ataron (CC-BY-NC-SA) # Todo - - Add a table handler for meta::set - - Create a better ASCII-art graph at the end of this file... + - Rewrite the table stocking : a variable containing a copy of the global + table returned by :to_table(), on which we would work, and a save command to + apply it on the node # Special thanks - mgl512 (Le_Docteur) for its locked itemframe which gave me the idea of a tool diff --git a/init.lua b/init.lua index c3841f3..52f70c7 100644 --- a/init.lua +++ b/init.lua @@ -130,6 +130,7 @@ minetest.register_chatcommand("meta", { minetest.log("action","[metatools] Player "..name.." opened node "..minetest.get_node(position).name.." at pos "..paramlist[2]) return true + elseif paramlist[1] == "close" then if not meta_info[name] or not meta_info[name]["node"] then minetest.chat_send_player(name,"- meta::close - You have no node open, use /meta open (x,y,z) to open one") @@ -143,6 +144,7 @@ minetest.register_chatcommand("meta", { return true elseif paramlist[1] == "show" then + if not meta_info[name] or not meta_info[name]["node"] then minetest.chat_send_player(name,"- meta::show - You have no node open, use /meta open (x,y,z) to open one") minetest.log("action","[metatools] Player "..name.." failed showing node : no node opened") @@ -378,6 +380,65 @@ minetest.register_chatcommand("meta", { minetest.chat_send_player("- meta::itemstack - Subcommand " .. paramlist[2] .. " unknown. Typ /meta help for help") return false end + + --[[ + Table method. + Should I keep this knowing that tables shouldn't be stocked in metadatas? + ]] + elseif paramlist[1] == "table" then + if not meta_info[name] or not meta_info[name]["node"] then + minetest.chat_send_player(name,"- meta::table - You have no node open, use /meta open (x,y,z) to open one") + minetest.log("action","[metatools] Player "..name.." failed table : no node opened") + return false + end + + if not paramlist[2] then + minetest.chat_send_player(name, "- meta::table - No subcommand given, see /meta help for help in table command") + minetest.log("action","[metatools] Player "..name.." failed table : no subcommand given") + return false + end + + if not (meta_info[name]["stratum"] >= 1 and meta_info[name]["pathname"][meta_info[name]["stratum"]] == "fields") then + minetest.chat_send_player(name,"- meta::table - tables must only exist in metadata fields") + minetest.log("action","[metatools] Player " .. name .. " tried to use table out of metadatas's fields") + return false + end + + if paramlist[2] == "serialize" then + if not paramlist[3] then + minetest.chat_send_player(name,"- meta::table::serialize - Name needed for serialize") + minetest.log("action","[metatools] Player "..name.." asked for serialize without name") + return false + end + + for index,table in pairs(meta_info[name]["pointer"]) do + if index == paramlist[3] and type(table) == "table" then + minetest.chat_send_player(name,"Raw datas : " .. minetest.serialize(table)) + return true + end + end + + minetest.chat_send_player(name,"Table " .. paramlist[3] .. " not found") + minetest.log("action","[metatools] Player " .. name .. " asked for an unknown table") + return false + +--[[ elseif paramlist[2] == "create" then + if not paramlist[3] then + minetest.chat_send_player(name,"- meta::table::create - No name given to create table") + minetest.log("action","[metatools] Player " .. name .. " wanted to create a table without any name") + end + + meta_info[name]["pointer"][paramlist[3]--] = {} + minetest.get_meta(meta_info[name]["node"]):from_table({ + fields = meta_info[name]["pointer"], + inventory = minetest.get_meta(meta_info[name]["node"]):to_table().inventory + }) + + minetest.chat_send_player(name,"- meta::table:create - Empty table created at index " .. paramlist[3]) + minetest.log("action","[metatools] Player " .. name .. " created empty table at index " .. paramlist[3]) + return true]] + end + else minetest.chat_send_player(name,"- meta - Subcommand " .. paramlist[1] .. " not known. Type /meta help for help") return false