Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ npm i bgio-effects
Call effects from your moves or other game code:

```js
function move(G, ctx) {
ctx.effects.explode();
function move({ G, effects }) {
effects.explode();
}
```

Expand Down
27 changes: 12 additions & 15 deletions docs/src/pages/demo/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ const effectsConfig = {

export type EffectsConfig = typeof effectsConfig;

const game: Game<
Record<string, never>,
Ctx & EffectsCtxMixin<EffectsConfig>
> = {
const game: Game<Record<string, never>, Ctx & EffectsCtxMixin<EffectsConfig>> = {
plugins: [EffectsPlugin(effectsConfig)],
moves: {
One: (_, ctx) => {
ctx.effects.A('one');
ctx.effects.A('two', '<+0.5');
ctx.effects.B('hello', '<+0.5');
ctx.effects.A('three', '<+0.25');
ctx.effects.B('world', '<+0.5');
One: ({ effects }) => {
effects.A('one');
effects.A('two', '<+0.5');
effects.B('hello', '<+0.5');
effects.A('three', '<+0.25');
effects.B('world', '<+0.5');
},
Two: (_, ctx) => {
ctx.effects.A('synch-');
ctx.effects.B('ronise', '<');
ctx.effects.A('effects', '<+0.5');
ctx.effects.B('FX!', '<');
Two: ({ effects }) => {
effects.A('synch-');
effects.B('ronise', '<');
effects.A('effects', '<+0.5');
effects.B('FX!', '<');
},
},
};
Expand Down
12 changes: 6 additions & 6 deletions docs/src/pages/plugin/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ const game = {
// Each effect type declared in your config will
// be available in your moves as ctx.effects[effectType]
moves: {
roll: (G, ctx) => {
const roll = ctx.random.D6();
ctx.effects.rollDie(roll);
roll: ({ G, random, effects }) => {
const roll = random.D6();
effects.rollDie(roll);
if (roll > 4) ctx.effects.explode();
G.roll = roll;
},

end: (G, ctx) => {
ctx.events.endTurn();
ctx.effects.endTurn();
end: ({ G, events, effects }) => {
events.endTurn();
effects.endTurn();
},
},
};
Expand Down
16 changes: 8 additions & 8 deletions docs/src/pages/tutorial/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const BaseGame: Game<G> = {
score: 0,
}),
moves: {
roll: (G: G, ctx): void => {
G.roll = ctx.random.D6();
roll: ({ G: G, random }): void => {
G.roll = random.D6();
if (G.roll === 6) G.score++;
},
},
Expand All @@ -33,9 +33,9 @@ export const GameWithRollEffect: Game<G> = {
plugins: [EffectsPlugin(baseEffectsConfig)],
moves: {
...BaseGame.moves,
roll: (G, ctx) => {
G.roll = ctx.random.D6();
ctx.effects.roll(G.roll);
roll: ({ G, random, effects }) => {
G.roll = random.D6();
effects.roll(G.roll);
if (G.roll === 6) G.score++;
},
},
Expand All @@ -55,9 +55,9 @@ export const GameWithTimedRollEffect: Game<G> = {
plugins: [EffectsPlugin(timedEffectsConfig)],
moves: {
...BaseGame.moves,
roll: (G, ctx) => {
G.roll = ctx.random.D6();
ctx.effects.roll(G.roll);
roll: ({ G, random, effects }) => {
G.roll = random.D6();
effects.roll(G.roll);
if (G.roll === 6) G.score++;
},
},
Expand Down
14 changes: 7 additions & 7 deletions docs/src/pages/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const game = {
setup: () => ({ roll: 1, score: 0 }),

moves: {
roll: (G, ctx) => {
const roll = ctx.random.D6();
roll: ({ G, random }) => {
const roll = random.D6();
G.roll = roll;
if (roll === 6) G.score++;
},
},

// End the game when the player has scored 5 points.
endIf: (G) => G.score >= 5,
endIf: ({ G }) => G.score >= 5,
};
```

Expand Down Expand Up @@ -154,16 +154,16 @@ const game = {
setup: () => ({ roll: 1, score: 0 }),

moves: {
roll: (G, ctx) => {
const roll = ctx.random.D6();
roll: ({ G, random, effects }) => {
const roll = random.D6();
// Call the newly added roll effect.
ctx.effects.roll(roll);
effects.roll(roll);
G.roll = roll;
if (G.roll === 6) G.score++;
},
},

endIf: (G) => G.score >= 5,
endIf: ({ G }) => G.score >= 5,
};
```

Expand Down
Loading