Skip to content

Commit

Permalink
Merge branch 'main' into feature/723-improve-client-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoster committed May 23, 2021
2 parents 0f1888f + 4163e09 commit 0a6c7a5
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [boardgameio]
open_collective: boardgameio
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Checklist

* [ ] Use a separate branch in your local repo (not `master`).
* [ ] Test coverage is 100% (or you have a story for why it's ok).
- [ ] Use a separate branch in your local repo (not `main`).
- [ ] Test coverage is 100% (or you have a story for why it's ok).
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
unit:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ The Issue Tracker may contain items labelled [**good first issue**][gfi] or [**h

[Pull Requests](https://help.github.com/articles/about-pull-requests/) are used for contributions. Code must be well-tested and not decrease the test coverage significantly.

#### Use a separate branch (not `master`)
#### Use a separate branch (not `main`)

Please commit changes to a separate branch in your fork
so that we can work together making changes to it before it
is ready to be merged. Name your branch something like
`<username>/feature`.

Once you are ready, you can create a Pull Request for it to be
merged into the `master` branch in this repo.
merged into the `main` branch in this repo.

#### Testing

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p align="center">
<img src="https://raw.githubusercontent.com/boardgameio/boardgame.io/master/docs/logo-optimized.svg?sanitize=true" alt="boardgame.io" />
<img src="https://raw.githubusercontent.com/boardgameio/boardgame.io/main/docs/logo-optimized.svg?sanitize=true" alt="boardgame.io" />
</p>

<p align="center">
<a href="https://www.npmjs.com/package/boardgame.io"><img src="https://badge.fury.io/js/boardgame.io.svg" alt="npm version" /></a>
<a href="https://github.com/boardgameio/boardgame.io/actions?query=workflow%3ATests"> <img src="https://github.com/boardgameio/boardgame.io/workflows/Tests/badge.svg" alt='Build Status'></a>
<a href='https://coveralls.io/github/boardgameio/boardgame.io?branch=master'><img src='https://coveralls.io/repos/github/boardgameio/boardgame.io/badge.svg?branch=master' alt='Coverage Status' /></a>
<a href='https://coveralls.io/github/boardgameio/boardgame.io?branch=main'><img src='https://coveralls.io/repos/github/boardgameio/boardgame.io/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://gitter.im/boardgame-io"><img src="https://badges.gitter.im/boardgame-io.svg" alt="Gitter" /></a>
</p>

Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta name="twitter:title" content="boardgame.io">
<meta name="twitter:image" content="https://res.cloudinary.com/dyfmhmho5/image/upload/v1543585150/logo_w1snck.png">
<meta name="twitter:description" content="Open Source Game Engine for Turn-Based Games">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/boardgameio/boardgame.io/master/docs/favicon.png" type="image/png" sizes="16x16">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/boardgameio/boardgame.io/main/docs/favicon.png" type="image/png" sizes="16x16">
<link rel="stylesheet" href="//unpkg.com/docsify-themeable@0/dist/css/theme-simple.css">
<link rel="stylesheet" href="theme.css">

Expand Down Expand Up @@ -94,7 +94,7 @@
<script src="//unpkg.com/docsify-edit-on-github@1/index.js"></script>
<script>
window.$docsify.plugins.push(EditOnGithubPlugin.create(
'https://github.com/boardgameio/boardgame.io/blob/master/docs/documentation/',
'https://github.com/boardgameio/boardgame.io/blob/main/docs/documentation/',
null,
'Edit on GitHub'
));
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ a basic caching model compatible with any boardgame.io database connector.

### Writing a Custom Adapter

Create a class that implements the [StorageAPI.Async](https://github.com/boardgameio/boardgame.io/blob/master/src/server/db/base.ts) interface.
Create a class that implements the [StorageAPI.Async](https://github.com/boardgameio/boardgame.io/blob/main/src/server/db/base.ts) interface.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta name="twitter:title" content="boardgame.io">
<meta name="twitter:image" content="https://res.cloudinary.com/dyfmhmho5/image/upload/v1543585150/logo_w1snck.png">
<meta name="twitter:description" content="Open Source Game Engine for Turn-Based Games">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/boardgameio/boardgame.io/master/docs/favicon.png" type="image/png" sizes="16x16">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/boardgameio/boardgame.io/main/docs/favicon.png" type="image/png" sizes="16x16">
<link rel="stylesheet" href="//unpkg.com/docsify-themeable@0/dist/css/theme-simple.css">
<link rel="stylesheet" href="documentation/theme.css">
<link rel="stylesheet" href="index.css">
Expand All @@ -28,7 +28,7 @@
<div id="badges" class="web-only">
<a href="https://www.npmjs.com/package/boardgame.io"><img src="https://badge.fury.io/js/boardgame.io.svg" alt="npm version" /></a>
<a href="https://github.com/boardgameio/boardgame.io/actions?query=workflow%3ATests"> <img src="https://github.com/boardgameio/boardgame.io/workflows/Tests/badge.svg" alt='Build Status'></a>
<a href='https://coveralls.io/github/boardgameio/boardgame.io?branch=master'><img src='https://coveralls.io/repos/github/boardgameio/boardgame.io/badge.svg?branch=master' alt='Coverage Status' /></a>
<a href='https://coveralls.io/github/boardgameio/boardgame.io?branch=main'><img src='https://coveralls.io/repos/github/boardgameio/boardgame.io/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://gitter.im/boardgame-io"><img src="https://badges.gitter.im/boardgame-io.svg" alt="Gitter" /></a>
</div>

Expand Down
2 changes: 1 addition & 1 deletion roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The issues below (and some others that are not in this document) are also availa
- ##### Databases

We encourage developers to contribute third-party storage connectors, implementing
[the `StorageAPI.Async` interface](https://github.com/boardgameio/boardgame.io/blob/master/src/server/db/base.ts).
[the `StorageAPI.Async` interface](https://github.com/boardgameio/boardgame.io/blob/main/src/server/db/base.ts).

See the [Storage docs](https://boardgame.io/documentation/#/storage) for
examples and details of the backends currently available.
Expand Down
25 changes: 24 additions & 1 deletion src/core/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,17 @@ describe('undo / redo', () => {
G.roll = ctx.random.D6();
},
},
turn: {
stages: {
special: {},
},
},
};

beforeEach(() => {
jest.clearAllMocks();
});

const reducer = CreateGameReducer({ game });

const initialState = InitializeGame({ game });
Expand All @@ -348,7 +357,7 @@ describe('undo / redo', () => {
expect(state._undo[1].ctx.random).toBeUndefined();
});

test('undo restores previous state', () => {
test('undo restores previous state after move', () => {
let state = reducer(initialState, makeMove('move', 'A', '0'));
const { G, ctx, plugins } = state;
state = reducer(state, makeMove('roll', null, '0'));
Expand All @@ -358,6 +367,20 @@ describe('undo / redo', () => {
expect(state.plugins).toEqual(plugins);
});

test('undo restores previous state after event', () => {
let state = reducer(initialState, gameEvent('setStage', 'special', '0'));
const { G, ctx, plugins } = state;
state = reducer(state, gameEvent('endStage', undefined, '0'));
expect(error).not.toBeCalled();
// Make sure we actually modified the stage.
expect(state.ctx.activePlayers).not.toEqual(ctx.activePlayers);
state = reducer(state, undo());
expect(error).not.toBeCalled();
expect(state.G).toEqual(G);
expect(state.ctx).toEqual(ctx);
expect(state.plugins).toEqual(plugins);
});

test('redo restores undone state', () => {
let state = initialState;
// Make two moves.
Expand Down
21 changes: 10 additions & 11 deletions src/core/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,16 @@ export function CreateGameReducer({
return state;
}

// Only allow undoable moves to be undone.
const lastMove: Move = game.flow.getMove(
restore.ctx,
last.moveType,
last.playerID
);
if (!CanUndoMove(state.G, state.ctx, lastMove)) {
// TODO(#723): Add an error case here.
// error(`Move cannot be undone`);
// return WithError(state, ActionErrorType.ActionDisabled);
return state;
// If undoing a move, check it is undoable.
if (last.moveType) {
const lastMove: Move = game.flow.getMove(
restore.ctx,
last.moveType,
last.playerID
);
if (!CanUndoMove(state.G, state.ctx, lastMove)) {
return state;
}
}

state = initializeDeltalog(state, action);
Expand Down

0 comments on commit 0a6c7a5

Please sign in to comment.