feat(farming/database): switched to built-in craftos functions

This commit is contained in:
2025-05-15 14:10:27 +02:00
parent b2f6a83074
commit db6c33246e

View File

@@ -13,12 +13,11 @@ local function listenForFieldDataRequests()
while true do
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
if (incomingChannel == fieldDataChannel) then
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
local database = json.decode(databaseFile:read("*a"))
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
local database = json.decode(databaseFile.readAll())
databaseFile.close()
databaseFile:close()
databaseFile = nil
end
end
end
@@ -27,13 +26,12 @@ local function listenForFieldSetups()
while true do
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
if (incomingChannel == setupFieldChannel) then
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
local database = json.decode(databaseFile:read("*a"))
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
local database = json.decode(databaseFile.readAll())
databaseFile:write(json.encode(database))
databaseFile:close()
databaseFile = nil
databaseFile.write(json.encode(database))
databaseFile.close()
end
end
end