corrections for pick up computers with cached OS

This commit is contained in:
Alexander Weber 2018-03-22 20:25:51 +01:00
parent 76c5e6b2d4
commit 3d5ea888c3
2 changed files with 32 additions and 15 deletions

View File

@ -21,8 +21,8 @@ function bdev:get_ram_disk()
end
function bdev:free_ram_disk()
self.os.meta:set_string('laptop_ram','')
self.ram_disk = nil
self.ram_disk = {}
self:sync()
end
@ -47,7 +47,7 @@ function bdev:get_removable_disk(removable_type)
function data:reload(stack)
-- self.inv unchanged
-- self.rtype unchanged (assumption
stack = stack or data.inv:get_stack("main", 1)
stack = stack or self.inv:get_stack("main", 1)
if stack then
local def = stack:get_definition()
if def and def.name ~= "" then

View File

@ -16,10 +16,6 @@ local function on_construct(pos)
end
end
local function after_destruct(pos, oldnode)
laptop.mtos_cache:free(pos)
end
local function on_punch(pos, node, puncher)
local mtos = laptop.os_get(pos)
@ -104,6 +100,7 @@ local function on_metadata_inventory_take(pos, listname, index, stack, player)
local mtos = laptop.os_get(pos)
mtos:pass_to_app("on_metadata_inventory_take", true, player, listname, index, stack)
end
local function on_timer(pos, elapsed)
local mtos = laptop.os_get(pos)
return mtos:pass_to_app("on_timer", true, nil, elapsed)
@ -111,15 +108,13 @@ end
local function after_place_node(pos, placer, itemstack, pointed_thing)
local save = minetest.deserialize(itemstack:get_meta():get_string("laptop_metadata"))
laptop.mtos_cache:free(pos)
if save then
local meta = minetest.get_meta(pos)
meta:from_table({fields = save.fields})
if save.invlist.main then
for invname, inv in pairs(save.invlist) do
meta:get_inventory():set_list(invname, inv)
end
else -- compatibility to prev. version
meta:get_inventory():set_list("main", save.invlist)
for invname, inv in pairs(save.invlist) do
meta:get_inventory():set_list(invname, inv)
end
end
itemstack:clear()
@ -128,6 +123,30 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
--local function preserve_metadata(pos, oldnode, oldmetadata, drops) --TODO: if MT-0.5 stable
local save = { fields = oldmetadata.fields, invlist = {} }
local cached_mtos = laptop.mtos_cache:get(pos)
if cached_mtos then
-- Workaround, handle sync without nodemeta access
local bdev = cached_mtos.bdev
save.fields.laptop_ram = minetest.serialize(bdev.ram_disk)
save.fields.laptop_appdata = minetest.serialize(bdev.hard_disk)
if bdev.removable_disk then
local stack = bdev.removable_disk.stack
if stack then
local stackmeta = stack:get_meta()
if bdev.removable_disk.def and bdev.removable_disk.label ~= bdev.removable_disk.def.description then
stackmeta:set_string("description", bdev.removable_disk.label)
end
if bdev.removable_disk.storage then
stackmeta:set_string("os_storage", minetest.serialize(bdev.removable_disk.storage))
end
end
oldmetadata.inventory.main = oldmetadata.inventory.main or {}
oldmetadata.inventory.main[1] = stack
end
laptop.mtos_cache:free(pos)
end
if oldmetadata.inventory then
for invname, inv in pairs(oldmetadata.inventory) do
local invsave = {}
@ -137,7 +156,6 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
end
end
end
local item_name = minetest.registered_items[oldnode.name].drop or oldnode.name
local inventory = digger:get_inventory()
local in_inv
@ -192,7 +210,6 @@ function laptop.register_hardware(name, hwdef)
-- def.preserve_metadata = preserve_metadata TODO: if MT-0.5 stable
def.on_punch = on_punch
def.on_construct = on_construct
def.after_destruct = after_destruct
def.on_receive_fields = on_receive_fields
def.allow_metadata_inventory_move = allow_metadata_inventory_move
def.allow_metadata_inventory_put = allow_metadata_inventory_put