Skip to content
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6e99ff3
feat: Refactor core to use new move signature
delucis Nov 3, 2020
3ac0def
refactor(flow): Reorganise and clarify ProcessMove
delucis Nov 3, 2020
6355df4
fix(bot): Improve bot typing
delucis Nov 3, 2020
189b512
docs(examples): Update examples to use new function signatures
delucis Nov 3, 2020
36bb3b3
test(integration): Update to new function signature
delucis Nov 3, 2020
fc716e7
docs: Update to new function signature
delucis Nov 4, 2020
cf5be26
Merge branch 'master' into delucis/feat/new-move-signature
delucis Nov 7, 2020
b783644
test(socketio): Fix tests for new move signature
delucis Nov 7, 2020
7dd1703
refactor: Settle on hooks not receiving `playerID`
delucis Nov 7, 2020
ce4d657
style(plugins): Remove unused import
delucis Nov 8, 2020
c3d0dca
Merge branch 'master' into delucis/feat/new-move-signature
delucis Dec 24, 2020
93715c3
Merge branch 'master' into delucis/feat/new-move-signature
delucis Dec 24, 2020
b0b5693
fix(types): Restore plugin state type as `any`
delucis Dec 24, 2020
9d2adb0
Merge branch 'master' into delucis/feat/new-move-signature
delucis Jan 16, 2021
9315a02
fix(types): Fix PluginAPIs type parameters
delucis Jan 16, 2021
05ee1e6
test: Use new signature in merged tests
delucis Jan 16, 2021
869fe82
feat(types): Improve hook return types
delucis Jan 17, 2021
cb4fee4
docs(debugging): Update to use new move signature
delucis Jan 17, 2021
9ace4f5
fix: Use new signature in benchmark
delucis Jan 19, 2021
619f677
Merge branch 'master' into delucis/feat/new-move-signature
delucis Feb 1, 2021
f1923ee
Merge branch 'master' into delucis/feat/new-move-signature
delucis Feb 15, 2021
ff9d5ea
refactor(plugins): Update PluginSerializable for new move signature
delucis Feb 15, 2021
7d307cd
Merge branch 'master' into delucis/feat/new-move-signature
delucis May 12, 2021
3fcf383
test: Fix tests after merge
delucis May 12, 2021
f22b2ef
fix(client): Fix typings after merge
delucis May 12, 2021
dce2fac
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jun 3, 2021
0946d45
fix: Clean up after merge dce2fac
delucis Jun 3, 2021
c230b18
feat: Use new signature for playerView functions
delucis Jun 3, 2021
399ab71
feat: Update `undoable` method of long-form move to use new signature
delucis Jun 3, 2021
3e96871
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jul 5, 2021
eaf92a4
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jul 8, 2021
b077b3e
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jul 27, 2021
e1a348c
fix: Cleanup after merge b077b3e
delucis Jul 27, 2021
0904286
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jul 28, 2021
f9356bc
Merge branch 'main' into delucis/feat/new-move-signature
delucis Aug 6, 2021
8bc458e
refactor: Clean up after merge
delucis Aug 6, 2021
ccd4113
Merge branch 'main' into delucis/feat/new-move-signature
delucis Aug 7, 2021
daaa873
Merge branch 'main' into delucis/feat/new-move-signature
delucis Aug 15, 2021
fd97e3d
Merge branch 'main' into delucis/feat/new-move-signature
delucis Aug 29, 2021
e58dd33
fix: Cleanup after merge
delucis Aug 29, 2021
f11596e
docs(Game): Remove `events` plugin in `endIf` hook docs
delucis Aug 29, 2021
094b364
test(reducer): Improve test
delucis Aug 29, 2021
48d312f
Merge branch 'main' into delucis/feat/new-move-signature
delucis Sep 4, 2021
efecb69
Merge branch 'main' into delucis/feat/new-move-signature
delucis Oct 16, 2021
ce31e91
fix(flow): Pass `playerID` to wrapped `onMove` hook
delucis Oct 17, 2021
4fecbec
Merge branch 'main' into delucis/feat/new-move-signature
delucis Oct 22, 2021
1726e4e
Merge branch 'main' into delucis/feat/new-move-signature
delucis Oct 24, 2021
1f78293
Merge branch 'main' into delucis/feat/new-move-signature
delucis Nov 14, 2021
3506bd8
Merge branch 'main' into delucis/feat/new-move-signature
delucis Nov 29, 2021
b801d19
Merge branch 'main' into delucis/feat/new-move-signature
delucis Dec 18, 2021
5718725
Merge branch 'main' into delucis/feat/new-move-signature
delucis Dec 23, 2021
313bec6
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jan 23, 2022
317a5d3
fix(mock-random): update changes in 636ce8f6 for new move signature
delucis Jan 23, 2022
c57983a
docs(Game): update changes in d091a118 for new move signature
delucis Jan 23, 2022
a799884
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jan 23, 2022
9894155
feat(types): loosen typing of move arguments
delucis Jan 23, 2022
6b32f10
test: test the signatures different game methods are called with
delucis Jan 23, 2022
7663346
Merge branch 'main' into delucis/feat/new-move-signature
delucis Jan 23, 2022
12170f5
docs(typescript): use new signature in move example
delucis Jan 25, 2022
8e3c7ca
Merge branch 'main' into delucis/feat/new-move-signature
delucis Feb 22, 2022
decf26d
Merge branch 'main' into delucis/feat/new-move-signature
delucis Oct 6, 2022
7de8c67
Merge branch 'main' into delucis/feat/new-move-signature
vdfdev Oct 11, 2022
bff9fe0
Revert "Merge branch 'main' into delucis/feat/new-move-signature"
Oct 11, 2022
9f10e12
Revert "Revert "Merge branch 'main' into delucis/feat/new-move-signat…
Oct 11, 2022
b9a97ec
Trying to fix merge conflicts
Oct 11, 2022
6f1d3a3
Fixes filter-player-view.test.ts
Oct 11, 2022
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
2 changes: 1 addition & 1 deletion benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { makeMove, gameEvent } from '../src/core/action-creators';

const game = {
moves: {
A: (G) => G,
A: ({ G }) => G,
},
endIf: () => false,
};
Expand Down
7 changes: 0 additions & 7 deletions docs/documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
### 0.49.13

### Features

* [[aa99a9c](https://github.com/boardgameio/boardgame.io/commit/aa99a9cce28012cb747fa6db8b3f8ad73c28be0a) feat: Conditional log redacting in long form move ([#1089](https://github.com/boardgameio/boardgame.io/pull/1089))
* [[4bf203c](https://github.com/boardgameio/boardgame.io/commit/4bf203c1c1ec42e3193935a39e4cfb54a5658627) TypeScript: AiEnumerate return type ([#1080](https://github.com/boardgameio/boardgame.io/pull/1080))

### v0.49.12

#### Bugfixes
Expand Down
35 changes: 19 additions & 16 deletions docs/documentation/api/Game.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Function that returns the initial value of G.
// setupData is an optional custom object that is
// passed through the Game Creation API.
setup: (ctx, setupData) => G,
setup: ({ ctx, ...plugins }, setupData) => G,

// Optional function to validate the setupData before
// matches are created. If this returns a value,
Expand All @@ -20,14 +20,14 @@

moves: {
// short-form move.
A: (G, ctx, ...args) => {},
A: ({ G, ctx, playerID, events, random, ...plugins }, ...args) => {},

// long-form move.
B: {
// The move function.
move: (G, ctx, ...args) => {},
move: ({ G, ctx, playerID, events, random, ...plugins }, ...args) => {},
// Prevents undoing the move.
// Can also be a function: (G, ctx) => true/false
// Can also be a function: ({ G, ctx }) => true/false
undoable: false,
// Prevents the move arguments from showing up in the log.
redact: true,
Expand All @@ -44,7 +44,7 @@
// Everything below is OPTIONAL.

// Function that allows you to tailor the game state to a specific player.
playerView: (G, ctx, playerID) => G,
playerView: ({ G, ctx, playerID }) => G,

// The seed used by the pseudo-random number generator.
seed: 'random-string',
Expand All @@ -54,16 +54,19 @@
order: TurnOrder.DEFAULT,

// Called at the beginning of a turn.
onBegin: (G, ctx) => G,
onBegin: ({ G, ctx, events, random, ...plugins }) => G,

// Called at the end of a turn.
onEnd: (G, ctx) => G,
onEnd: ({ G, ctx, events, random, ...plugins }) => G,

// Ends the turn if this returns true.
endIf: (G, ctx) => true,
// Returning { next }, sets next playerID.
endIf: ({ G, ctx, random, ...plugins }) => (
true | { next: '0' }
),

// Called at the end of each move.
onMove: (G, ctx) => G,
// Called after each move.
onMove: ({ G, ctx, events, random, ...plugins }) => G,

// Prevents ending the turn before a minimum number of moves.
minMoves: 1,
Expand Down Expand Up @@ -92,13 +95,13 @@
phases: {
A: {
// Called at the beginning of a phase.
onBegin: (G, ctx) => G,
onBegin: ({ G, ctx, events, random, ...plugins }) => G,

// Called at the end of a phase.
onEnd: (G, ctx) => G,
onEnd: ({ G, ctx, events, random, ...plugins }) => G,

// Ends the phase if this returns true.
endIf: (G, ctx) => true,
endIf: ({ G, ctx, random, ...plugins }) => true,

// Overrides `moves` for the duration of this phase.
moves: { ... },
Expand All @@ -110,7 +113,7 @@
start: true,

// Set the phase to enter when this phase ends.
// Can also be a function: (G, ctx) => 'nextPhaseName'
// Can also be a function: ({ G, ctx }) => 'nextPhaseName'
next: 'nextPhaseName',
},

Expand All @@ -124,11 +127,11 @@

// Ends the game if this returns anything.
// The return value is available in `ctx.gameover`.
endIf: (G, ctx) => obj,
endIf: ({ G, ctx, random, ...plugins }) => obj,

// Called at the end of the game.
// `ctx.gameover` is available at this point.
onEnd: (G, ctx) => G,
onEnd: ({ G, ctx, events, random, ...plugins }) => G,

// Disable undo feature for all the moves in the game
disableUndo: true,
Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ immutability is handled by the framework.

```js
moves: {
drawCard: (G, ctx) => {
drawCard: ({ G, ctx }) => {
const card = G.deck.pop();
G.hand.push(card);
},
Expand Down Expand Up @@ -74,7 +74,7 @@ props.moves.drawCard();

### Events

These are framework-provided functions that are analagous to moves, except that they work on `ctx`. These typically advance the game state by doing things like
These are framework-provided functions that are analogous to moves, except that they work on `ctx`. These typically advance the game state by doing things like
ending the turn, changing the game phase etc.
Events are dispatched from the client in a similar way to moves.

Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ It can sometimes be helpful to surface some metadata during a move.
You can do this by using the log plugin. For example,

```js
const move = (G, ctx) => {
ctx.log.setMetadata('metadata for this move');
const move = ({ log }) => {
log.setMetadata('metadata for this move');
};
```

Expand Down
7 changes: 4 additions & 3 deletions docs/documentation/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ for more details.

You can trigger events from a move or code inside
your game logic (a phase’s `onBegin` hook, for example).
This is done through the `ctx.events` object:
This is done through the `events` API in the object passed
as the first argument to moves:

```js
moves: {
drawCard: (G, ctx) => {
ctx.events.endPhase();
drawCard: ({ G, ctx, events }) => {
events.endPhase();
};
}
```
Expand Down
10 changes: 6 additions & 4 deletions docs/documentation/immutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A traditional pure function just accepts arguments and then
returns the new state. Something like this:

```js
function move(G, ctx) {
function move({ G }) {
// Return new value of G without modifying the arguments.
return { ...G, hand: G.hand + 1 };
}
Expand All @@ -33,7 +33,7 @@ immutability principle. Both styles are supported interchangeably,
so use the one that you prefer.

```js
function move(G, ctx) {
function move({ G }) {
G.hand++;
}
```
Expand All @@ -42,7 +42,9 @@ function move(G, ctx) {
In fact, returning something while also mutating `G` is
considered an error.

!> `ctx` is a read-only object and is never modified in either style.
!> You can only modify `G`. Other values passed to your moves
are read-only and should never be modified in either style.
Changes to `ctx` can be made using [events](events.md).

### Invalid moves

Expand All @@ -57,7 +59,7 @@ Tic-Tac-Toe.
import { INVALID_MOVE } from 'boardgame.io/core';

moves: {
clickCell: function(G, ctx, id) {
clickCell: function({ G, ctx }, id) {
// Illegal move: Cell is filled.
if (G.cells[id] !== null) {
return INVALID_MOVE;
Expand Down
22 changes: 11 additions & 11 deletions docs/documentation/phases.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ two moves:
- play a card from your hand onto the deck.

```js
function DrawCard(G, ctx) {
function DrawCard({ G, playerID }) {
G.deck--;
G.hand[ctx.currentPlayer]++;
G.hand[playerID]++;
}

function PlayCard(G, ctx) {
function PlayCard({ G, playerID }) {
G.deck++;
G.hand[ctx.currentPlayer]--;
G.hand[playerID]--;
}

const game = {
setup: ctx => ({ deck: 6, hand: Array(ctx.numPlayers).fill(0) }),
setup: ({ ctx }) => ({ deck: 6, hand: Array(ctx.numPlayers).fill(0) }),
moves: { DrawCard, PlayCard },
turn: { minMoves: 1, maxMoves: 1 },
};
Expand All @@ -58,7 +58,7 @@ list of moves, which come into effect during that phase:

```js
const game = {
setup: ctx => ({ deck: 6, hand: Array(ctx.numPlayers).fill(0) }),
setup: ({ ctx }) => ({ deck: 6, hand: Array(ctx.numPlayers).fill(0) }),
turn: { minMoves: 1, maxMoves: 1 },

phases: {
Expand Down Expand Up @@ -102,7 +102,7 @@ empty.
phases: {
draw: {
moves: { DrawCard },
+ endIf: G => (G.deck <= 0),
+ endIf: ({ G }) => (G.deck <= 0),
+ next: 'play',
start: true,
},
Expand Down Expand Up @@ -134,8 +134,8 @@ You can also run code automatically at the beginning or end of a phase. These ar
```js
phases: {
phaseA: {
onBegin: (G, ctx) => { ... },
onEnd: (G, ctx) => { ... },
onBegin: ({ G, ctx }) => { ... },
onEnd: ({ G, ctx }) => { ... },
},
};
```
Expand Down Expand Up @@ -170,7 +170,7 @@ You can also end a phase by returning a truthy value from its
phases: {
phaseA: {
next: 'phaseB',
endIf: (G, ctx) => true,
endIf: ({ G, ctx }) => true,
},
phaseB: { ... },
},
Expand All @@ -188,7 +188,7 @@ state at the end of the phase:
```js
phases: {
phaseA: {
next: (G, ctx) => {
next: ({ G }) => {
return G.condition ? 'phaseC' : 'phaseB';
},
},
Expand Down
10 changes: 4 additions & 6 deletions docs/documentation/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ A plugin is an object that contains the following fields.
// wrapper can modify G before passing it down to
// the wrapped function. It is a good practice to
// undo the change at the end of the call.
fnWrap: (fn) => (G, ctx, ...args) => {
fnWrap: (fn) => ({ G, ...rest }, ...args) => {
G = preprocess(G);
G = fn(G, ctx, ...args);
G = fn({ G, ...rest }, ...args);
G = postprocess(G);
return G;
},
Expand Down Expand Up @@ -70,11 +70,9 @@ import { PluginA, PluginB } from 'boardgame.io/plugins';
const game = {
name: 'my-game',

moves: {
...
},

plugins: [PluginA, PluginB],

// ...
};
```

Expand Down
Loading