From 93ce219eec7a68de4e88f135325804ec51133918 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 31 Jan 2022 18:59:17 +0100 Subject: [PATCH] Add pack lib --- basis/pack_lib.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 1 + 2 files changed, 63 insertions(+) create mode 100644 basis/pack_lib.lua diff --git a/basis/pack_lib.lua b/basis/pack_lib.lua new file mode 100644 index 0000000..fdf274c --- /dev/null +++ b/basis/pack_lib.lua @@ -0,0 +1,62 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2022 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + Packing functions + +]]-- + +-- for lazy programmers +local P = minetest.string_to_pos +local M = minetest.get_meta + +--function techage.pack_nvm(pos) +-- return minetest.serialize(techage.) +--end + +--function techage.unpack_nvm(pos) +--end + +local function serialize_inventory(tbl) + local out1 = {} + for k,v in pairs(tbl) do + local out2 = {} + for i,item in ipairs(v) do + out2[i] = item:to_string() + end + out1[k] = minetest.serialize(out2) + end + return out1 +end + +function techage.pack_meta(pos) + local tbl = M(pos):to_table() + local fields, inventory + + if tbl and tbl.fields then + fields = minetest.serialize(tbl.fields) + end + + local inv = minetest.get_inventory({type="node", pos=pos}) + local lists = inv:get_lists() + print(dump(lists)) + if lists then + inventory = serialize_inventory(lists) + end + return minetest.serialize({fields = fields, inventory = inventory}) +end + +--function techage.unpack_meta(pos, s) +-- local tbl = minetest.deserialize(s or "") or {} +-- local out = {} +-- for i,item in ipairs(tbl) do +-- out[i] = ItemStack(item) +-- end +-- local inv = minetest.get_inventory({type="node", pos=pos}) +--end \ No newline at end of file diff --git a/init.lua b/init.lua index 7674ca0..fb90c15 100644 --- a/init.lua +++ b/init.lua @@ -104,6 +104,7 @@ dofile(MP.."/basis/submenu.lua") dofile(MP.."/basis/shared_inv.lua") dofile(MP.."/basis/shared_tank.lua") dofile(MP.."/basis/teleport.lua") +dofile(MP.."/basis/pack_lib.lua") -- Main doc dofile(MP.."/doc/manual_DE.lua")