summaryrefslogtreecommitdiff
path: root/sorter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'sorter.lua')
-rw-r--r--sorter.lua66
1 files changed, 66 insertions, 0 deletions
diff --git a/sorter.lua b/sorter.lua
new file mode 100644
index 0000000..6c50de5
--- /dev/null
+++ b/sorter.lua
@@ -0,0 +1,66 @@
+local refuel = require("modules.refuel")
+local inv_utils = require("modules.inv_utils")
+
+local DATA_PATH = "/data/sorter_data.txt"
+
+
+local function runDiagnostics()
+ local canStart = true
+
+ print("Running diagnostics...")
+ print(string.format("Fuel level: %s", turtle.getFuelLevel()))
+ local fuelStorage = peripheral.wrap("front")
+ local hasInStorage = refuel.hasFuelInStorage(fuelStorage) and "yes" or "no"
+ print(string.format("Fuel in storage: %s", hasInStorage))
+
+ local dataExists = fs.exists(DATA_PATH)
+
+ if not dataExists then
+ canStart = false
+ end
+
+ print(string.format("Data path exists: %s", dataExists and "yes" or "no"))
+
+ local hasItemsInUnsorted = inv_utils.hasItemsInStorage(peripheral.wrap("top"))
+
+ if not hasItemsInUnsorted then
+ canStart = false
+ end
+
+ print(string.format("Items in unsorted storage: %s", hasItemsInUnsorted and "yes" or "no"))
+
+ local hasItemsInLeftover = inv_utils.hasItemsInStorage(peripheral.wrap("bottom"))
+
+ if hasItemsInLeftover then
+ canStart = false
+ end
+
+ print(string.format("Items in leftover storage: %s", hasItemsInLeftover and "yes" or "no"))
+
+ if canStart then
+ print("Ready to start sorting.")
+ else
+ print("Can not start sorting.")
+ end
+
+ return canStart
+end
+
+local function run()
+ local result = runDiagnostics()
+ if not result then
+ return nil
+ end
+
+ write("Start? (y/N) ")
+ local response = read()
+ local firstChar = string.sub(response, 1, 1)
+ if firstChar == "y" or firstChar == "Y" then
+ print("Started sorting.")
+ else
+ print("Aborted.")
+ return nil
+ end
+end
+
+return { run = run }