first access to the item

This commit is contained in:
Alexander Weber 2017-12-12 09:16:24 +01:00
parent db5167f5cd
commit 9b5d9c633d
2 changed files with 29 additions and 3 deletions

View File

@ -1,16 +1,18 @@
laptop.register_app("removable", {
app_name = "Removable storage",
app_icon = "laptop_setting_wrench.png",
app_info = "Work with removable media.",
app_info = "Work with removable media",
formspec_func = function(app, mtos)
local inv = mtos:get_node_inventory()
local stack = mtos:get_node_inventory():get_stack("main", 1)
local formspec =
"list[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main;0,0.3;1,1;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main]" ..
"listring[current_player;main]"
if stack then
formspec = formspec .. mtos.theme:get_label('2,0.3', stack:to_string())
end
return formspec
end,
-- check if the item is compatible to the computer

24
os.lua
View File

@ -60,6 +60,16 @@ function os_class:save()
end
self.cloud_store = nil
end
if self.removable_store then
local stack = self:get_node_inventory():get_stack("main", 1)
if stack then
for store, value in pairs(self.removable_store) do
stack:get_meta():set_string(store, minetest.serialize(value))
end
end
self.removable_store = nil
end
end
-- Get given or current theme
@ -154,6 +164,20 @@ function os_class:connect_to_cloud(store_name)
return self.cloud_store[store_name]
end
-- Get item storage as (=floppy/usb)
function os_class:connect_to_removable(store_name)
local stack = self:get_node_inventory():get_stack("main", 1)
if not stack then
self.removable_store = nil
return nil
end
self.removable_store = self.removable_store or {}
self.removable_store[store_name] = self.removable_store[store_name] or
minetest.deserialize(stack:get_meta():get_string(store_name))
return self.removable_store[store_name]
end
-----------------------------------------------------
-- Get Operating system object
-----------------------------------------------------