SHOW:
|
|
- or go back to the newest paste.
1 | -- Internal Variables -- | |
2 | local buffer = {} | |
3 | local oldbuffer = {} | |
4 | local g = peripheral.find("arController") | |
5 | ||
6 | -- Internal Functions -- | |
7 | local compareBuffers = function() | |
8 | return (textutils.serialise(oldbuffer) == textutils.serialise(buffer)) | |
9 | end | |
10 | ||
11 | local renderObject = function(obj) | |
12 | return g[obj.func](table.unpack(obj.args)) | |
13 | end | |
14 | ||
15 | local addToBuffer = function(func,args) | |
16 | table.insert(buffer,{["func"]=func,["args"]=args}) | |
17 | end | |
18 | ||
19 | -- External Functions -- | |
20 | function render() | |
21 | if (compareBuffers()) then | |
22 | return false,"identical buffers" | |
23 | end | |
24 | g.clear() | |
25 | for k,v in ipairs(buffer) do | |
26 | renderObject(v) | |
27 | end | |
28 | oldbuffer = buffer | |
29 | clear() | |
30 | return true,nil | |
31 | end | |
32 | ||
33 | function clear() | |
34 | buffer = {} | |
35 | end | |
36 | ||
37 | -- Text Functions -- | |
38 | text = {} | |
39 | text.width = function(str) | |
40 | if type(str) == type("string") then | |
41 | return #string*5.25 | |
42 | end | |
43 | ||
44 | local longest = "" | |
45 | for k,v in ipairs(str) do | |
46 | if (#v > #longest) then | |
47 | longest = v | |
48 | end | |
49 | end | |
50 | return #longest*5.25 | |
51 | end | |
52 | text.height = function(strArr) | |
53 | if type(strArr) == type("string") then | |
54 | return 8 | |
55 | end | |
56 | return #strArr*8 | |
57 | end | |
58 | ||
59 | text.center = function(str,x,y,color) | |
60 | addToBuffer("drawCenteredString",{str,x,y,color}) | |
61 | end | |
62 | text.draw = function(str,x,y,color) | |
63 | addToBuffer("drawString",{str,x,y,color}) | |
64 | end | |
65 | text.left,text.write = text.draw | |
66 | text.right = function(str,x,y,color) | |
67 | addToBuffer("drawRightboundString",{str,x,y,color}) | |
68 | end | |
69 | text.formatArrayForMultiline = function(strArr) | |
70 | if type(strArr) == type("string") then | |
71 | return {["string"]=strArr,["side"]="left"} | |
72 | end | |
73 | local t = {} | |
74 | for k,v in ipairs(strArr) do | |
75 | if type(v) == type("string") then | |
76 | table.insert(t,{["string"]=v,["side"]="left"}) | |
77 | elseif v.side ~= "left" and v.side ~= "text" and v.side ~= "write" and v.side ~= "right" and v.side ~= "center" then | |
78 | table.insert(t,{["string"]=v.string,["side"]="left"}) | |
79 | else | |
80 | table.insert(t,v) | |
81 | end | |
82 | end | |
83 | return t | |
84 | end | |
85 | text.multiline = function(strArr,x,y,color) | |
86 | strArr = text.formatArrayForMultiline(strArr) | |
87 | for k,v in ipairs(strArr) do | |
88 | text[v.side](v.string,x,y+((k-1)*8),color) | |
89 | end | |
90 | end | |
91 | ||
92 | -- Shape Functions -- | |
93 | shapes = {} | |
94 | shapes.lines = {} | |
95 | shapes.fill = {} | |
96 | shapes.stroke = {} | |
97 | ||
98 | shapes.lines.h = function(x1,x2,y,color) | |
99 | addToBuffer("horizontalLine",{x1,x2,y,color}) | |
100 | end | |
101 | shapes.lines.v = function(x,y1,y2,color) | |
102 | addToBuffer("verticalLine",{x,y1,y2,color}) | |
103 | end | |
104 | ||
105 | shapes.fill.circle = function(x,y,radius,color) | |
106 | addToBuffer("fillCircle",{x,y,radius,color}) | |
107 | end | |
108 | shapes.fill.box = function(x1,y1,x2,y2,color) | |
109 | addToBuffer("fill",{x1,y1,x2,y2,color}) | |
110 | end | |
111 | shapes.fill.gradient = function(x1,y1,x2,y2,colorFrom,colorTo) | |
112 | addToBuffer("fillGradient",{x1,y1,x2,y2,colorFrom,colorTo}) | |
113 | end | |
114 | ||
115 | shapes.stroke.circle = function(x,y,radius,color) | |
116 | addToBuffer("drawCircle",{x,y,radius,color}) | |
117 | end | |
118 | shapes.stroke.box = function(x1,y1,x2,y2,color) | |
119 | shapes.lines.h(x1,x2,y1,color) | |
120 | shapes.lines.h(x1,x2,y2,color) | |
121 | shapes.lines.v(x1,y1,y2,color) | |
122 | shapes.lines.v(x2,y1,y2,color) | |
123 | end | |
124 | ||
125 | -- Image Functions -- | |
126 | images = {} | |
127 | images.item = function(itemId,x,y) | |
128 | addToBuffer("drawItemIcon",{itemId,x,y}) | |
129 | end | |
130 | ||
131 | -- Don't change this please <3 -- | |
132 | version = "1.0-a" |