feat(farming/database): switched to built-in craftos functions
This commit is contained in:
@@ -13,12 +13,11 @@ local function listenForFieldDataRequests()
|
|||||||
while true do
|
while true do
|
||||||
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
||||||
if (incomingChannel == fieldDataChannel) then
|
if (incomingChannel == fieldDataChannel) then
|
||||||
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
|
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
|
||||||
local database = json.decode(databaseFile:read("*a"))
|
local database = json.decode(databaseFile.readAll())
|
||||||
|
databaseFile.close()
|
||||||
|
|
||||||
|
|
||||||
databaseFile:close()
|
|
||||||
databaseFile = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -27,13 +26,12 @@ local function listenForFieldSetups()
|
|||||||
while true do
|
while true do
|
||||||
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
||||||
if (incomingChannel == setupFieldChannel) then
|
if (incomingChannel == setupFieldChannel) then
|
||||||
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
|
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
|
||||||
local database = json.decode(databaseFile:read("*a"))
|
local database = json.decode(databaseFile.readAll())
|
||||||
|
|
||||||
|
|
||||||
databaseFile:write(json.encode(database))
|
databaseFile.write(json.encode(database))
|
||||||
databaseFile:close()
|
databaseFile.close()
|
||||||
databaseFile = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user