From 984bcb2e9e2867160d1d375cc753649080b33fe7 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 13 Jan 2023 09:59:02 +0000 Subject: [PATCH] Update 'Controller/CropController.lua' --- Controller/CropController.lua | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Controller/CropController.lua b/Controller/CropController.lua index d9967e4..f5c8d58 100644 --- a/Controller/CropController.lua +++ b/Controller/CropController.lua @@ -4,9 +4,45 @@ function CropController:new(t) t = t or {} setmetatable(t, self) self.__index = self + t.matrix = {} return t end +function CropController:getMatrix() + local s, matrixString = self:doAction(self.slaveID, "getMatrix") + local matrix + if (s == true) then + self.matrix = self:toMatrix(matrixString) + end +end + +function CropController:initMonitor() + self.monitor = peripheral.find("monitor") + self.monitor.setBackgroundColour(colours.black) + self.monitor.clear() + self.monitor.setTextScale(0.5) + self.monitor.setTextColour(colours.white) + term.redirect(self.monitor) +end + +function CropController:displayMatrix() + assert(type(self.matrix) == "table") + assert(type(self.matrix[1]) == "table") + local width = #self.matrix + local length = #self.matrix[1] + for i = 1, width do + for j = 1, length do + term.setCursorPos(i,j) + if(self.matrix[i][j] >= 0) then + term.setTextColour(colours.white) + term.write(self.matrix[i][j]) + else + term.setTextColour(colours.blue) + term.write("W") + end + end + end +end function CropController:toMatrix(str) local matrix = {}