HoldAndWinState\<TData = `unknown`\>
pixi-reels / index / HoldAndWinState
Class: HoldAndWinState<TData = unknown>
Defined in: board/HoldAndWinState.ts:25
The pure Hold & Win state machine - the single source of truth for board
state, with zero PixiJS. It owns the locked-coin ledger, the respin
counter, the round number, the set of dormant cells and the feature
HwPhase; every derived value (freeCells, isFull, capacity) is
computed from that state, never stored in parallel, so nothing can drift
out of sync.
It is a reducer, not a cache: HoldAndWinBoard drives the reels and
reports each landing here; the methods mutate the ledger and return the
ordered list of HwEffects to emit, which the driver replays onto its
event emitter (and uses to fire visual side effects like playWin()). Locks
happen progressively as cells land in stagger order, so this is an
incremental reducer (beginWave → N×land → endWave),
not a one-shot reduce(state, hits).
Being PixiJS-free, it is fully unit-testable: assert the returned effect sequence for hit / miss / full / release / reset / error paths.
Type Parameters#
| Type Parameter | Default type |
|---|---|
TData | unknown |
Constructors#
Constructor#
new HoldAndWinState<TData = unknown>(
allCells: HwCell[],
defaultRespins: number,
inactive?: HwCell[]
): HoldAndWinState<TData>;
Defined in: board/HoldAndWinState.ts:42
inactive cells exist in the grid but take no part in the feature until
activated: they never spin, never take a coin, and do not count
toward capacity. reset() puts them back to dormant.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
allCells | HwCell[] | undefined |
defaultRespins | number | undefined |
inactive | HwCell[] | [] |
Returns#
HoldAndWinState<TData>
Accessors#
capacity#
Get Signature#
get capacity(): number;
Defined in: board/HoldAndWinState.ts:67
Number of active cells - what isFull is measured against.
Returns
number
isFull#
Get Signature#
get isFull(): boolean;
Defined in: board/HoldAndWinState.ts:70
Returns
boolean
phase#
Get Signature#
get phase(): HwPhase;
Defined in: board/HoldAndWinState.ts:57
Returns
respinsLeft#
Get Signature#
get respinsLeft(): number;
Defined in: board/HoldAndWinState.ts:60
Returns
number
round#
Get Signature#
get round(): number;
Defined in: board/HoldAndWinState.ts:63
Returns
number
Methods#
abortWave()#
abortWave(): void;
Defined in: board/HoldAndWinState.ts:222
Abandon an in-flight wave after a driver error: restore the phase from
spinning back to active so a thrown spin doesn’t strand the board (every
later beginWave would otherwise throw “wave in flight”). Cells that already
landed stay locked; the caller decides whether to retry or reset.
Returns#
void
activate()#
activate(cells: HwCell[]): HwEffect<TData>[];
Defined in: board/HoldAndWinState.ts:251
Wake dormant cells: from now on they spin with the free cells and count
toward capacity. Already-active cells are ignored. Not allowed mid-wave -
the spinning set was fixed when the wave began.
Parameters#
| Parameter | Type |
|---|---|
cells | HwCell[] |
Returns#
HwEffect<TData>[]
beginWave()#
beginWave(hits: HwCoin<TData>[]): {
hitByKey: Map<string, HwCoin<TData>>;
round: number;
spinning: HwCell[];
};
Defined in: board/HoldAndWinState.ts:134
Open a wave: validate the hits, mark every free cell as spinning, bump the
round. Returns the data the driver needs to emit respin:start and to land
each cell. Active → spinning.
Parameters#
| Parameter | Type |
|---|---|
hits | HwCoin<TData>[] |
Returns#
{
hitByKey: Map<string, HwCoin<TData>>;
round: number;
spinning: HwCell[];
}
| Name | Type | Defined in |
|---|---|---|
hitByKey | Map<string, HwCoin<TData>> | board/HoldAndWinState.ts:137 |
round | number | board/HoldAndWinState.ts:135 |
spinning | HwCell[] | board/HoldAndWinState.ts:136 |
coinAt()#
coinAt(cell: HwCell): HwCoin<TData> | undefined;
Defined in: board/HoldAndWinState.ts:99
Parameters#
| Parameter | Type |
|---|---|
cell | HwCell |
Returns#
HwCoin<TData> | undefined
endWave()#
endWave(): {
effects: HwEffect<TData>[];
landed: HwCoin<TData>[];
};
Defined in: board/HoldAndWinState.ts:183
Close the wave: resolve the counter, detect full / feature end.
Returns#
{
effects: HwEffect<TData>[];
landed: HwCoin<TData>[];
}
| Name | Type | Defined in |
|---|---|---|
effects | HwEffect<TData>[] | board/HoldAndWinState.ts:183 |
landed | HwCoin<TData>[] | board/HoldAndWinState.ts:183 |
enter()#
enter(seed: HwCoin<TData>[]): HwEffect<TData>[];
Defined in: board/HoldAndWinState.ts:106
Seed the trigger coins and arm the counter. Idle → active.
Parameters#
| Parameter | Type |
|---|---|
seed | HwCoin<TData>[] |
Returns#
HwEffect<TData>[]
freeCells()#
freeCells(): HwCell[];
Defined in: board/HoldAndWinState.ts:79
Active cells with no coin.
Returns#
HwCell[]
inactiveCells()#
inactiveCells(): HwCell[];
Defined in: board/HoldAndWinState.ts:87
Cells that are dormant right now.
Returns#
HwCell[]
isActive()#
isActive(cell: HwCell): boolean;
Defined in: board/HoldAndWinState.ts:91
Parameters#
| Parameter | Type |
|---|---|
cell | HwCell |
Returns#
boolean
isLocked()#
isLocked(cell: HwCell): boolean;
Defined in: board/HoldAndWinState.ts:95
Parameters#
| Parameter | Type |
|---|---|
cell | HwCell |
Returns#
boolean
land()#
land(cell: HwCell, coin: HwCoin<TData> | null): HwEffect<TData>[];
Defined in: board/HoldAndWinState.ts:162
Record one cell’s landing. coin is null on a miss.
Parameters#
| Parameter | Type |
|---|---|
cell | HwCell |
coin | HwCoin<TData> | null |
Returns#
HwEffect<TData>[]
lockedCoins()#
lockedCoins(): HwCoin<TData>[];
Defined in: board/HoldAndWinState.ts:74
Returns#
HwCoin<TData>[]
release()#
release(cells: HwCell[]): {
effects: HwEffect<TData>[];
released: HwCoin<TData>[];
};
Defined in: board/HoldAndWinState.ts:229
Remove locked coins - the collect moment.
Parameters#
| Parameter | Type |
|---|---|
cells | HwCell[] |
Returns#
{
effects: HwEffect<TData>[];
released: HwCoin<TData>[];
}
| Name | Type | Defined in |
|---|---|---|
effects | HwEffect<TData>[] | board/HoldAndWinState.ts:229 |
released | HwCoin<TData>[] | board/HoldAndWinState.ts:229 |
reset()#
reset(): HwEffect<TData>[];
Defined in: board/HoldAndWinState.ts:291
Hard clear back to idle. Fires feature:reset, never coin:released.
Cells activated during the feature go dormant again.
Returns#
HwEffect<TData>[]
swap()#
swap(
cell: HwCell,
id: string,
data: TData | undefined
): void;
Defined in: board/HoldAndWinState.ts:273
Rewrite a locked cell’s coin identity in place (coin → jackpot, mini →
major). Throws on a free cell - placing a brand-new tracked coin out of a
spin is enter/respin’s job; for purely decorative art on a free cell use
the cell’s reel directly.
Parameters#
| Parameter | Type |
|---|---|
cell | HwCell |
id | string |
data | TData | undefined |
Returns#
void