Compare commits
No commits in common. "e7fce569e39ebe6f2f4f5bb115a79c79df806c29" and "e8a2105c77fe001ff1389363f2a16055269b86d9" have entirely different histories.
e7fce569e3
...
e8a2105c77
@ -1,13 +1,11 @@
|
|||||||
CropController = {}
|
CropController = {}
|
||||||
CropController.title = "Wheat farm"
|
CropController.interval = 900
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -152,72 +150,10 @@ 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.stats["Last harvest duration"] = duration
|
self.lastHarvestDuration = 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.stats["Last yield"] = yield
|
self.lastYield = yield
|
||||||
end
|
end
|
||||||
self:getMatrix()
|
end
|
||||||
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