API reference
PhaseFactory
pixi-reels / index / PhaseFactory
Defined in: spin/phases/PhaseFactory.ts:47
Factory for creating reel phase instances.
Ships with all four default phases pre-registered. Users can override any phase by registering a custom constructor or factory function. Use registerFactory() when the phase needs extra construction-time config (e.g. cascade drop settings baked in via closure).
Constructors#
Constructor#
new PhaseFactory(): PhaseFactory;
Defined in: spin/phases/PhaseFactory.ts:50
Returns#
PhaseFactory
Methods#
create()#
create<T extends ReelPhase<any, SpeedProfile> = ReelPhase<any, SpeedProfile>>(
name: string,
reel: Reel,
speed: SpeedProfile,
context?: PhaseCreateContext
): T;
Defined in: spin/phases/PhaseFactory.ts:116
Create a phase instance for a reel.
context is what the phase and the registered factory learn about this
reel: its index, and whether it has already teased or been quickened. The
controller always passes it; a direct caller that omits it gets a context
that claims nothing (reelIndex: -1), and the phase then reads its
profile section without the whenAnticipated half.
Type Parameters#
| Type Parameter | Default type |
|---|---|
T extends ReelPhase<any, SpeedProfile> | ReelPhase<any, SpeedProfile> |
Parameters#
| Parameter | Type |
|---|---|
name | string |
reel | Reel |
speed | SpeedProfile |
context | PhaseCreateContext |
Returns#
T
has()#
has(name: string): boolean;
Defined in: spin/phases/PhaseFactory.ts:133
Parameters#
| Parameter | Type |
|---|---|
name | string |
Returns#
boolean
register()#
register<C extends PhaseConstructor<ReelPhase<any, any>, any, any>>(
name: string,
PhaseClass: C,
options?: PhaseOptionsOf<C>
): void;
Defined in: spin/phases/PhaseFactory.ts:77
Register or override a phase type by constructor, with the options its
constructor takes as a third argument. Registering a built-in under its
own key with options is how a game reconfigures it without subclassing:
Type Parameters#
| Type Parameter |
|---|
C extends PhaseConstructor<ReelPhase<any, any>, any, any> |
Parameters#
| Parameter | Type |
|---|---|
name | string |
PhaseClass | C |
options? | PhaseOptionsOf<C> |
Returns#
void
Example#
factory.register('stop', StopPhase, {
steps: (steps) => insertAfter(steps, 'land', step('flash', (ctx) => flash(ctx.reel))),
});
A phase declared against a wider profile (`ReelPhase<Config, MyProfile>`)
registers the same way: the manager hands every phase the profile
instance the game registered, so the extra fields are there at run time,
and narrowing to `P` here is what lets that declaration typecheck.
registerFactory()#
registerFactory<P extends SpeedProfile, T extends ReelPhase<any, any>>(name: string, factory: PhaseCreatorFn<T, P>): void;
Defined in: spin/phases/PhaseFactory.ts:100
Register or override a phase type by factory function. Use this when the phase needs extra args at construction time.
The third argument says which reel this is and what has already happened
to it, so a registration can pick a different phase per reel. 'stop'
built one way for a reel that teased and another for one that did not:
Type Parameters#
| Type Parameter |
|---|
P extends SpeedProfile |
T extends ReelPhase<any, any> |
Parameters#
| Parameter | Type |
|---|---|
name | string |
factory | PhaseCreatorFn<T, P> |
Returns#
void
Examples#
factory.registerFactory('cascade:dropIn', (reel, speed) => new CascadeDropInPhase(reel, speed, dropConfig));
factory.registerFactory('anticipation', (reel, speed, ctx) =>
ctx.reelIndex === 4 ? new CustomAnticipationPhase(reel, speed) : new AnticipationPhase(reel, speed));