Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal "write phase" page #1

Merged
merged 3 commits into from
Jun 24, 2024
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Build and Test

on:
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: make install
- run: make build
- run: make check-format
- run: make test
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ install:

.PHONY: build
build:
cd ui && pnpm run lingui:extract && pnpm run lingui:compile
pnpm run -r build
cd game && pnpm build
cd ui && pnpm lingui:extract && pnpm lingui:compile

.PHONY: test
test:
pnpm run -r test
pnpm -r test

.PHONY: format
format:
Expand All @@ -25,8 +25,8 @@ check-format:

.PHONY: watch
watch:
pnpm run -r watch
pnpm -r --parallel watch

.PHONY: dev
dev:
cd ui && pnpm run dev
cd ui && pnpm dev
91 changes: 66 additions & 25 deletions game/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,83 @@
import { UserId } from "@lefun/core";
import { createMove, GameDef, Moves, PlayerMove } from "@lefun/game";

type Player = {
isRolling: boolean;
diceValue?: number;
const NUM_ROUNDS = 3;

// Hard-code some categories for now.
const CATEGORIES = [
"Something You Can Drink",
"Place With Lots of People",
"Horror Movies",
"Animal",
"Small Fruit",
"Thing That Is Frozen",
"Flower",
"Color",
"Something you write with",
"In a House",
// Should we use 10 or 12?
// "Something Blue",
// "Pop Artist",
];

const NUM_CATEGORIES = CATEGORIES.length;

export type Phase = "write" | "review";

export type B = {
categories: string[];

// Info of the current round.
round: number;
phase: Phase;
letter: string;
};

export type Board = {
count: number;
players: Record<UserId, Player>;
export type PB = {
// An array of answers for each round.
answers: string[][];
};

const [ROLL, roll] = createMove("roll");
type WritePayload = {
index: number;
answer: string;
};

const moves: Moves<Board> = {
[ROLL]: {
executeNow({ board, userId }) {
board.players[userId].isRolling = true;
},
execute({ board, userId, random }) {
board.players[userId].diceValue = random.d6();
board.players[userId].isRolling = false;
const [WRITE, write] = createMove<WritePayload>("write");

const moves: Moves<B, PB> = {
[WRITE]: {
executeNow({ board, playerboard, payload }) {
const { answer, index } = payload as WritePayload;
const { round } = board;
playerboard.answers[round][index] = answer;
},
},
};

const game: GameDef<Board> = {
initialBoards: ({ players }) => ({
board: {
count: 0,
players: Object.fromEntries(
players.map((userId) => [userId, { isRolling: false }]),
),
},
}),
const game: GameDef<B, PB> = {
initialBoards: ({ players }) => {
const board = {
categories: CATEGORIES,
round: 0,
// TODO No letter to start with, then a count them and then only we pick the letter.
letter: "A",
phase: "write" as const,
};

const playerboards: Record<UserId, PB> = {};

for (const userId of players) {
playerboards[userId] = {
answers: Array(NUM_ROUNDS).fill(Array(NUM_CATEGORIES).fill("")),
};
}

return { board, playerboards };
},
moves,
minPlayers: 1,
maxPlayers: 10,
};

export { game, roll };
export { game, write };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"devDependencies": {
"prettier": "^3.3.2"
},
"private": true
"private": true,
"packageManager": "[email protected]"
}
Loading