[READ-ONLY] Mirror of https://github.com/thoda-dev/du_render_script_library. A library to build renderscript in boards without writting it as a full string
0

Configure Feed

Select the types of activity you want to include in your feed.

base

Thomas (Apr 13, 2023, 8:16 PM +0200) a0d41c65 b8bed2e3

+451 -1
+34 -1
README.md
··· 1 1 # du_render_script_library 2 - A library to build renderscript in boards without writting it as a full string 2 + 3 + A library to build renderscript in boards without writting it as a full string 4 + 5 + The goal of that lib is to make RenderScript easier to write and read when written un control units and not directly in screens. 6 + 7 + ## How to use it 8 + 9 + Paste all the content of the library (prefer the minified version) at the start of your script in a control unit in game and then you can use it like this: 10 + 11 + ```lua 12 + local script = setmetatable({},RenderScript) 13 + local MyFirstLayer = script:createLayer() 14 + script:addBox(MyFirstLayer,0,0,100,100) 15 + 16 + if not script:isTooLong() then 17 + screen.setRenderScript(tostring(script)) 18 + else 19 + system.print("WARNING: Script too long!! Length is actualy " .. script:len() .. " / " .. script:getMaxSize()) 20 + end 21 + 22 + ``` 23 + 24 + ## Code before 25 + 26 + Code was all formated as a string and was hard to read, write and debug 27 + 28 + ```lua 29 + local script = [[ 30 + local MyFirstLayer = createLayer() 31 + addBox(MyFirstLayer, 0, 0, 100, 100) 32 + ]] 33 + 34 + screen.setRenderScript(script) 35 + ```
+416
RenderScript.lua
··· 1 + RenderScript = { 2 + __index = { 3 + _s = "", --script stored as string 4 + _l = {}, --layers variable name stored 5 + _f = {}, --fonts variable name stored 6 + 7 + ---@alias table Shape IDs 8 + SHAPES = { 9 + BEZIER=0, 10 + BOX=1, 11 + BOX_ROUNDED=2, 12 + CIRCLE=3, 13 + IMAGE=4, 14 + LINE=5, 15 + POLYGON=6, 16 + TEXT=7, 17 + }, 18 + 19 + ---@alias table AlignH IDs 20 + ALIGN_H = { 21 + LEFT=0, 22 + CENTER=1, 23 + RIGHT=2, 24 + }, 25 + 26 + ---@alias table AlignV IDs 27 + ALIGN_V = { 28 + ASCENDER=0, 29 + TOP=1, 30 + MIDDLE=2, 31 + BASELINE=3, 32 + BOTTOM=4, 33 + DESCENDER=5, 34 + }, 35 + 36 + --- Create a new layer that will be rendered on top of all previously-created layers 37 + ---@return integer index The id that can be used to uniquely identify the layer for use with other API functions 38 + createLayer = function(self) 39 + local layer_name = '_L' .. (#self._l + 1) 40 + self._s = self._s .. 'local ' .. layer_name .. '=createLayer();' 41 + self._l[#self._l + 1] = layer_name 42 + return #self._l 43 + end, 44 + 45 + --- Load a font to be used with addText 46 + ---@param name string The name of the font to load; see the font list section for available font names 47 + ---@param size integer The size, in vertical pixels, at which the font will render. Note that this size can be changed during script execution with the setFontSize function 48 + ---@return integer value The id that can be used to uniquely identify the font for use with other API functions 49 + loadFont = function (self, name, size) 50 + local font_name = '_F' .. (#self._f + 1) 51 + self._f[#self._f + 1] = font_name 52 + self._s = self._s .. 'local ' .. font_name .. '=loadFont("' .. name .. '",' .. size .. ');' 53 + end, 54 + 55 + --- Return the screen location that is currently raycasted by the player 56 + ---@return number x, number y A tuple containing the (x, y) coordinates of the cursor, or (-1, -1) if the screen is not currently raycasted 57 + getCursor = function (self) 58 + self._s = self._s .. 'local _CX,_CY=getCursor();' 59 + --cursor x and y are always named _CX and _CY in the RenderScript 60 + return '_CX','_CY' 61 + end, 62 + 63 + --- Return the screen's current resolution. 64 + --- Ideally, your render scripts should be written to adapt to the resolution, as it may change in the future 65 + ---@return integer width, integer height A tuple containing the (width, height) of the screen's render surface, in pixels 66 + getResolution = function (self) 67 + self._s = self._s .. 'local _RX,_RY=getResolution();' 68 + --resolution x and y are always named _RX and _RY in the RenderScript 69 + return '_RX','_RY' 70 + end, 71 + 72 + --- Add a quadratic bezier curve to the given layer. 73 + --- Supported properties: shadow, strokeColor, strokeWidth 74 + ---@param layer integer The id of the layer to which to add 75 + ---@param x1 number X coordinate of the first point of the curve (the starting point) 76 + ---@param y1 number Y coordinate of the first point of the curve (the starting point) 77 + ---@param x2 number X coordinate of the second point of the curve (the control point) 78 + ---@param y2 number Y coordinate of the second point of the curve (the control point) 79 + ---@param x3 number X coordinate of the third point of the curve (the ending point) 80 + ---@param y3 number Y coordinate of the third point of the curve (the ending point) 81 + addBezier = function(self, layer, x1, y1, x2, y2, x3, y3) 82 + self._s = self._s .. 'addBezier(' .. self._l[layer] .. ',' .. x1 .. ',' .. x2 .. ',' .. y1 .. ',' .. y2 .. ',' .. x3 .. ',' .. y3 .. ');' 83 + end, 84 + 85 + --- Add a box to the given layer. 86 + --- Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth 87 + ---@param layer integer The id of the layer to which to add 88 + ---@param x number X coordinate of the box's top-left corner 89 + ---@param y number Y coordinate of the box's top-left corner 90 + ---@param sx number Width of the box 91 + ---@param sy number Height of the box 92 + addBox = function(self, layer, x, y, sx, sy) 93 + self._s = self._s .. 'addBox(' .. self._l[layer] .. ',' .. x .. ',' .. y .. ',' .. sx .. ',' .. sy .. ');' 94 + end, 95 + 96 + --- Add a rounded box to the given layer. 97 + --- Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth 98 + ---@param layer integer The id of the layer to which to add 99 + ---@param x number X coordinate of the box's top-left corner 100 + ---@param y number Y coordinate of the box's top-left corner 101 + ---@param sx number Width of the box 102 + ---@param sy number Height of the box 103 + ---@param r number Rounding radius of the box 104 + addBoxRounded = function (self, layer, x, y, sx, sy, r) 105 + self._s = self._s .. 'addBoxRounded(' .. self._l[layer] .. ',' .. x .. ',' .. y .. ',' .. sx .. ',' .. sy .. ',' .. r .. ');' 106 + end, 107 + 108 + --- Add a circle to the given layer. 109 + --- Supported properties: fillColor, shadow, strokeColor, strokeWidth 110 + ---@param layer integer The id of the layer to which to add 111 + ---@param x number X coordinate of the circle's center 112 + ---@param y number Y coordinate of the circle's center 113 + ---@param r number Radius of the circle 114 + addCircle = function(self, layer, x, y, r) 115 + self._s = self._s .. 'addCircle(' .. self._l[layer] .. ',' .. x .. ',' .. y .. ',' .. r .. ');' 116 + end, 117 + 118 + --- Add an image to the given layer. 119 + --- Supported properties: fillColor, rotation 120 + ---@param layer integer The id of the layer to which to add 121 + ---@param image integer The id of the image to add 122 + ---@param x number X coordinate of the image's top-left corner 123 + ---@param y number Y coordinate of the image's top-left corner 124 + ---@param sx number Width of the image 125 + ---@param sy number Height of the image 126 + addImage = function(self, layer, image, x, y, sx, sy) 127 + self._s = self._s .. 'addImage(' .. self._l[layer] .. ',' .. image .. ',' .. x .. ',' .. y .. ',' .. sx .. ',' .. sy .. ');' 128 + end, 129 + 130 + --- Add a sub-region of an image to the given layer. 131 + --- Supported properties: fillColor, rotation 132 + ---@param layer integer The id of the layer to which to add 133 + ---@param image integer The id of the image to add 134 + ---@param x number X coordinate of the image's top-left corner 135 + ---@param y number Y coordinate of the image's top-left corner 136 + ---@param sx number Width of the image 137 + ---@param sy number Height of the image 138 + ---@param subX number X coordinate of the top-left corner of the sub-region to draw 139 + ---@param subY number Y coordinate of the top-left corner of the sub-region to draw 140 + ---@param subSx number Width of the sub-region within the image to draw 141 + ---@param subSy number Height of the sub-region within the image to draw 142 + addImageSub = function(self, layer, image, x, y, sx, sy, subX, subY, subSx, subSy) 143 + self._s = self._s .. 'addImageSub(' .. self._l[layer] .. ',' .. image .. ',' .. x .. ',' .. y .. ',' .. sx .. ',' .. sy .. ',' .. subX .. ',' .. subY .. ',' .. subSx .. ',' .. subSy .. ');' 144 + end, 145 + 146 + --- Add a line to the given layer. 147 + --- Supported properties: rotation, shadow, strokeColor, strokeWidth 148 + ---@param layer integer The id of the layer to which to add 149 + ---@param x1 number X coordinate of the start of the line 150 + ---@param y1 number Y coordinate of the start of the line 151 + ---@param x2 number X coordinate of the end of the line 152 + ---@param y2 number Y coordinate of the end of the line 153 + addLine = function(self, layer, x1, y1, x2, y2) 154 + self._s = self._s .. 'addLine(' .. self._l[layer] .. ',' .. x1 .. ',' .. y1 .. ',' .. x2 .. ',' .. y2 .. ');' 155 + end, 156 + 157 + --- Add a quadrilateral to the given layer. 158 + --- Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth 159 + ---@param layer integer The id of the layer to which to add 160 + ---@param x1 number X coordinate of the first point of the quad 161 + ---@param y1 number Y coordinate of the first point of the quad 162 + ---@param x2 number X coordinate of the second point of the quad 163 + ---@param y2 number Y coordinate of the second point of the quad 164 + ---@param x3 number X coordinate of the third point of the quad 165 + ---@param y3 number Y coordinate of the third point of the quad 166 + ---@param x4 number X coordinate of the fourth point of the quad 167 + ---@param y4 number Y coordinate of the fourth point of the quad 168 + addQuad = function(self, layer, x1, y1, x2, y2, x3, y3, x4, y4) 169 + self._s = self._s .. 'addQuad(' .. self._l[layer] .. ',' .. x1 .. ',' .. y1 .. ',' .. x2 .. ',' .. y2 .. ',' .. x3 .. ',' .. y3 .. ',' .. x4 .. ',' .. y4 .. ');' 170 + end, 171 + 172 + --- Add a string of text to the given layer. 173 + --- See setNextTextAlign for information on controlling text anchoring. 174 + --- Supported properties: fillColor, shadow, strokeColor, strokeWidth 175 + ---@param layer integer The id of the layer to which to add 176 + ---@param font integer The id of the font to use 177 + ---@param text string The string of text to be added 178 + ---@param x number X coordinate of the text anchor 179 + ---@param y number Y coordinate of the text anchor 180 + addText = function(self, layer, font, text, x, y) 181 + self._s = self._s .. 'addText(' .. self._l[layer] .. ',' .. self._f[font] .. ',' .. text .. ',' .. x .. ',' .. y .. ');' 182 + end, 183 + 184 + --- Add a triangle to the given layer. 185 + --- Supported properties: fillColor, rotation, shadow, strokeColor, strokeWidth 186 + ---@param layer integer The id of the layer to which to add 187 + ---@param x1 number X coordinate of the first point of the triangle 188 + ---@param y1 number Y coordinate of the first point of the triangle 189 + ---@param x2 number X coordinate of the second point of the triangle 190 + ---@param y2 number Y coordinate of the second point of the triangle 191 + ---@param x3 number X coordinate of the third point of the triangle 192 + ---@param y3 number Y coordinate of the third point of the triangle 193 + addTriangle = function(self, layer, x1, y1, x2, y2, x3, y3) 194 + self._s = self._s .. 'addTriangle(' .. self._l[layer] .. ',' .. x1 .. ',' .. y1 .. ',' .. x2 .. ',' .. y2 .. ',' .. x3 .. ',' .. y3 .. ');' 195 + end, 196 + 197 + --- Set the background color of the screen 198 + ---@param r number Red component, between 0 and 1 199 + ---@param g number Green component, between 0 and 1 200 + ---@param b number Blue component, between 0 and 1 201 + setBackgroundColor = function (self, r, g, b) 202 + self._s = self._s .. 'setBackgroundColor(' .. r .. ',' .. g .. ',' .. b .. ');' 203 + end, 204 + 205 + --- Set the default fill color for all subsequent shapes of the given type added to the given layer 206 + ---@param layer integer The layer for which the default will be set 207 + ---@param shapeType integer The type of shape to which the default will apply (see ShapeType) 208 + ---@param r number Red component, between 0 and 1 209 + ---@param g number Green component, between 0 and 1 210 + ---@param b number Blue component, between 0 and 1 211 + ---@param a number Alpha component, between 0 and 1 212 + setDefaultFillColor = function (self, layer, shapeType, r, g, b, a) 213 + self._s = self._s .. 'setDefaultFillColor(' .. self._l[layer] .. ',' .. shapeType .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 214 + end, 215 + 216 + --- Set the default rotation for all subsequent shapes of the given type added to the given layer 217 + ---@param layer integer The layer for which the default will be set 218 + ---@param shapeType integer The type of shape to which the default will apply (see ShapeType) 219 + ---@param rotation number Rotation, in radians; positive is counter-clockwise, negative is clockwise 220 + setDefaultRotation = function (self, layer, shapeType, rotation) 221 + self._s = self._s .. 'setDefaultRotation(' .. self._l[layer] .. ',' .. shapeType .. ',' .. rotation .. ');' 222 + end, 223 + 224 + --- Set the default shadow for all subsequent shapes of the given type added to the given layer 225 + ---@param layer integer The layer for which the default will be set 226 + ---@param shapeType integer The type of shape to which the default will apply (see ShapeType) 227 + ---@param radius number The distance that the shadow extends from the shape's border 228 + ---@param r number Red component, between 0 and 1 229 + ---@param g number Green component, between 0 and 1 230 + ---@param b number Blue component, between 0 and 1 231 + ---@param a number Alpha component, between 0 and 1 232 + setDefaultShadow = function (self, layer, shapeType, radius, r, g, b, a) 233 + self._s = self._s .. 'setDefaultShadow(' .. self._l[layer] .. ',' .. shapeType .. ',' .. radius .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 234 + end, 235 + 236 + --- Set the default stroke color for all subsequent shapes of the given type added to the given layer 237 + ---@param layer integer The layer for which the default will be set 238 + ---@param shapeType integer The type of shape to which the default will apply (see ShapeType) 239 + ---@param r number Red component, between 0 and 1 240 + ---@param g number Green component, between 0 and 1 241 + ---@param b number Blue component, between 0 and 1 242 + ---@param a number Alpha component, between 0 and 1 243 + setDefaultStrokeColor = function (self, layer, shapeType, r, g, b, a) 244 + self._s = self._s .. 'setDefaultStrokeColor(' .. self._l[layer] .. ',' .. shapeType .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 245 + end, 246 + 247 + --- Set the default stroke width for all subsequent shapes of the given type added to the given layer 248 + ---@param layer integer The layer for which the default will be set 249 + ---@param shapeType integer The type of shape to which the default will apply (see ShapeType) 250 + ---@param strokeWidth number Stroke width, in pixels 251 + setDefaultStrokeWidth = function (self, layer, shapeType, strokeWidth) 252 + self._s = self._s .. 'setDefaultStrokeWidth(' .. self._l[layer] .. ',' .. shapeType .. ',' .. strokeWidth .. ');' 253 + end, 254 + 255 + --- Set the default text alignment of all subsequent text strings on the given layer 256 + ---@param layer integer The layer for which the default will be set 257 + ---@param alignH integer Specifies the horizontal anchoring of a text string relative to the draw coordinates; must be one of the following built-in constants: AlignH_Left, AlignH_Center, AlignH_Right 258 + ---@param alignV integer Specifies the vertical anchoring of a text string relative to the draw coordinates; must be one of the following built-in constants: AlignV_Ascender, AlignV_Top, AlignV_Middle, AlignV_Baseline, AlignV_Bottom, AlignV_Descender 259 + setDefaultTextAlign = function (self, layer, alignH, alignV) 260 + self._s = self._s .. 'setDefaultTextAlign(' .. self._l[layer] .. ',' .. alignH .. ',' .. alignV .. ');' 261 + end, 262 + 263 + --- Set the size at which a font will render. 264 + --- Impacts all subsequent font-related calls, including addText, getFontMetrics, and getTextBounds. 265 + ---@param font integer The font for which the size will be set 266 + ---@param size integer The new size, in vertical pixels, at which the font will render 267 + setFontSize = function (font, size) 268 + self._s = self._s .. 'setFontSize(' .. self._f[font] .. ',' .. size .. ');' 269 + end, 270 + 271 + --- Set a clipping rectangle applied to the layer as a whole. 272 + --- Layer contents that fall outside the clipping rectangle will not be rendered, and those that are 273 + --- partially within the rectangle will be 'clipped' against it. The clipping rectangle is applied 274 + --- before layer transformations. Note that clipped contents still count toward the render cost. 275 + ---@param layer integer The layer for which the clipping rectangle will be set 276 + ---@param x number X coordinate of the clipping rectangle's top-left corner 277 + ---@param y number Y coordinate of the clipping rectangle's top-left corner 278 + ---@param sx number Width of the clipping rectangle 279 + ---@param sy number Height of the clipping rectangle 280 + setLayerClipRect = function (self, layer, x, y, sx, sy) 281 + self._s = self._s .. 'setLayerClipRect(' .. self._l[layer] .. ',' .. x .. ',' .. y .. ',' .. sx .. ',' .. sy .. ');' 282 + end, 283 + 284 + --- Set the transform origin of a layer; layer scaling and rotation are applied relative to this origin 285 + ---@param layer integer The layer for which the origin will be set 286 + ---@param x number X coordinate of the layer's transform origin 287 + ---@param y number Y coordinate of the layer's transform origin 288 + setLayerOrigin = function (self, layer, x, y) 289 + self._s = self._s .. 'setLayerOrigin(' .. self._l[layer] .. ',' .. x .. ',' .. y .. ');' 290 + end, 291 + 292 + --- Set a rotation applied to the layer as a whole, relative to the layer's transform origin 293 + ---@param layer integer The layer for which the rotation will be set 294 + ---@param rotation number Rotation, in radians; positive is counter-clockwise, negative is clockwise 295 + setLayerRotation = function (self, layer, rotation) 296 + self._s = self._s .. 'setLayerRotation(' .. self._l[layer] .. ',' .. rotation .. ');' 297 + end, 298 + 299 + --- Set a scale factor applied to the layer as a whole, relative to the layer's transform origin. 300 + --- Scale factors are multiplicative, so that a scale >1 enlarges the size of the layer, 1.0 does nothing, and 301 + --- <1 reduces the size of the layer. 302 + ---@param layer integer The layer for which the scale factor will be set 303 + ---@param sx number Scale factor along the X axis 304 + ---@param sy number Scale factor along the Y axis 305 + setLayerScale = function (self, layer, sx, sy) 306 + self._s = self._s .. 'setLayerScale(' .. self._l[layer] .. ',' .. sx .. ',' .. sy .. ');' 307 + end, 308 + 309 + --- Set a translation applied to the layer as a whole 310 + ---@param layer integer The layer for which the translation will be set 311 + ---@param tx number Translation along the X axis 312 + ---@param ty number Translation along the Y axis 313 + setLayerTranslation = function (self, layer, tx, ty) 314 + self._s = self._s .. 'setLayerTranslation(' .. self._l[layer] .. ',' .. tx .. ',' .. ty .. ');' 315 + end, 316 + 317 + --- Set the fill color of the next rendered shape on the given layer; has no effect on shapes that do not support a fill color 318 + ---@param layer integer The layer to which this property applies 319 + ---@param r number Red component, between 0 and 1 320 + ---@param g number Green component, between 0 and 1 321 + ---@param b number Blue component, between 0 and 1 322 + ---@param a number Alpha component, between 0 and 1 323 + setNextFillColor = function (self, layer, r, g, b, a) 324 + self._s = self._s .. 'setNextFillColor(' .. self._l[layer] .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 325 + end, 326 + 327 + --- Set the rotation of the next rendered shape on the given layer; has no effect on shapes that do not support rotation 328 + ---@param layer integer The layer to which this property applies 329 + ---@param rotation number Rotation, in radians; positive is counter-clockwise, negative is clockwise 330 + setNextRotation = function (self, layer, rotation) 331 + self._s = self._s .. 'setNextRotation(' .. self._l[layer] .. ',' .. rotation .. ');' 332 + end, 333 + 334 + --- Set the rotation of the next rendered shape on the given layer; has no effect on shapes that do not support rotation 335 + ---@param layer integer The layer to which this property applies 336 + ---@param rotation number Rotation, in degrees; positive is counter-clockwise, negative is clockwise 337 + setNextRotationDegrees = function (self, layer, rotation) 338 + self._s = self._s .. 'setNextRotationDegrees(' .. self._l[layer] .. ',' .. rotation .. ');' 339 + end, 340 + 341 + --- Set the shadow of the next rendered shape on the given layer; has no effect on shapes that do not support a shadow 342 + ---@param layer integer The layer to which this property applies 343 + ---@param radius number The distance that the shadow extends from the shape's border 344 + ---@param r number Red component, between 0 and 1 345 + ---@param g number Green component, between 0 and 1 346 + ---@param b number Blue component, between 0 and 1 347 + ---@param a number Alpha component, between 0 and 1 348 + setNextShadow = function (self, layer, radius, r, g, b, a) 349 + self._s = self._s .. 'setNextShadow(' .. self._l[layer] .. ',' .. radius .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 350 + end, 351 + 352 + --- Set the stroke color of the next rendered shape on the given layer; has no effect on shapes that do not support a stroke color 353 + ---@param layer integer The layer to which this property applies 354 + ---@param r number Red component, between 0 and 1 355 + ---@param g number Green component, between 0 and 1 356 + ---@param b number Blue component, between 0 and 1 357 + ---@param a number Alpha component, between 0 and 1 358 + setNextStrokeColor = function (self, layer, r, g, b, a) 359 + self._s = self._s .. 'setNextStrokeColor(' .. self._l[layer] .. ',' .. r .. ',' .. g .. ',' .. b .. ',' .. a .. ');' 360 + end, 361 + 362 + --- Set the stroke width of the next rendered shape on the given layer; has no effect on shapes that do not support a stroke width 363 + ---@param layer integer The layer to which this property applies 364 + ---@param strokeWidth number Stroke width, in pixels 365 + setNextStrokeWidth = function (self, layer, strokeWidth) 366 + self._s = self._s .. 'setNextStrokeWidth(' .. self._l[layer] .. ',' .. strokeWidth .. ');' 367 + end, 368 + 369 + --- Set the text alignment of the next rendered text string on the given layer. 370 + --- By default, text is anchored horizontally on the left, and vertically on the baseline 371 + ---@param layer integer The layer to which this property applies 372 + ---@param alignH AlignH Specifies the horizontal anchoring of a text string relative to the draw coordinates; must be one of the following built-in constants: AlignH_Left, AlignH_Center, AlignH_Right 373 + ---@param alignV AlignV Specifies the vertical anchoring of a text string relative to the draw coordinates; must be one of the following built-in constants: AlignV_Ascender, AlignV_Top, AlignV_Middle, AlignV_Baseline, AlignV_Bottom, AlignV_Descender 374 + setNextTextAlign = function (self, layer, alignH, alignV) 375 + self._s = self._s .. 'setNextTextAlign(' .. self._l[layer] .. ',' .. alignH .. ',' .. alignV .. ');' 376 + end, 377 + 378 + --************************************************************************************************************ 379 + -- Joker function that is here to permit all the things that are not doable with the other functions 380 + --************************************************************************************************************ 381 + 382 + --- Add a line of code to the renderscript as a string 383 + ---@param line string The line of code to add 384 + insertCodeLine = function(self, line) 385 + self._s = self._s .. line .. '\n' 386 + end, 387 + 388 + --************************************************************************************************************ 389 + -- utilities to add to the renderscript that are not by default in game 390 + --************************************************************************************************************ 391 + 392 + --- Return the maximum size of a renderscript 393 + ---@return integer The maximum size of a renderscript, in characters 394 + getMaxSize = function(self) 395 + return 50000 396 + end, 397 + 398 + --- Return whether the renderscript is too long 399 + ---@return boolean Whether the renderscript is too long 400 + isTooLong = function(self) 401 + return #self._s > 50000 402 + end, 403 + 404 + --- Return the current size of the renderscript 405 + ---@param screen Screen The screen to which to send the renderscript 406 + sendToScreen = function(self, screen) 407 + screen.setRenderScript(self._s) 408 + end, 409 + }, 410 + __tostring = function(self) 411 + return self._s 412 + end, 413 + __len = function(self) 414 + return #self._s 415 + end, 416 + }
+1
RenderScript.min.lua
··· 1 + RenderScript={__index={_s="",_l={},_f={},SHAPES={BEZIER=0,BOX=1,BOX_ROUNDED=2,CIRCLE=3,IMAGE=4,LINE=5,POLYGON=6,TEXT=7},ALIGN_H={LEFT=0,CENTER=1,RIGHT=2},ALIGN_V={ASCENDER=0,TOP=1,MIDDLE=2,BASELINE=3,BOTTOM=4,DESCENDER=5},createLayer=function(self)local a='_L'..#self._l+1;self._s=self._s..'local '..a..'=createLayer();'self._l[#self._l+1]=a;return#self._l end,loadFont=function(self,b,c)local d='_F'..#self._f+1;self._f[#self._f+1]=d;self._s=self._s..'local '..d..'=loadFont("'..b..'",'..c..');'end,getCursor=function(self)self._s=self._s..'local _CX,_CY=getCursor();'return'_CX','_CY'end,getResolution=function(self)self._s=self._s..'local _RX,_RY=getResolution();'return'_RX','_RY'end,addBezier=function(self,e,f,g,h,i,j,k)self._s=self._s..'addBezier('..self._l[e]..','..f..','..h..','..g..','..i..','..j..','..k..');'end,addBox=function(self,e,l,m,n,o)self._s=self._s..'addBox('..self._l[e]..','..l..','..m..','..n..','..o..');'end,addBoxRounded=function(self,e,l,m,n,o,p)self._s=self._s..'addBoxRounded('..self._l[e]..','..l..','..m..','..n..','..o..','..p..');'end,addCircle=function(self,e,l,m,p)self._s=self._s..'addCircle('..self._l[e]..','..l..','..m..','..p..');'end,addImage=function(self,e,q,l,m,n,o)self._s=self._s..'addImage('..self._l[e]..','..q..','..l..','..m..','..n..','..o..');'end,addImageSub=function(self,e,q,l,m,n,o,r,s,t,u)self._s=self._s..'addImageSub('..self._l[e]..','..q..','..l..','..m..','..n..','..o..','..r..','..s..','..t..','..u..');'end,addLine=function(self,e,f,g,h,i)self._s=self._s..'addLine('..self._l[e]..','..f..','..g..','..h..','..i..');'end,addQuad=function(self,e,f,g,h,i,j,k,v,w)self._s=self._s..'addQuad('..self._l[e]..','..f..','..g..','..h..','..i..','..j..','..k..','..v..','..w..');'end,addText=function(self,e,x,y,l,m)self._s=self._s..'addText('..self._l[e]..','..self._f[x]..','..y..','..l..','..m..');'end,addTriangle=function(self,e,f,g,h,i,j,k)self._s=self._s..'addTriangle('..self._l[e]..','..f..','..g..','..h..','..i..','..j..','..k..');'end,setBackgroundColor=function(self,p,z,A)self._s=self._s..'setBackgroundColor('..p..','..z..','..A..');'end,setDefaultFillColor=function(self,e,B,p,z,A,C)self._s=self._s..'setDefaultFillColor('..self._l[e]..','..B..','..p..','..z..','..A..','..C..');'end,setDefaultRotation=function(self,e,B,D)self._s=self._s..'setDefaultRotation('..self._l[e]..','..B..','..D..');'end,setDefaultShadow=function(self,e,B,E,p,z,A,C)self._s=self._s..'setDefaultShadow('..self._l[e]..','..B..','..E..','..p..','..z..','..A..','..C..');'end,setDefaultStrokeColor=function(self,e,B,p,z,A,C)self._s=self._s..'setDefaultStrokeColor('..self._l[e]..','..B..','..p..','..z..','..A..','..C..');'end,setDefaultStrokeWidth=function(self,e,B,F)self._s=self._s..'setDefaultStrokeWidth('..self._l[e]..','..B..','..F..');'end,setDefaultTextAlign=function(self,e,G,H)self._s=self._s..'setDefaultTextAlign('..self._l[e]..','..G..','..H..');'end,setFontSize=function(x,c)self._s=self._s..'setFontSize('..self._f[x]..','..c..');'end,setLayerClipRect=function(self,e,l,m,n,o)self._s=self._s..'setLayerClipRect('..self._l[e]..','..l..','..m..','..n..','..o..');'end,setLayerOrigin=function(self,e,l,m)self._s=self._s..'setLayerOrigin('..self._l[e]..','..l..','..m..');'end,setLayerRotation=function(self,e,D)self._s=self._s..'setLayerRotation('..self._l[e]..','..D..');'end,setLayerScale=function(self,e,n,o)self._s=self._s..'setLayerScale('..self._l[e]..','..n..','..o..');'end,setLayerTranslation=function(self,e,I,J)self._s=self._s..'setLayerTranslation('..self._l[e]..','..I..','..J..');'end,setNextFillColor=function(self,e,p,z,A,C)self._s=self._s..'setNextFillColor('..self._l[e]..','..p..','..z..','..A..','..C..');'end,setNextRotation=function(self,e,D)self._s=self._s..'setNextRotation('..self._l[e]..','..D..');'end,setNextRotationDegrees=function(self,e,D)self._s=self._s..'setNextRotationDegrees('..self._l[e]..','..D..');'end,setNextShadow=function(self,e,E,p,z,A,C)self._s=self._s..'setNextShadow('..self._l[e]..','..E..','..p..','..z..','..A..','..C..');'end,setNextStrokeColor=function(self,e,p,z,A,C)self._s=self._s..'setNextStrokeColor('..self._l[e]..','..p..','..z..','..A..','..C..');'end,setNextStrokeWidth=function(self,e,F)self._s=self._s..'setNextStrokeWidth('..self._l[e]..','..F..');'end,setNextTextAlign=function(self,e,G,H)self._s=self._s..'setNextTextAlign('..self._l[e]..','..G..','..H..');'end,insertCodeLine=function(self,K)self._s=self._s..K..'\n'end,getMaxSize=function(self)return 50000 end,isTooLong=function(self)return#self._s>50000 end,sendToScreen=function(self,L)L.setRenderScript(self._s)end},__tostring=function(self)return self._s end,__len=function(self)return#self._s end}