test
This commit is contained in:
parent
103e0ea17d
commit
5238e31018
28
behavior.lua
28
behavior.lua
@ -1,28 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local logger = require("logger")
|
||||
local currentStatus = "idle"
|
||||
|
||||
function M.getStatus()
|
||||
return currentStatus
|
||||
end
|
||||
|
||||
function M.run()
|
||||
while true do
|
||||
currentStatus = "moving backward"
|
||||
logger.log("Started moving backward")
|
||||
for i = 1, 10 do
|
||||
turtle.back()
|
||||
sleep(0.5)
|
||||
end
|
||||
|
||||
currentStatus = "moving forward"
|
||||
logger.log("Started moving forward")
|
||||
for i = 1, 10 do
|
||||
turtle.forward()
|
||||
sleep(0.5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
29
logger.lua
29
logger.lua
@ -1,29 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local logLines = {}
|
||||
local maxLines = 5
|
||||
|
||||
function M.log(msg)
|
||||
local time = textutils.formatTime(os.time(), true)
|
||||
local entry = string.format("[%s] %s", time, msg)
|
||||
|
||||
table.insert(logLines, entry)
|
||||
if #logLines > maxLines then
|
||||
table.remove(logLines, 1)
|
||||
end
|
||||
|
||||
M.draw()
|
||||
end
|
||||
|
||||
function M.draw()
|
||||
local w, h = term.getSize()
|
||||
for i = 1, maxLines do
|
||||
term.setCursorPos(1, h - maxLines + i)
|
||||
term.clearLine()
|
||||
if logLines[i] then
|
||||
term.write(logLines[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
12
startup.lua
12
startup.lua
@ -1,7 +1,7 @@
|
||||
local filesToDownload = {
|
||||
"behavior.lua",
|
||||
"status.lua",
|
||||
"logger.lua"
|
||||
"libs/behavior.lua",
|
||||
"libs/status.lua",
|
||||
"libs/logger.lua"
|
||||
}
|
||||
|
||||
local baseURL = "https://git.fisher.network/cc/turtle/raw/main/"
|
||||
@ -24,6 +24,7 @@ local function downloadFile(filename)
|
||||
end
|
||||
|
||||
-- Download each file
|
||||
if not fs.exists("libs") then fs.makeDir("libs") end
|
||||
for _, filename in ipairs(filesToDownload) do
|
||||
-- remove each file first
|
||||
if fs.exists(filename) then
|
||||
@ -33,8 +34,9 @@ for _, filename in ipairs(filesToDownload) do
|
||||
downloadFile(filename)
|
||||
end
|
||||
|
||||
local behavior = require("behavior")
|
||||
local status = require("status")
|
||||
local tutil = require("libs.turtleutils")
|
||||
local behavior = require("libs.behavior")
|
||||
local status = require("libs.status")
|
||||
|
||||
-- Run behavior and status reporting in parallel
|
||||
parallel.waitForAny(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user