Skip to content

Commit 8243380

Browse files
committed
docs: add docs for game
1 parent f6364a7 commit 8243380

19 files changed

+131
-48
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ GitHub_private_key.pem
5151
# Scripts can create temporary SQL files
5252
/scripts/bash/*.sql
5353

54+
# Docs for npm packages
55+
/packages/game/docs
56+
5457
# ------------------------------
5558
# GitHub Node.gitignore template
5659
# https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"**/misc/keldon/": true,
3737
"**/server-old/": true,
3838
"**/card-images/": true,
39+
"**/packages/game/docs/**/*.html": true,
3940
// @template-customization-end
4041
},
4142

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"tsconfig": "^7.0.0",
8686
"tslib": "^2.6.2",
8787
"tsx": "^4.6.2",
88+
"typedoc": "^0.25.4",
8889
"typescript": "^5.3.3",
8990
"ws": "^8.15.1",
9091
"xmlserializer": "^0.6.1",

packages/client/src/game/reducers/stateReducer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { draw, replayEnter } from "../../../test/testActions";
2-
import { testMetadata } from "../../../test/testMetadata";
2+
import { getTestMetadata } from "../../../test/testMetadata";
33
import { initialState } from "./initialStates/initialState";
44
import { stateReducer } from "./stateReducer";
55

@@ -8,7 +8,7 @@ jest.mock("./uiReducer", () => ({
88
}));
99

1010
const numPlayers = 3;
11-
const defaultMetadata = testMetadata(numPlayers);
11+
const defaultMetadata = getTestMetadata(numPlayers);
1212

1313
describe("stateReducer", () => {
1414
test("does not mutate state", () => {

packages/client/test/loadGameJSON.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { ActionType } from "../src/game/types/ActionType";
3131
import type { CardIdentity } from "../src/game/types/CardIdentity";
3232
import type { State } from "../src/game/types/State";
3333
import type testGame from "../test_data/up_or_down.json";
34-
import { testMetadata } from "./testMetadata";
34+
import { getTestMetadata } from "./testMetadata";
3535

3636
type JSONGame = typeof testGame;
3737

@@ -56,7 +56,7 @@ export function loadGameJSON(gameJSON: JSONGame): State {
5656
}
5757
const numPlayers = potentialNumPlayers as NumPlayers;
5858

59-
const metadata = testMetadata(numPlayers, gameJSON.options.variant);
59+
const metadata = getTestMetadata(numPlayers, gameJSON.options.variant);
6060
const variant = getVariant(metadata.options.variantName);
6161

6262
const cardsPerHand = getCardsPerHand(metadata.options);

packages/client/test/testMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import type { Tuple } from "isaacscript-common-ts";
1313
import { newArray } from "isaacscript-common-ts";
1414

15-
export function testMetadata(
15+
export function getTestMetadata(
1616
numPlayers: NumPlayers,
1717
variantName: string = DEFAULT_VARIANT_NAME,
1818
): GameMetadata {

packages/game/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# @hanabi/game
1+
# Hanab Live Game Logic
22

3-
This contains the rules for the game. Can compute the next game state, given an existing game state and a game action.
3+
This package contains the rules for the game. These are exported as functions like `isCardTouchedByClue`, `isCardOnChop`, and so on. You can see the full list of functions on the [auto-generated documentation](./docs/modules.html).
4+
5+
Additionally, it can compute the next game state, given an existing game state and a game action (via the `gameReducer` function).
46

57
## Installation
68

9+
If you want to use the game logic in a bot or some other Hanab-related program, then you can install it from npm:
10+
711
```sh
8-
npm install @hanabi/game --save
12+
npm install @hanabi-live/game --save
913
```
1014

1115
## Usage

packages/game/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"README.md"
2525
],
2626
"scripts": {
27-
"build": "rm -rf dist && tsc",
27+
"build": "rm -rf dist && tsc --project ./tsconfig.npm.json && npx typedoc ./src/index.ts",
2828
"lint": "bash ./lint.sh"
2929
},
3030
"peerDependencies": {

packages/game/src/reducers/cardPossibilitiesReducer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertDefined } from "isaacscript-common-ts";
2-
import { testMetadata } from "../../../client/test/testMetadata";
2+
import { getTestMetadata } from "../../../client/test/testMetadata";
33
import { getVariant } from "../gameData";
44
import type { CardState } from "../interfaces/CardState";
55
import type { CardOrder } from "../types/CardOrder";
@@ -11,7 +11,7 @@ import { cardPossibilitiesReducer } from "./cardPossibilitiesReducer";
1111
import { getInitialCardState } from "./initialStates/initialCardState";
1212

1313
const NUM_PLAYERS = 3;
14-
const DEFAULT_METADATA = testMetadata(NUM_PLAYERS);
14+
const DEFAULT_METADATA = getTestMetadata(NUM_PLAYERS);
1515
const VARIANT = getVariant(DEFAULT_METADATA.options.variantName);
1616
const DEFAULT_CARD = getInitialCardState(0 as CardOrder, VARIANT, NUM_PLAYERS);
1717

@@ -93,7 +93,7 @@ describe("cardPossibilitiesReducer", () => {
9393
});
9494

9595
test("removes possibilities based on previous rank and color clues", () => {
96-
const metadata = testMetadata(
96+
const metadata = getTestMetadata(
9797
NUM_PLAYERS,
9898
"Rainbow-Ones & Brown (6 Suits)",
9999
);

packages/game/src/reducers/cardsReducer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
play,
1111
rankClue,
1212
} from "../../../client/test/testActions";
13-
import { testMetadata } from "../../../client/test/testMetadata";
13+
import { getTestMetadata } from "../../../client/test/testMetadata";
1414
import { getVariant } from "../gameData";
1515
import type { CardState } from "../interfaces/CardState";
1616
import type { GameState } from "../interfaces/GameState";
@@ -24,8 +24,8 @@ import { getInitialCardState } from "./initialStates/initialCardState";
2424
import { getInitialGameState } from "./initialStates/initialGameState";
2525

2626
const NUM_PLAYERS = 3;
27-
const DEFAULT_METADATA = testMetadata(NUM_PLAYERS);
28-
const THROW_IT_IN_A_HOLE_METADATA = testMetadata(
27+
const DEFAULT_METADATA = getTestMetadata(NUM_PLAYERS);
28+
const THROW_IT_IN_A_HOLE_METADATA = getTestMetadata(
2929
NUM_PLAYERS,
3030
"Throw It in a Hole (4 Suits)",
3131
);

0 commit comments

Comments
 (0)