Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local utils = require("utils")
- HasSomethingChanged = false
- RenderBuffer = {}
- Width, Height = term.getSize()
- -- Helper functions
- function getWidth()
- return Width
- end
- function getHeight()
- return Height
- end
- function clear()
- term.clear()
- end
- -- Text
- function addCentralXText(message, posY)
- -- y goes unused here
- local x, y = utils.midpoint(Width, Height)
- local newX = utils.getXPosOfString(message, x)
- return addText(message, newX, posY)
- end
- function addCentralText(message)
- -- x goes unused here
- local x, y = utils.midpoint(Width, Height)
- return addCentralXText(message, y)
- end
- function addText(message, posX, posY)
- data = {}
- data["message"] = message
- data["posX"] = posX
- data["posY"] = posY
- RenderBuffer[(#RenderBuffer) + 1] = data
- HasSomethingChanged = true
- return #RenderBuffer
- end
- function updateText(handle, newText)
- RenderBuffer[handle]["message"] = newText
- end
- -- Display
- function flush()
- local count = #RenderBuffer
- for i = 1, count do
- RenderBuffer[i] = nil
- end
- end
- function writeText(message, startX, startY)
- term.setCursorPos(startX, startY)
- term.write(message)
- end
- function display()
- if HasSomethingChanged then
- clear()
- for i = 1, #RenderBuffer do
- local current = RenderBuffer[i]
- local x, y, message = current["posX"], current["posY"], current["message"]
- writeText(message, x, y)
- end
- HasSomethingChanged = false
- end
- end
- return {
- clear = clear,
- addText = addText,
- addCentralText = addCentralText,
- addCentralXText = addCentralXText,
- updateText = updateText,
- flush = flush,
- display = display,
- getWidth = getWidth,
- getHeight = getHeight
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement