diff --git a/example/src/client/actions.ts b/example/src/client/actions.ts index 6e2c34c..78bdd44 100644 --- a/example/src/client/actions.ts +++ b/example/src/client/actions.ts @@ -1,13 +1,21 @@ // DO NOT MODIFY! // This file is generated by pyre. -// Generated: 2026-01-20 12:25:24. +// Generated: 2026-01-24 09:09:49. import { send } from 'pyre/client' +export const playAgain = () => { + send({ + type: 'action', + action: 'playAgain', + args: [] + }) +} + export const nameChange = (name: string) => { send({ type: 'action', - action: 'name:change', + action: 'nameChange', args: [name] }) } diff --git a/example/src/client/board.tsx b/example/src/client/board.tsx index 7908881..0d321a8 100644 --- a/example/src/client/board.tsx +++ b/example/src/client/board.tsx @@ -1,5 +1,5 @@ import { define, createThemes } from 'forge' -import { move, nameChange } from './actions' +import { move, nameChange, playAgain } from './actions' import type { Game } from '../types' import { sessionId } from 'pyre/client' @@ -271,6 +271,7 @@ const WinBanner = define('WinBanner', { {props.title} + ) }, diff --git a/example/src/game.ts b/example/src/game.ts index ffc1326..be63cad 100644 --- a/example/src/game.ts +++ b/example/src/game.ts @@ -3,7 +3,7 @@ export { default } from 'pyre/server' import type { Game, WinLine, xo } from './types' -const game: Game = { +const newGame: Game = { phase: 'play', turn: 'x', players: {}, @@ -15,7 +15,7 @@ const game: Game = { ] } -const action = setup(game, { +const action = setup(newGame, { onJoin(game, session) { if (game.players[session]) return @@ -31,7 +31,20 @@ const action = setup(game, { } }) -action('name:change', (ctx, name: string) => { +action('playAgain', (ctx) => { + const game = ctx.game as Game + game.phase = 'play' + game.turn = 'x' + delete game.winLine + game.board = [ + ['', '', ''], + ['', '', ''], + ['', '', ''], + ] + return game +}) + +action('nameChange', (ctx, name: string) => { const game = ctx.game as Game const player = game.players[ctx.session] @@ -52,6 +65,9 @@ action('move', (ctx, x: number, y: number) => { if (game.board[x] === undefined || game.board[x][y] === undefined) throw new Error(`x,y not in board: ${x},${y}`) + if (game.board[x][y] !== '') + throw new Error(`someone already played at ${x},${y}`) + if (game.turn !== player) throw new Error('not your turn!')