Containers

Source: resources/modules/xs/containers.wren


Class Grid ↗

Logical representation of a (game) grid

construct new(width: Num, height: Num, zero) ↗

Creates a new grid with the given dimensions, filled with a default value

width -> Num ↗

The number of columns in the grid.

height -> Num ↗

The number of rows in the grid.

swapValues(x1: Num, y1: Num, x2: Num, y2: Num) -> Bool ↗

Swaps the values of two given grid cells.

valid(x: Num, y: Num) -> Bool ↗

Checks if a given cell position exists in the grid.

[x: Num, y: Num] ↗

Returns the value stored at the given grid cell.

[x: Num, y: Num]=(v) ↗

Assigns a given value to a given grid cell.

[coord: Vec2] ↗

Get using a coordinate pair.

[coord: Vec2]=(v) ↗

Assign using a coordinate pair.

toString -> String ↗

Constructs a string representation of this grid.


Class SparseGrid ↗

Logical representation of a grid with many empty spaces

construct new() ↗

Creates a new empty sparse grid

static makeId(x: Num, y: Num) -> Num ↗

Creates a unique identifier for a given cell position.

has(x: Num, y: Num) -> Bool ↗

Checks if a given cell position exists in the grid.

remove(x: Num, y: Num) ↗

Removes the value stored at the given grid cell.

[x: Num, y: Num] ↗

Returns the value stored at the given grid cell.

[x: Num, y: Num]=(v) ↗

Assigns a given value to a given grid cell.

clear() ↗

Clears the grid.

values -> Sequence ↗

Returns the values stored in the grid.


Class Queue ↗

First-in-first-out (FIFO) data structure

construct new() ↗

Creates a new empty queue

push(val) ↗

Adds a value to the back of the queue

pop() ↗

Removes and returns the value from the front of the queue

empty() -> Bool ↗

Checks if the queue is empty


Class Dequeue ↗

Last-in-first-out (LIFO) data structure (stack)

construct new() ↗

Creates a new empty dequeue

push(val) ↗

Adds a value to the top of the stack

pop() ↗

Removes and returns the value from the top of the stack

empty() -> Bool ↗

Checks if the dequeue is empty


Class RingBuffer ↗

A simple ring buffer (circular buffer) implementation

construct new(size: Num, value) ↗

Creates a new ring buffer of the given size, filled with a default value

push(value) ↗

Adds a value to the buffer, overwriting the oldest value if full

peek() ↗

Returns the most recently added value

[index: Num] ↗

Gets a value at the given offset from the current position

size -> Num ↗

Gets the size of the ring buffer