Lost Lily/Grid ToolkitDocs 1.0
Table of Contents

Move, rotate, and sort items

When to use

Use these actions to rearrange placed Inventory items without moving them to another board. Each action needs a structure-definition resolver so it can rebuild the item footprint safely.

Before you start

Start with the authored board and structure library from Add Inventory to a board in Unity. The excerpts assume state, definitionResolver, instanceId, targetCoordinate, and targetOrientation are available.

Procedure

Move one item

GridInventoryMoveItemAction keeps the same instance ID and quantity while changing its anchor and, optionally, orientation.

Excerpt — move one item while preserving its identity. Tested using public APIs.

public static GridActionResult MoveItem(
    GridBoardState state,
    IGridStructureDefinitionResolver definitionResolver,
    string instanceId,
    GridCoordinate targetCoordinate,
    out GridActionResult preview)
{
    IGridAction action = new GridInventoryMoveItemAction(
        definitionResolver,
        instanceId,
        targetCoordinate);
    preview = GridActionRunner.Preview(state, action);
    return preview.Success
        ? GridActionRunner.Apply(state, action)
        : preview;
}

Rotate one item

Rotation rebuilds the footprint around the existing anchor. The definition must allow orientation, and every rotated cell must fit the board and its occupancy rules.

Excerpt — rotate one item around its current anchor. Tested using public APIs.

public static GridActionResult RotateItem(
    GridBoardState state,
    IGridStructureDefinitionResolver definitionResolver,
    string instanceId,
    GridOrientation targetOrientation,
    out GridActionResult preview)
{
    IGridAction action = new GridInventoryRotateItemAction(
        definitionResolver,
        instanceId,
        targetOrientation);
    preview = GridActionRunner.Preview(state, action);
    return preview.Success
        ? GridActionRunner.Apply(state, action)
        : preview;
}

Sort Inventory items

GridInventorySortAction plans the whole sort before committing. Non-Inventory structures remain in place. Enable rotate-to-fit only when the topology supplies an orientation sequence or you pass explicit candidate orientations.

Excerpt — sort Inventory items atomically. Tested using public APIs.

public static GridActionResult SortItems(
    GridBoardState state,
    IGridStructureDefinitionResolver definitionResolver,
    bool allowRotateToFit,
    out GridActionResult preview)
{
    IGridAction action = new GridInventorySortAction(
        definitionResolver,
        new GridInventorySortOptions(allowRotateToFit));
    preview = GridActionRunner.Preview(state, action);
    return preview.Success
        ? GridActionRunner.Apply(state, action)
        : preview;
}

Result

A successful operation advances revision once and publishes one event batch, even when sorting repositions several items. A rejected move, rotation, or sort leaves the complete board unchanged and returns the affected cells and failure diagnostics.

Troubleshooting

Symptom Check
Move or rotation is rejected. Inspect target cells, topology, footprint, occupancy, and definition resolution.
Sort ignores a structure. Only structures whose definitions contain Inventory metadata participate.
Rotate-to-fit is rejected. Supply explicit candidates or use a topology whose orientation system implements an orientation sequence.