Lost Lily/Grid ToolkitDocs 1.0
Table of Contents

Custom selection patterns

Use case

Use this contract when a reusable topology-aware query cannot be expressed by the built-in single, radius, ring, line, or offset patterns.

Contract and ownership

The Select(...) method on IGridSelectionPattern receives an immutable definition and origin and returns a detached GridSelection.

Copy coordinates into the result. Do not retain mutable state, mutate the definition, or publish visual feedback from the pattern.

Implementation

Excerpt — select alternating cells with a custom pattern. Tested using public APIs.

public sealed class CheckerboardSelectionPattern : IGridSelectionPattern
{
    public GridSelection Select(
        GridBoardDefinition definition,
        GridCoordinate origin)
    {
        GridSelection nearby = GridSelectionPatterns
            .Radius(maxDistance: 2)
            .Select(definition, origin);
        return nearby.Where(coordinate =>
            coordinate is SquareGridCoordinate square &&
            (square.X + square.Y) % 2 == 0);
    }
}

The example delegates topology traversal to the built-in radius pattern and adds a deterministic checkerboard filter.

Registration

Patterns are ordinary values. Construct them in the gameplay system that owns targeting rules or expose serializable configuration that builds them.

Verification

Reject incompatible origins early. Ensure result coordinates belong to the definition and remove duplicates while preserving a deterministic order.

Tests

Cover origin handling, edges, empty boards, ordering, duplicate elimination, and every supported topology.

Done when

The pattern returns deterministic, normalized coordinates for the same definition and remains detached from mutable board state.