add save and load to file
This commit is contained in:
parent
c1a3ca6bb8
commit
7ae6f135fa
21
main.lua
21
main.lua
@ -33,19 +33,14 @@ end
|
|||||||
local function main()
|
local function main()
|
||||||
local main_view = require("views.main")
|
local main_view = require("views.main")
|
||||||
|
|
||||||
local bundles = {
|
local save_file = "/storage-config.txt"
|
||||||
green = {
|
if fs.exists(save_file) then
|
||||||
["minecraft:kelp"] = 64,
|
main_view:load_from_file(save_file)
|
||||||
["minecraft:grass_block"] = 64
|
else
|
||||||
},
|
local inventories = list_inventories()
|
||||||
terraform = {
|
main_view:prepare(inventories, {}, "minecraft:barrel_4")
|
||||||
["minecraft:grass_block"] = 64,
|
end
|
||||||
["minecraft:stone"] = 64,
|
main_view.save_file = save_file
|
||||||
["#green"] = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
local inventories = list_inventories()
|
|
||||||
main_view:prepare(inventories, bundles, "minecraft:barrel_4")
|
|
||||||
|
|
||||||
local update_interval = 0.1
|
local update_interval = 0.1
|
||||||
local update_timer = os.startTimer(update_interval)
|
local update_timer = os.startTimer(update_interval)
|
||||||
|
@ -296,6 +296,29 @@ function main_view:prepare(inventories, bundles, result_inventory)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function main_view:save_to_file(filename)
|
||||||
|
local f, err = io.open(filename, "w")
|
||||||
|
if not f then return nil, err end
|
||||||
|
|
||||||
|
f:write(textutils.serialise{
|
||||||
|
inventories = self.inventories,
|
||||||
|
bundles = self.bundles,
|
||||||
|
result_inventory = self.result_inventory
|
||||||
|
})
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
function main_view:load_from_file(filename)
|
||||||
|
local f, err = io.open(filename, "r")
|
||||||
|
if not f then return nil, err end
|
||||||
|
|
||||||
|
local data = textutils.unserialise(f:read("a"))
|
||||||
|
|
||||||
|
main_view:prepare(data.inventories, data.bundles, data.result_inventory)
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -589,6 +612,10 @@ function main_view:save_bundle(name, items, bundles)
|
|||||||
self.left_store.bundles = derive_available_bundles(self.left_store.items, self.bundle_details)
|
self.left_store.bundles = derive_available_bundles(self.left_store.items, self.bundle_details)
|
||||||
self:refresh_filtered_names(self.left_store, self.left_area)
|
self:refresh_filtered_names(self.left_store, self.left_area)
|
||||||
|
|
||||||
|
if self.save_file then
|
||||||
|
self:save_to_file(self.save_file)
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user