Reference
Migrating to 2.0.0
Run the codemod first. It has not reached npm yet, so run it from a clone of this repo:
git clone https://github.com/schmooky/pixi-reels
cd pixi-reels && pnpm install
node packages/pixi-reels-codemod/bin/cli.js v1-to-v2 /path/to/your/src
Add --dry --print to see the rewrite without touching anything. The codemod
edits in place, so commit before you run it for real. Then read this page for
the things a codemod cannot do.
Why any of this#
v2 has one engine for four layouts: vertical or horizontal, forward or reverse. Once a strip can run sideways, “row” stops describing anything, so a reel’s strip is made of cells, and the off-window slots at either side are start and end.
Start and end are geometric. Start is the smaller screen coordinate (above on a vertical reel, left on a horizontal one), whichever way the reel travels. They do not follow travel because a buffer symbol is presentation, a coin peeking above the top row, and flipping a reel’s direction must not move that coin to the opposite edge.
There are no deprecated aliases. A v1 name either fails to compile or throws
with a message naming its replacement. A quiet alias would let a bufferAbove
that now means something different reach production.
Geometry#
Before:
new ReelSetBuilder()
.reels(5)
.visibleRows(3)
.visibleRowsPerReel([3, 5, 5, 5, 3])
.reelPixelHeights([300, 500, 500, 500, 300])
.reelAnchor('bottom') // or 'top'
.bufferSymbols({ above: 1, below: 0 });
After:
new ReelSetBuilder()
.reels(5)
.visibleCells(3)
.visibleCellsPerReel([3, 5, 5, 5, 3])
.reelExtents([300, 500, 500, 500, 300])
.reelAnchor('end') // or 'start'
.bufferSymbols({ start: 1, end: 0 });
On Reel: reelHeight is extent, offsetY is mainOffset,
spinSymbolHeight is spinCellSize, bufferAbove / bufferBelow are
bufferStart / bufferEnd.
Reel.symbolWidth and Reel.symbolHeight are unchanged. They are the
screen-space pair you hand to ReelSymbol.resize(width, height), and
screen-space inputs stay screen-space in v2.
MultiWays#
All three keys were renamed, and the builder throws on the old ones:
// Before
builder.multiways({ minRows: 2, maxRows: 7, reelPixelHeight: 700 });
// After
builder.multiways({ minCells: 2, maxCells: 7, reelExtent: 700 });
setShape() takes the same array, cells per reel.
Result grids#
Before:
reelSet.setResult([
{ visible: ['A', 'B', 'C'], bufferAbove: ['COIN'], bufferBelow: ['X'] },
]);
After:
reelSet.setResult([
{ visible: ['A', 'B', 'C'], bufferStart: ['COIN'], bufferEnd: ['X'] },
]);
A ColumnTarget now travels unchanged all the way down to the reel. The
internal negative-index encoding, arr[-1] for a buffer-above slot, is gone.
In a custom frame middleware, FrameContext.targetSymbols (a string[]) is
now FrameContext.target (a ColumnTarget). Read one cell of it with
getTargetSlot(target, cell), or materialize the strip with
columnTargetToStrip(target, bufferStart).
Reel.placeSymbols takes a ColumnTarget instead of a string[]. If you
had a full strip frame, buffers included, use the new Reel.placeStrip.
Coordinates#
Every (col, row) pair is now (reel, cell):
Before:
reelSet.pin(2, 1, 'wild');
const p = reelSet.getPin(2, 1);
console.log(p.col, p.row, p.originRow);
reelSet.events.on('cascade:chain:end', (e) => e.winners.forEach((w) => w.row));
reelSet.events.on('pin:migrated', (m) => console.log(m.fromRow, m.toRow));
After:
reelSet.pin(2, 1, 'wild');
const p = reelSet.getPin(2, 1);
console.log(p.reel, p.cell, p.originCell);
reelSet.events.on('cascade:chain:end', (e) => e.winners.forEach((w) => w.cell));
reelSet.events.on('pin:migrated', (m) => console.log(m.fromCell, m.toCell));
The positional arguments did not move, only the names. SymbolPosition.rowIndex
is cellIndex, and it gains an optional setId for a game that composes more
than one reel set.
BoardGrid and HoldAndWinBoard keep cols and rows as board dimensions,
because a board is a real 2-D grid. Only their cell coordinates changed:
BoardCell and HwCell are { reel, cell }.
Big symbols#
SymbolData.size was { w, h }, which became ambiguous once a reel could run
sideways. It is now { reels, cells }: reels spans columns and cells spans
the strip, in every orientation.
Before:
builder.symbolData({ bonus: { weight: 0, size: { w: 2, h: 2 } } });
const fp = reelSet.getSymbolFootprint(2, 1);
console.log(fp.anchor.col, fp.size.w);
After:
builder.symbolData({ bonus: { weight: 0, size: { reels: 2, cells: 2 } } });
const fp = reelSet.getSymbolFootprint(2, 1);
console.log(fp.anchor.reel, fp.size.reels);
getBlockBounds still returns screen-space { x, y, width, height }.
One restriction is new. A cross-reel block (size.reels > 1) cannot be
combined with a mixed directionPerReel([...]). The coordinator assumes one
shared feed edge across the reels a block covers, so build() throws instead
of shipping a block that would split at run time. Use a single direction(),
or keep blocks within one reel.
Cascades#
Before:
builder.tumble({
fall: { rowStagger: 40, rowOrder: 'bottomToTop' },
dropIn: { rowStagger: 30, rowOrder: 'topToBottom' },
});
reelSet.events.on('cascade:place:end', (e) => console.log(e.winnerRows));
After:
builder.tumble({
fall: { cellStagger: 40, cellOrder: 'endFirst' },
dropIn: { cellStagger: 30, cellOrder: 'startFirst' },
});
reelSet.events.on('cascade:place:end', (e) => console.log(e.winnerCells));
'endFirst' is what 'bottomToTop' meant: the cell at the gravity-exit
edge moves first. DropOffset.originalRow / .offsetRows are
.originalCell / .offsetCells.
DropOffset also gains isNew. If you branched on originalCell < 0 to
tell an arriving symbol from a surviving one, switch to isNew. The sign
test only holds under forward gravity.
Cascades on a reverse or horizontal set#
tumble() takes a gravity option. The default, 'auto', follows each
reel’s own direction, so a reverse or horizontal cascade needs nothing extra.
Set it only when the tumble should settle against the reel’s travel:
builder.direction('reverse').tumble({}); // drains up, refills from below
builder.orientation('horizontal').tumble({}); // drains right, refills from the left
builder.tumble({ gravity: 'reverse' }); // spin one way, drop the other
Whichever edge gravity exits by is the edge your server must pack survivors
against in the grids it returns. The engine animates the result and does not
reorder it. On a 'reverse' cascade that means survivors first and new
symbols at the end of each column, the mirror of the v1 convention.
Nudge#
direction is now relative to the reel’s own axis, not to the screen:
Before:
await reelSet.nudge(2, { distance: 1, direction: 'down', incoming: ['wild'] });
After:
await reelSet.nudge(2, { distance: 1, direction: 'forward', incoming: ['wild'] });
'up' became 'reverse' by the same rule. NudgeOptions.direction is
'forward' | 'reverse', with no screen-relative values left.
On a vertical forward reel these are the same motion. On a reel built with
direction('reverse'), 'forward' now travels the way that reel spins and
feeds from the matching edge. In v1 it always fed from the top.
Motion internals#
If you wrote a custom SpinningMode or phase:
| v1 | v2 |
|---|---|
ReelMotion.displace(deltaY) | .advance(travelDelta), a signed travel distance, not screen pixels |
ReelMotion.slotHeight | .slotPitch |
ReelMotion.getRowY(row) | .getCellMain(cell) |
SpinningMode.computeDeltaY(symbolHeight, ...) | .computeDelta(slotPitch, ...) |
A positive travelDelta means forward for this reel, and the axis turns that
into a screen direction. Your mode no longer needs to know which way the reel
points.
ReelMotion’s wrap callback lost its arrayIndex and direction
arguments. Nothing read them; the consumer derives position from the symbol
itself.
Offsets#
OffsetXMode is CrossOffsetMode, and the trapezoid’s
topWidthFactor / bottomWidthFactor are startFactor / endFactor.
The horizontal reel classes are gone#
HorizontalReel, HorizontalReelBuilder, HorizontalReelConfig,
HorizontalDirection and HorizontalReelEvents were deleted. A sideways
banner is now a ReelSet whose strip travels along X.
// Before
const banner = new HorizontalReelBuilder()
.visibleCount(5)
.symbols((r) => { /* ... */ })
.ticker(app.ticker)
.build();
// After
const banner = new ReelSetBuilder()
.orientation('horizontal')
.reels(1) // one strip
.visibleCells(5) // 5 symbols along it
.symbols((r) => { /* ... */ })
.ticker(app.ticker)
.build();
Everything else carries over. spin() returns the same promise,
setResult([{ visible: ids }]) takes the same ColumnTarget[], and
refill, runCascade and destroySymbols work on it as on the main board.
Add the built set to the stage yourself; there is no composition layer.
The codemod does not rewrite this one, because the shapes are too different. It is the one migration you do by hand.
Motion blur follows travel now#
MotionBlurOptions.axis used to default to 'y', and its docs told you to
pass { axis: 'x' } for a HorizontalReel, the class that no longer exists.
A horizontal set using StaticSpinSymbol therefore smeared across its
direction of travel, with no warning.
The axis now defaults to the owning set’s orientation. If you passed
{ axis: 'x' } to work around the old default, delete it. If you want a
cross-smear, keep it; an explicit value still wins.
Custom mask strategies#
This only matters if you passed your own maskStrategy(...). The two built-in
strategies are unchanged.
Both methods now take a single MaskContext instead of positional
arguments, and the context carries the axis:
Before:
const strategy: MaskStrategy = {
build: (rects, totalWidth, totalHeight) => { /* ... */ },
update: (g, rects, totalWidth, totalHeight) => { /* ... */ },
};
After:
import { MASK_STRATEGY_VERSION, type MaskStrategy } from 'pixi-reels';
const strategy: MaskStrategy = {
version: MASK_STRATEGY_VERSION,
build: ({ rects, width, height, axis }) => { /* ... */ },
update: (g, { rects, width, height, axis }) => { /* ... */ },
};
maskStrategy() throws on any strategy that does not declare version 2. The
field is there because a ReelMaskRect is screen-space: on a vertical set the
strip runs along y and height, on a horizontal set along x and width.
A v1 strategy written for one rect per column, with height equal to the
visible window, would receive the same struct with a transposed meaning and no
compile error to catch it. A v1 strategy handed a MaskContext would also read
rects as an object, find no .length, and draw a full-bleed rect that clips
nothing.
If your strategy unions the rects it is given and assumes no axis, adding the
field is the whole migration. If it assumes an axis, branch on axis.mainProp
or axis.toLocal(width, height).
gsap is now per reel set#
v1 kept one gsap instance in a module global; the last setGsap call won.
With a single ReelSet that was harmless. With two, the second build()
moved the first set’s tweens onto a different timeline without warning.
builder.gsap(instance) now binds that set only, at build() time. Nothing
changes for a single-set game that never calls it.
Two consequences:
// Before: driveGsapWithTicker looked the instance up from the global.
const stop = driveGsapWithTicker(app.ticker);
// After: pass the SAME instance you gave the builder.
const stop = driveGsapWithTicker(app.ticker, myGsap);
Omit the second argument only if you never called .gsap(...) either.
In a custom ReelSymbol subclass, animate on this.gsap rather than an
imported gsap:
class MySymbol extends ReelSymbol {
async playWin() {
// `this.gsap` is the owning set's instance, bound by SymbolFactory.
await this.gsap.to(this.view.scale, { x: 1.2, y: 1.2, duration: 0.2 });
}
}
An imported gsap still works when your app and the engine resolve to the
same module. this.gsap is correct whether they do or not.
Render order#
This one is new and optional. cellStacking and reelStacking make render
order explicit:
builder.cellStacking('ascending').reelStacking('ascending'); // the defaults
'ascending' is the v1 behaviour: the cell or reel at the larger coordinate
draws in front. The order is geometric, so direction('reverse') does not
flip it. Art lit from above keeps overlapping the way it was drawn, and a
per-spin reversal tease does not re-layer the board. Pass 'descending' if
your art wants the opposite.
Cascade grids are validated now#
refill() and runCascade()’s nextGrid run the same checks setResult()
always did: shape, v1 option keys, and buffer counts that fit the reels.
They previously checked nothing. A grid still carrying bufferAbove was read
for bufferStart, came back undefined, and was random-filled with no
warning, on every stage of the chain. If a cascade of yours has been dropping
a peeking symbol, this is why. It now throws. Errors name their own entry
point, so a bad nextGrid says runCascade(): nextGrid rather than
refill().
The debug snapshot follows the travel axis#
debugSnapshot()’s reels[].allSymbols[].y is now .main, the coordinate
along that reel’s travel axis, and each reel reports its orientation and
direction:
// Before
snap.reels[0].allSymbols[0].y
// After
snap.reels[0].allSymbols[0].main
snap.reels[0].orientation // 'vertical' | 'horizontal'
The old field was hard-coded to view.y, so on a horizontal set every
symbol reported a constant 0.
The v1 rename tables are no longer exported#
CODEMOD_HINT, V1_BUILDER_METHODS, V1_OPTION_KEYS and
V1_OPTION_VALUES were public in the pre-release. They are 1.x migration
scaffolding, and exporting them would have pinned that scaffolding into all
of 2.x.
Nothing you write needs them. The guards still read the table internally, and every throw names the replacement and the codemod. If you built your own migration tooling against these, copy the pairs you need out of the tables above; they are frozen.
Gsap is now exported, so you can name the type you pass to
driveGsapWithTicker(ticker, gsap) and ReelConfig.gsap.
The example apps left the repo#
examples/ is gone. The standalone demo apps live in their own repo now, and
the runnable demos are on this site under /recipes, about
130 of them, each with its source alongside.
Nothing in the published package changed; examples/ was never in the
tarball. This only matters if you were importing reference code out of the
repo, which the old README encouraged. Where it went:
| Was | Now |
|---|---|
examples/shared/BlurSpriteSymbol.ts, CoinSymbol.ts, the Spine loaders, prototypeSpriteLoader.ts | packages/kit/src/ (same filenames), published as @pixi-reels/kit |
examples/shared/cheats.ts, seededRng.ts | the private @pixi-reels/cheats package, still outside the library per ADR 009 |
examples/assets/prototype-symbols/ | apps/site/public/prototype-symbols/ |
examples/orientation-matrix/ | tests/e2e/fixtures/orientation-matrix/ |
examples/shared/mockServer.ts, ui.ts, CheatPanel.ts, WinBox.ts, roundBus.ts | moved out with the demo apps |
None of these were ever library API, so none of them is a pixi-reels
import you need to change. CheatEngine and SeededRng were always
reference code you copy; the package never exported them.
What the codemod will not do#
It is an AST transform, so it leaves two things for you:
- Your own local variables.
row,col,wandhare ordinary words, and a codemod that renamed them would rewritefor (const row of table). Code likereelSet.getCellBounds(col, row)keeps working; those are your values passed positionally. - Your comments. Grep them afterwards.
Most of what it misses on the API surface is a type error, and a v1 key that reaches the engine throws at the call site naming the replacement.
Two more things to check by hand:
- Review the codemod’s diff before you keep it. It rewrites the names it knows wherever it can prove the receiver is a reel set or builder. Anything it cannot prove, it leaves alone and reports.
nudge({ direction })values.'down'and'up'became'forward'and'reverse'. Passing the old value throws, but only the literal form inside anudge(...)call gets rewritten. A direction hoisted into a config object is yours to fix.