Source: resources/modules/xs/tools.wren
Utility functions and helpers for common operations
static initialize() ↗Initializes the random number generator
static toList(range: Range) -> List ↗Converts a range to a list
static toList(from: Num, to: Num) -> List ↗Creates a list of numbers from 'from' to 'to'
static removeFromList(list: List, element) ↗Removes the first occurrence of an element from a list
static pickOne(list: List) ↗Returns a random element from the list
static random -> Random ↗Gets the shared random number generator
Builder class for creating custom mesh shapes with vertices, texture coordinates, and triangle indices
Important: Position and texture arrays must have the same number of elements (each representing x,y pairs)
Indices must be divisible by 3 (triangles) and reference valid vertex indices
construct new() ↗Creates a new empty ShapeBuilder
Use addPosition(), addTexture(), and addIndex() to build the mesh, then call build() to create the shape
addPosition(position: Vec2) ↗Adds a position vertex from a Vec2
Must be paired with a corresponding addTexture() call to maintain equal array lengths
addPosition(x: Num, y: Num) ↗Adds a position vertex from coordinates
Must be paired with a corresponding addTexture() call to maintain equal array lengths
addTexture(texture: Vec2) ↗Adds a texture coordinate from a Vec2
UV coordinates should be normalized (0.0 to 1.0)
Must be paired with a corresponding addPosition() call to maintain equal array lengths
addTexture(x: Num, y: Num) ↗Adds a texture coordinate from UV values
UV coordinates should be normalized (0.0 to 1.0)
Must be paired with a corresponding addPosition() call to maintain equal array lengths
addIndex(index: Num) ↗Adds a triangle index referencing a vertex by its order
Indices must form complete triangles (count must be divisible by 3)
Each index must be >= 0 and < number of vertices added
validate() -> Bool ↗Validates that the shape data is correct
Checks: position/texture arrays are equal length, indices are divisible by 3, indices are in valid range
build(image: Num) ↗Builds and returns the shape with the given texture image, or null if validation fails
Returns null if position/texture counts don't match, indices aren't divisible by 3, or indices are out of range
Builder class for creating procedural images from pixel data
Pixels are packed RGBA values — use ImageBuilder.pack(r, g, b, a) to create them
construct new(width, height) ↗Creates a new image builder with the given dimensions, filled with opaque black
width ↗Image width in pixels
height ↗Image height in pixels
static pack(r, g, b, a) ↗Packs r, g, b, a (0-255 each) into a single pixel value
setPixel(x, y, color) ↗Sets a pixel at (x, y) to the given packed color value
getPixel(x, y) ↗Gets the packed color value at (x, y)
fill(color) ↗Fills the entire image with a packed color value
build() ↗Builds the image and returns an image ID for use with Render.createSprite()