Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mon = {
- textScale = 0.5,
- textWidth = 15,
- width = 15,
- height = 10,
- data = {},
- screen = 1,
- totalScreens = 0,
- monitor,
- view = "gps"
- }
- function Mon:new()
- if #peripheral.getNames() == 0 then
- error("No peripherals found to check")
- end
- for k, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "monitor" then
- self.monitor = peripheral.wrap(v)
- break
- end
- end
- if not self.monitor then
- error("couldn't find a monitor to wrap")
- end
- setmetatable({}, Mon)
- local x, y = self.monitor.getSize()
- self.width = x
- self.height = y
- self.monitor.setTextScale(self.textScale)
- self.monitor.setCursorPos(1, 1)
- return self
- end
- function Mon:fillScreen(data, multiScreen)
- local height = self.height
- multiScreen = multiScreen or false
- if multiScreen then
- height = height - 2
- end
- local width = self.width
- local cursorPos = {[1] = 1, [2] = 1}
- local spaces = 3
- local counter = 0
- local screenText = ""
- local dummyText = ""
- local workingText = ""
- for k, v in pairs(data) do
- if data[k][2] + 600 > os.clock() then
- workingText = "on"
- elseif data[k][2] + 600 < os.clock() then
- workingText = "off"
- else
- workingText = "un"
- end
- -- 3+1+5+5+7+4+2 = 31 = +1 = 32
- if type(data[k][1]) == "table" then
- dummyText = self:spaceNumber(k, 3) .. ":"
- if self.view == "chunk" then
- dummyText =
- dummyText ..
- self:spaceNumber(math.floor(data[k][1].x / 16), 5) ..
- "," .. self:spaceNumber(math.floor(data[k][1].y / 16), 5) .. ","
- else
- dummyText =
- dummyText .. self:spaceNumber(data[k][1].x, 5) .. "," .. self:spaceNumber(data[k][1].y, 5) .. ","
- end
- dummyText =
- dummyText .. self:spaceNumber(data[k][1].z, 3) .. "-" .. self:spaceNumber(workingText, 4) .. "| "
- else
- dummyText =
- self:spaceNumber(k, 3) ..
- ":" .. self:spaceNumber(data[k][1], 15) .. "-" .. self:spaceNumber(workingText, 4) .. "| "
- end
- counter = counter + 1
- screenText = screenText .. dummyText
- if counter == math.floor(width / 25) then
- screenText = screenText .. "\n"
- counter = 0
- end
- end
- self.monitor.setCursorPos(1, 1)
- self.monitor.clear()
- local oldTerm = term.redirect(self.monitor)
- write(screenText)
- term.redirect(oldTerm)
- end
- function Mon:spaceNumber(number, totalSpace)
- local spaceText = ""
- local number = number
- if number == nil then
- number = "nan"
- end
- local totalSpace = totalSpace or 0
- spaces = totalSpace - #tostring(number)
- for i = 1, spaces do
- spaceText = spaceText .. " "
- end
- return number .. spaceText
- end
- function Mon:setData(data)
- local something = {}
- for k, v in pairs(data) do
- something[#something + 1] = k
- end
- self.data = data
- end
- function Mon:addData(data)
- for i = 1, #data do
- self.data[#self.data + 1] = data[i]
- end
- end
- function Mon:showData(screen)
- local displayData = {}
- local columns = math.floor(self.width / 25)
- if columns == 0 then
- columns = 1
- end
- local screen = screen or nil
- local rows = self.height
- local totalSpots = (columns * rows) - 5
- if #self.data > totalSpots and self.totalScreens ~= 1 then
- rows = rows - 2
- -- data = {[i] = {1, x, y}}
- if screen then
- self.screen = screen
- end
- self.totalScreens = math.ceil(#self.data / totalSpots)
- local multiplier = self.screen - 1
- for i = 1 + (multiplier * totalSpots), (totalSpots + (multiplier * totalSpots)) do
- if self.data[i] ~= nil then
- if type(self.data[i][3]) == nil then
- displayData[self.data[i][1]] = {self.data[i][2], self.data[i][3]}
- else
- displayData[self.data[i][1]] = {self.data[i][2], self.data[i][3]}
- end
- end
- end
- self:fillScreen(displayData, true)
- self.monitor.setCursorPos(2, self.height)
- self.monitor.write("PREV")
- local middleText = self.screen .. "/" .. self.totalScreens
- self.monitor.setCursorPos(math.floor((self.width / 2) - (#middleText / 2)), self.height)
- self.monitor.write(tostring(middleText))
- self.monitor.setCursorPos((self.width - 11), self.height)
- self.monitor.write("NEXT")
- self.monitor.setCursorPos((self.width - 5), self.height)
- if self.view == "chunk" then
- self.monitor.write("CHUNK")
- else
- self.monitor.write("GPS")
- end
- else
- for k, v in pairs(self.data) do
- if v[3] then
- displayData[v[1]] = {v[2], v[3]}
- else
- displayData[v[1]] = {v[2]}
- end
- end
- self:fillScreen(displayData, false)
- self.monitor.setCursorPos((self.width - 5), self.height)
- if self.view == "chunk" then
- self.monitor.write("GPS ")
- else
- self.monitor.write("CHUNK")
- end
- end
- end
- function Mon:listen()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- local button1 = {[1] = true, [2] = true, [3] = true, [4] = true, [5] = true}
- local button2 = {
- [self.width] = true,
- [self.width - 1] = true,
- [self.width - 2] = true,
- [self.width - 3] = true,
- [self.width - 4] = true
- }
- local button3 = {
- [self.width - 5] = true,
- [self.width - 6] = true,
- [self.width - 7] = true,
- [self.width - 8] = true,
- [self.width - 9] = true
- }
- if button1[x] and y == self.height then
- self.screen = self.screen - 1
- if self.screen <= 0 then
- self.screen = self.totalScreens
- end
- self:showData()
- elseif button2[x] and y == self.height then
- if self.view == "chunk" then
- self.view = "gps"
- else
- self.view = "chunk"
- end
- self:showData()
- elseif button3[x] and y == self.height then
- self.screen = self.screen + 1
- if self.screen > self.totalScreens then
- self.screen = 1
- end
- self:showData()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment