Fixed shelves lists saving
This commit is contained in:
parent
d64e8e812e
commit
aa0800a51f
@ -34,11 +34,13 @@ function multidecor.helpers.upper_first_letters(s)
|
||||
return new_s
|
||||
end
|
||||
|
||||
function multidecor.helpers.build_name_from_tmp(name, type, i)
|
||||
local res = name .. "_" .. i .. "_".. type
|
||||
function multidecor.helpers.build_name_from_tmp(name, type, i, pos)
|
||||
local strpos = pos.x .. "_" .. pos.y .. "_" .. pos.z
|
||||
local res = name .. "_" .. i .. "_".. type .. "_" .. strpos
|
||||
|
||||
if not name:match("multidecor:") then
|
||||
res = "multidecor:" .. res
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
@ -129,13 +129,9 @@ function multidecor.shelves.set_shelves(pos)
|
||||
return
|
||||
end
|
||||
|
||||
local dir = def.paramtype2 == "facedir" and minetest.facedir_to_dir(node.param2) or
|
||||
def.paramtype2 == "wallmounted" and minetest.wallmounted_to_dir(node.param2)
|
||||
local rot_y = vector.dir_to_rotation(dir)
|
||||
|
||||
for i, shelf_data in ipairs(def.add_properties.shelves_data) do
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(def.add_properties.shelves_data.common_name, "inv", i)
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(def.add_properties.shelves_data.common_name, "list", i)
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(def.add_properties.shelves_data.common_name, "inv", i, pos)
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(def.add_properties.shelves_data.common_name, "list", i, pos)
|
||||
local list_type = shelf_data.invlist_type or "storage"
|
||||
|
||||
local padding = 0.25
|
||||
@ -209,14 +205,16 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
self.cook_info = data[10]
|
||||
end
|
||||
|
||||
minetest.debug("self.inv_list: " .. dump(self.inv_list))
|
||||
local node = minetest.get_node(self.connected_to.pos)
|
||||
|
||||
if node.name ~= self.connected_to.name then
|
||||
local shelves_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data
|
||||
if not node.name:match(shelves_data.common_name) then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local shelf_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data[self.shelf_data_i]
|
||||
local shelf_data = shelves_data[self.shelf_data_i]
|
||||
local obj_props = {}
|
||||
|
||||
obj_props.visual_size = self.object:get_properties().visual_size
|
||||
@ -238,8 +236,11 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
|
||||
multidecor.shelves.rotate_shelf_bbox(self.object)
|
||||
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data.common_name, "inv", self.shelf_data_i)
|
||||
minetest.create_detached_inventory(inv_name, {
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", self.shelf_data_i, self.connected_to.pos)
|
||||
local inv = minetest.get_inventory({type="detached", name=inv_name})
|
||||
|
||||
if not inv then
|
||||
inv = minetest.create_detached_inventory(inv_name, {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return count
|
||||
end,
|
||||
@ -280,7 +281,7 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
local cook_active_fs = "image[" .. list_x .. ",1;1,1;multidecor_cooker_active_bg.png^[lowpart:%f:multidecor_cooker_active_fs.png]"
|
||||
|
||||
minetest.swap_node(self.connected_to.pos, {
|
||||
name="multidecor:" .. minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data.common_name .. "_activated",
|
||||
name="multidecor:" ..shelves_data.common_name .. "_activated",
|
||||
param2=minetest.get_node(self.connected_to.pos).param2
|
||||
})
|
||||
|
||||
@ -291,7 +292,7 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
end
|
||||
})
|
||||
|
||||
local inv = minetest.get_inventory({type="detached", name=inv_name})
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i, self.connected_to.pos)
|
||||
local inv_list = {}
|
||||
|
||||
for _, stack_t in ipairs(self.inv_list) do
|
||||
@ -302,8 +303,6 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
table.insert(inv_list, stack)
|
||||
end
|
||||
|
||||
local shelves_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i)
|
||||
local list_type = shelf_data.invlist_type or "storage"
|
||||
local invsize = list_type == "storage" and shelf_data.inv_size or {w=1, h=1}
|
||||
inv:set_list(list_name, inv_list)
|
||||
@ -313,6 +312,7 @@ multidecor.shelves.default_on_activate = function(self, staticdata)
|
||||
inv:set_size("main", 32)
|
||||
inv:set_width("main", 8)
|
||||
end
|
||||
end
|
||||
|
||||
multidecor.shelves.default_get_staticdata = function(self)
|
||||
return minetest.serialize({self.inv, self.connected_to, self.dir, self.shelf_data_i, self.inv_list, self.start_v, self.end_v, self.is_flip_x_scale, self.rotate_x, self.cook_info})
|
||||
@ -321,7 +321,7 @@ end
|
||||
multidecor.shelves.default_on_rightclick = function(self, clicker)
|
||||
open_shelves[clicker:get_player_name()] = self.object
|
||||
local shelves_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data
|
||||
minetest.show_formspec(clicker:get_player_name(), multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "fs", self.shelf_data_i), self.inv)
|
||||
minetest.show_formspec(clicker:get_player_name(), multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "fs", self.shelf_data_i, self.connected_to.pos), self.inv)
|
||||
|
||||
if self.dir == 0 then
|
||||
multidecor.shelves.open_shelf(self.object, 1)
|
||||
@ -333,6 +333,7 @@ local function cook_step(self, dtime)
|
||||
if not self.cook_info then
|
||||
return
|
||||
end
|
||||
--minetest.debug("1")
|
||||
self.cook_info[2] = self.cook_info[2] + dtime
|
||||
local elapsed_time = self.cook_info[2]
|
||||
|
||||
@ -341,20 +342,23 @@ local function cook_step(self, dtime)
|
||||
local str_perc = tostring(math.round(percents)) .. " %"
|
||||
self.inv = self.cook_info[4]:sub(1, i-1) .. self.cook_info[6]:format(percents) .. self.cook_info[4]:sub(i) .. self.cook_info[5]:format(str_perc)
|
||||
|
||||
--minetest.debug("2")
|
||||
local meta = minetest.get_meta(self.connected_to.pos)
|
||||
meta:set_string("infotext", "Cooked to: " .. str_perc)
|
||||
|
||||
local shelves_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", self.shelf_data_i)
|
||||
local inv_list = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i)
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", self.shelf_data_i, self.connected_to.pos)
|
||||
local inv_list = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i, self.connected_to.pos)
|
||||
local inv = minetest.get_inventory({type="detached", name=inv_name})
|
||||
|
||||
--minetest.debug("3")
|
||||
local time_elapsed = self.cook_info and self.cook_info[2] >= self.cook_info[3]
|
||||
if inv:is_empty(inv_list) or time_elapsed then
|
||||
if time_elapsed then
|
||||
self.cook_info[1].item:set_count(self.cook_info[7])
|
||||
inv:set_stack(inv_list, 1, self.cook_info[1].item)
|
||||
end
|
||||
--minetest.debug("4")
|
||||
self.inv = self.cook_info[4]
|
||||
self.cook_info = nil
|
||||
meta:set_string("infotext", "")
|
||||
@ -364,6 +368,7 @@ local function cook_step(self, dtime)
|
||||
name="multidecor:" .. shelves_data.common_name,
|
||||
param2=minetest.get_node(self.connected_to.pos).param2
|
||||
})
|
||||
--minetest.debug("5")
|
||||
end
|
||||
|
||||
local show_to
|
||||
@ -375,11 +380,13 @@ local function cook_step(self, dtime)
|
||||
end
|
||||
end
|
||||
|
||||
--minetest.debug("6")
|
||||
local i, f = math.modf(elapsed_time)
|
||||
|
||||
if show_to and (f > 0 and f < 0.05) then
|
||||
minetest.show_formspec(show_to, multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "fs", self.shelf_data_i), self.inv)
|
||||
minetest.show_formspec(show_to, multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "fs", self.shelf_data_i, self.connected_to.pos), self.inv)
|
||||
end
|
||||
--minetest.debug("7")
|
||||
end
|
||||
|
||||
multidecor.shelves.default_drawer_on_step = function(self, dtime)
|
||||
@ -422,25 +429,20 @@ multidecor.shelves.default_door_on_step = function(self, dtime)
|
||||
end
|
||||
|
||||
multidecor.shelves.default_on_receive_fields = function(player, formname, fields)
|
||||
local is_table_inv = formname:find("%d+", -10)
|
||||
local shelf_i = formname:find("%d+")
|
||||
|
||||
if not is_table_inv then
|
||||
minetest.debug("1")
|
||||
if not shelf_i then
|
||||
return
|
||||
end
|
||||
|
||||
local name = formname:sub(1, is_table_inv-2)
|
||||
minetest.debug("formname: " .. formname)
|
||||
minetest.debug("name: " .. name)
|
||||
local name = formname:sub(1, shelf_i-2)
|
||||
local def = minetest.registered_nodes[name]
|
||||
|
||||
if not def then
|
||||
minetest.debug("2")
|
||||
return
|
||||
end
|
||||
|
||||
if not name:sub(1, name:find(":")-1) == "multidecor" then
|
||||
minetest.debug("3")
|
||||
return
|
||||
end
|
||||
|
||||
@ -450,11 +452,12 @@ multidecor.shelves.default_on_receive_fields = function(player, formname, fields
|
||||
|
||||
local self = shelf:get_luaentity()
|
||||
local shelves_data = minetest.registered_nodes[self.connected_to.name].add_properties.shelves_data
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", self.shelf_data_i)
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", self.shelf_data_i, self.connected_to.pos)
|
||||
local inv = minetest.get_inventory({type="detached", name=inv_name})
|
||||
local shelf_data = def.add_properties.shelves_data[self.shelf_data_i]
|
||||
local list = inv:get_list(multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i))
|
||||
local list = inv:get_list(multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", self.shelf_data_i, self.connected_to.pos))
|
||||
minetest.debug("list: " .. dump(list))
|
||||
|
||||
self.inv_list = {}
|
||||
for _, stack in ipairs(list) do
|
||||
table.insert(self.inv_list, {name=stack:get_name(), count=stack:get_count(), wear=stack:get_wear()})
|
||||
end
|
||||
@ -465,12 +468,12 @@ end
|
||||
|
||||
multidecor.shelves.default_can_dig = function(pos)
|
||||
local name = minetest.get_node(pos).name
|
||||
local add_props = minetest.registered_nodes[name].add_properties
|
||||
local shelves_data = minetest.registered_nodes[name].add_properties.shelves_data
|
||||
|
||||
local is_all_empty = true
|
||||
for i, shelf in ipairs(add_props.shelves_data) do
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(add_props.shelves_data.common_name, "inv", i)
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(add_props.shelves_data.common_name, "list", i)
|
||||
for i, shelf in ipairs(shelves_data) do
|
||||
local inv_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "inv", i, pos)
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(shelves_data.common_name, "list", i, pos)
|
||||
local inv = minetest.get_inventory({type="detached", name=inv_name})
|
||||
|
||||
is_all_empty = is_all_empty and inv:is_empty(list_name)
|
||||
|
@ -1,5 +1,5 @@
|
||||
local function get_shelf_formspec(name, pos, w, h)
|
||||
local listname = multidecor.helpers.build_name_from_tmp(name, "list", 1)
|
||||
local listname = multidecor.helpers.build_name_from_tmp(name, "list", 1, pos)
|
||||
return table.concat({
|
||||
"formspec_version[5]",
|
||||
"size[11,9]",
|
||||
@ -15,7 +15,7 @@ local shelf_on_construct = function(pos)
|
||||
meta:set_string("formspec", get_shelf_formspec(name, pos, add_props.inv_size.w, add_props.inv_size.h))
|
||||
|
||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(name, "list", 1)
|
||||
local list_name = multidecor.helpers.build_name_from_tmp(name, "list", 1, pos)
|
||||
inv:set_size(list_name, add_props.inv_size.w*add_props.inv_size.h)
|
||||
inv:set_width(list_name, add_props.inv_size.w)
|
||||
|
||||
@ -26,7 +26,7 @@ end
|
||||
local shelf_can_dig = function(pos)
|
||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
||||
|
||||
return inv:is_empty(multidecor.helpers.build_name_from_tmp(minetest.get_node(pos).name, "list", 1))
|
||||
return inv:is_empty(multidecor.helpers.build_name_from_tmp(minetest.get_node(pos).name, "list", 1, pos))
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user