Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Internal Variables --
- local buffer = {}
- local oldbuffer = {}
- local g = peripheral.find("arController")
- -- Internal Functions --
- local compareBuffers = function()
- return (textutils.serialise(oldbuffer) == textutils.serialise(buffer))
- end
- local renderObject = function(obj)
- return g[obj.func](table.unpack(obj.args))
- end
- local addToBuffer = function(func,args)
- table.insert(buffer,{["func"]=func,["args"]=args})
- end
- -- External Functions --
- function render()
- if (compareBuffers()) then
- return false,"identical buffers"
- end
- g.clear()
- for k,v in ipairs(buffer) do
- renderObject(v)
- end
- oldbuffer = buffer
- clear()
- return true,nil
- end
- function clear()
- buffer = {}
- end
- -- Text Functions --
- text = {}
- text.width = function(str)
- if type(str) == type("string") then
- return #string*5.25
- end
- local longest = ""
- for k,v in ipairs(str) do
- if (#v > #longest) then
- longest = v
- end
- end
- return #longest*5.25
- end
- text.height = function(strArr)
- if type(strArr) == type("string") then
- return 8
- end
- return #strArr*8
- end
- text.center = function(str,x,y,color)
- addToBuffer("drawCenteredString",{str,x,y,color})
- end
- text.draw = function(str,x,y,color)
- addToBuffer("drawString",{str,x,y,color})
- end
- text.left,text.write = text.draw
- text.right = function(str,x,y,color)
- addToBuffer("drawRightboundString",{str,x,y,color})
- end
- text.formatArrayForMultiline = function(strArr)
- if type(strArr) == type("string") then
- return {["string"]=strArr,["side"]="left"}
- end
- local t = {}
- for k,v in ipairs(strArr) do
- if type(v) == type("string") then
- table.insert(t,{["string"]=v,["side"]="left"})
- elseif v.side ~= "left" and v.side ~= "text" and v.side ~= "write" and v.side ~= "right" and v.side ~= "center" then
- table.insert(t,{["string"]=v.string,["side"]="left"})
- else
- table.insert(t,v)
- end
- end
- return t
- end
- text.multiline = function(strArr,x,y,color)
- strArr = text.formatArrayForMultiline(strArr)
- for k,v in ipairs(strArr) do
- text[v.side](v.string,x,y+((k-1)*8),color)
- end
- end
- -- Shape Functions --
- shapes = {}
- shapes.lines = {}
- shapes.fill = {}
- shapes.stroke = {}
- shapes.lines.h = function(x1,x2,y,color)
- addToBuffer("horizontalLine",{x1,x2,y,color})
- end
- shapes.lines.v = function(x,y1,y2,color)
- addToBuffer("verticalLine",{x,y1,y2,color})
- end
- shapes.fill.circle = function(x,y,radius,color)
- addToBuffer("fillCircle",{x,y,radius,color})
- end
- shapes.fill.box = function(x1,y1,x2,y2,color)
- addToBuffer("fill",{x1,y1,x2,y2,color})
- end
- shapes.fill.gradient = function(x1,y1,x2,y2,colorFrom,colorTo)
- addToBuffer("fillGradient",{x1,y1,x2,y2,colorFrom,colorTo})
- end
- shapes.stroke.circle = function(x,y,radius,color)
- addToBuffer("drawCircle",{x,y,radius,color})
- end
- shapes.stroke.box = function(x1,y1,x2,y2,color)
- shapes.lines.h(x1,x2,y1,color)
- shapes.lines.h(x1,x2,y2,color)
- shapes.lines.v(x1,y1,y2,color)
- shapes.lines.v(x2,y1,y2,color)
- end
- -- Image Functions --
- images = {}
- images.item = function(itemId,x,y)
- addToBuffer("drawItemIcon",{itemId,x,y})
- end
- -- Don't change this please <3 --
- version = "1.0-a"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement