pixi-reels

HoldAndWinState\<TData\>

pixi-reels


pixi-reels / index / HoldAndWinState

Class: HoldAndWinState<TData>

Defined in: board/HoldAndWinState.ts:24

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 and the feature HwPhase; every derived value (freeCells, isFull) is computed from the one ledger, 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×landendWave), 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 ParameterDefault type
TDataunknown

Constructors

Constructor

new HoldAndWinState<TData>(allCells: HwCell[], defaultRespins: number): HoldAndWinState<TData>;

Defined in: board/HoldAndWinState.ts:34

Parameters

ParameterType
allCellsHwCell[]
defaultRespinsnumber

Returns

HoldAndWinState<TData>

Accessors

capacity

Get Signature

get capacity(): number;

Defined in: board/HoldAndWinState.ts:51

Returns

number


isFull

Get Signature

get isFull(): boolean;

Defined in: board/HoldAndWinState.ts:54

Returns

boolean


phase

Get Signature

get phase(): HwPhase;

Defined in: board/HoldAndWinState.ts:42

Returns

HwPhase


respinsLeft

Get Signature

get respinsLeft(): number;

Defined in: board/HoldAndWinState.ts:45

Returns

number


round

Get Signature

get round(): number;

Defined in: board/HoldAndWinState.ts:48

Returns

number

Methods

abortWave()

abortWave(): void;

Defined in: board/HoldAndWinState.ts:193

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


beginWave()

beginWave(hits: HwCoin<TData>[]): {
  hitByKey: Map<string, HwCoin<TData>>;
  round: number;
  spinning: HwCell[];
};

Defined in: board/HoldAndWinState.ts:105

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

ParameterType
hitsHwCoin<TData>[]

Returns

{
  hitByKey: Map<string, HwCoin<TData>>;
  round: number;
  spinning: HwCell[];
}
NameTypeDefined in
hitByKeyMap<string, HwCoin<TData>>board/HoldAndWinState.ts:108
roundnumberboard/HoldAndWinState.ts:106
spinningHwCell[]board/HoldAndWinState.ts:107

coinAt()

coinAt(cell: HwCell): HwCoin<TData> | undefined;

Defined in: board/HoldAndWinState.ts:70

Parameters

ParameterType
cellHwCell

Returns

HwCoin<TData> | undefined


endWave()

endWave(): {
  effects: HwEffect<TData>[];
  landed: HwCoin<TData>[];
};

Defined in: board/HoldAndWinState.ts:154

Close the wave: resolve the counter, detect full / feature end.

Returns

{
  effects: HwEffect<TData>[];
  landed: HwCoin<TData>[];
}
NameTypeDefined in
effectsHwEffect<TData>[]board/HoldAndWinState.ts:154
landedHwCoin<TData>[]board/HoldAndWinState.ts:154

enter()

enter(seed: HwCoin<TData>[]): HwEffect<TData>[];

Defined in: board/HoldAndWinState.ts:77

Seed the trigger coins and arm the counter. Idle → active.

Parameters

ParameterType
seedHwCoin<TData>[]

Returns

HwEffect<TData>[]


freeCells()

freeCells(): HwCell[];

Defined in: board/HoldAndWinState.ts:62

Returns

HwCell[]


isLocked()

isLocked(cell: HwCell): boolean;

Defined in: board/HoldAndWinState.ts:66

Parameters

ParameterType
cellHwCell

Returns

boolean


land()

land(cell: HwCell, coin: HwCoin<TData> | null): HwEffect<TData>[];

Defined in: board/HoldAndWinState.ts:133

Record one cell’s landing. coin is null on a miss.

Parameters

ParameterType
cellHwCell
coinHwCoin<TData> | null

Returns

HwEffect<TData>[]


lockedCoins()

lockedCoins(): HwCoin<TData>[];

Defined in: board/HoldAndWinState.ts:58

Returns

HwCoin<TData>[]


release()

release(cells: HwCell[]): {
  effects: HwEffect<TData>[];
  released: HwCoin<TData>[];
};

Defined in: board/HoldAndWinState.ts:200

Remove locked coins — the collect moment.

Parameters

ParameterType
cellsHwCell[]

Returns

{
  effects: HwEffect<TData>[];
  released: HwCoin<TData>[];
}
NameTypeDefined in
effectsHwEffect<TData>[]board/HoldAndWinState.ts:200
releasedHwCoin<TData>[]board/HoldAndWinState.ts:200

reset()

reset(): HwEffect<TData>[];

Defined in: board/HoldAndWinState.ts:238

Hard clear back to idle. Fires feature:reset, never coin:released.

Returns

HwEffect<TData>[]


swap()

swap(
   cell: HwCell, 
   id: string, 
   data: TData | undefined): void;

Defined in: board/HoldAndWinState.ts:223

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

ParameterType
cellHwCell
idstring
dataTData | undefined

Returns

void