Compare commits
10 Commits
e8a2105c77
...
e7fce569e3
Author | SHA1 | Date | |
---|---|---|---|
|
e7fce569e3 | ||
|
7820506e6a | ||
|
65d31d1959 | ||
|
c4cd334cbe | ||
|
4485896dc0 | ||
|
6b831c18ef | ||
|
0f4164e4ec | ||
|
748576643f | ||
|
326814c092 | ||
|
070f33ac80 |
@ -1,11 +1,13 @@
|
|||||||
CropController = {}
|
CropController = {}
|
||||||
CropController.interval = 900
|
CropController.title = "Wheat farm"
|
||||||
|
|
||||||
function CropController:new(t)
|
function CropController:new(t)
|
||||||
t = t or {}
|
t = t or {}
|
||||||
setmetatable(t, self)
|
setmetatable(t, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
t.matrix = {}
|
t.matrix = {}
|
||||||
|
t.stats = {}
|
||||||
|
t.stats["Harvest Interval"] = 900
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -150,10 +152,72 @@ function CropController:harvest()
|
|||||||
self:doAction(self.slaveID, "harvest")
|
self:doAction(self.slaveID, "harvest")
|
||||||
local s, duration = self:doAction(self.slaveID, "getLastHarvestDuration")
|
local s, duration = self:doAction(self.slaveID, "getLastHarvestDuration")
|
||||||
if s == true then
|
if s == true then
|
||||||
self.lastHarvestDuration = duration
|
self.stats["Last harvest duration"] = duration
|
||||||
end
|
end
|
||||||
local s, yield = self:doAction(self.slaveID, "getLastYield")
|
local s, yield = self:doAction(self.slaveID, "getLastYield")
|
||||||
if s == true then
|
if s == true then
|
||||||
self.lastYield = yield
|
self.stats["Last yield"] = yield
|
||||||
end
|
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()
|
Loading…
x
Reference in New Issue
Block a user