Tools

Source: assets/modules/xs_tools.wren


Class Tools

Utility functions and helpers for common operations

static initialize()

Initializes the random number generator

static toList(range)

Converts a range to a list

static toList(from, to)

Creates a list of numbers from 'from' to 'to'

static removeFromList(list, element)

Removes the first occurrence of an element from a list

static pickOne(list)

Returns a random element from the list

static random

Gets the shared random number generator


Class ShapeBuilder

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)

Adds a position vertex from a Vec2

Must be paired with a corresponding addTexture() call to maintain equal array lengths

addPosition(x, y)

Adds a position vertex from coordinates

Must be paired with a corresponding addTexture() call to maintain equal array lengths

addTexture(texture)

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, y)

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)

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()

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)

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