Compare commits

...

10 Commits

Author SHA1 Message Date
manuel
e7fce569e3 Update 'Controller/CropController.lua' 2023-01-14 10:36:48 +00:00
manuel
7820506e6a Update 'Controller/CropController.lua' 2023-01-14 10:33:17 +00:00
manuel
65d31d1959 Update 'Controller/CropController.lua' 2023-01-14 10:30:41 +00:00
manuel
c4cd334cbe Update 'Controller/CropController.lua' 2023-01-14 10:27:53 +00:00
manuel
4485896dc0 Update 'Controller/CropController.lua' 2023-01-14 10:05:39 +00:00
manuel
6b831c18ef Update 'Controller/CropController.lua' 2023-01-14 10:03:02 +00:00
manuel
0f4164e4ec Update 'Controller/CropController.lua' 2023-01-14 10:02:17 +00:00
manuel
748576643f Update 'Controller/CropController.lua' 2023-01-14 09:56:35 +00:00
manuel
326814c092 Update 'Controller/CropController.lua' 2023-01-13 20:23:47 +00:00
manuel
070f33ac80 Update 'Controller/CropController.lua' 2023-01-13 20:05:49 +00:00

@ -1,11 +1,13 @@
CropController = {}
CropController.interval = 900
CropController.title = "Wheat farm"
function CropController:new(t)
t = t or {}
setmetatable(t, self)
self.__index = self
t.matrix = {}
t.stats = {}
t.stats["Harvest Interval"] = 900
return t
end
@ -150,10 +152,72 @@ function CropController:harvest()
self:doAction(self.slaveID, "harvest")
local s, duration = self:doAction(self.slaveID, "getLastHarvestDuration")
if s == true then
self.lastHarvestDuration = duration
self.stats["Last harvest duration"] = duration
end
local s, yield = self:doAction(self.slaveID, "getLastYield")
if s == true then
self.lastYield = yield
self.stats["Last yield"] = yield
end
end
self:getMatrix()
end
function CropController:displayStats(x,y)
local keyWidth = 0
for k, v in pairs(self.stats) do
if string.len(tostring(k)) > keyWidth then
keyWidth = string.len(tostring(k))
end
end
for k, v in pairs(self.stats) do
term.setCursorPos(x, y)
term.write(tostring(k))
term.setCursorPos(x + keyWidth + 1, y)
term.write(tostring(v))
y = y + 1
end
end
function CropController:displayTitle(x,y)
term.setCursorPos(x,y)
term.write(self.title)
local width = term.getSize()
for i = 1, width do
term.setCursorPos(i, y+1)
term.write("_")
end
end
function CropController:refreshDisplay()
term.clear()
term.setTextColour(colours.white)
self:displayTitle(1,1)
self:displayMatrix(1,3)
term.setTextColour(colours.white)
local matrixHeight = #self.matrix
self:displayStats(1, matrixHeight + 4)
end
function CropController:updateTimeToHarvest(x,y)
term.clearLine(y)
term.setCursorPos(x,y)
term.write("next harvest in " .. tostring(math.ceil(self.stats["Harvest Interval"] - (os.clock() - self.lastHarvest))) .. " seconds")
end
function CropController:main()
local termWidth, termHeight = term.getSize()
local cc = CropController:new()
cc:setSlaveID(5)
cc:doAction(cc.slaveID, "init")
cc:initMonitor()
while true do
cc.lastHarvest = os.clock()
cc:harvest()
cc:refreshDisplay()
while cc.stats["Harvest Interval"] - (os.clock() - cc.lastHarvest) > 0 do
cc:updateTimeToHarvest(1, termHeight - 1)
sleep(0.5)
end
end
end
CropController:main()