summaryrefslogtreecommitdiff
path: root/sorter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'sorter.lua')
-rw-r--r--sorter.lua20
1 files changed, 19 insertions, 1 deletions
diff --git a/sorter.lua b/sorter.lua
index c5ac286..f2ff4f2 100644
--- a/sorter.lua
+++ b/sorter.lua
@@ -4,6 +4,7 @@ local str_utils = require("modules.str_utils")
local nav = require("modules.nav")
local DATA_PATH = "/data/sorter_data.txt"
+local CAT_PATH = "/data/sorter_cat.txt"
local function runDiagnostics()
@@ -23,6 +24,8 @@ local function runDiagnostics()
print(string.format("Data path exists: %s", dataExists and "yes" or "no"))
+ print(string.format("Category path exists: %s", fs.exists(CAT_PATH) and "yes" or "no"))
+
local hasItemsInUnsorted = inv_utils.hasItemsInStorage(peripheral.wrap("top"))
if not hasItemsInUnsorted then
@@ -88,6 +91,21 @@ local function getState()
table.remove(state.coords, 1)
end
+ state.categories = { }
+ if fs.exists(CAT_PATH) then
+ local file2 = fs.open(CAT_PATH, "r")
+ local cat_content = file2.readAll()
+ file2.close()
+
+ for _, cat in pairs(str_utils.split(cat_content, "---")) do
+ local categ = {}
+ for _, entry in pairs(str_utils.split(cat)) do
+ table.insert(categ, entry)
+ end
+ table.insert(state.categories, categ)
+ end
+ end
+
return state
end
@@ -112,7 +130,7 @@ local function runErrands()
for _, next_pos in pairs(state.coords) do
move(current_pos, next_pos, state.safe_y)
current_pos = next_pos
- inv_utils.storeIdenticalItemsInStorage()
+ inv_utils.storeIdenticalItemsInStorage(state)
if not inv_utils.hasItemsInTurtle() then
break