Exact source used by this build. SHA-256: 3f3e099b71ca74e51474898b5120350c7afa10263c2985234a1e5330acd53eda.
1 import { z } from "zod";
2 import { defineIntent, defineSystem } from "../systems/registry";
3
4 /** Small, compiled extension example; register it in systems/index.ts to enable it. */
5 export const counterSystem = defineSystem({
6 id: "counter",
7 worldDefaults: () => ({ count: 0 }),
8 playerDefaults: () => ({ contributions: 0 }),
9 events: ["counterChanged"],
10 intents: [defineIntent("increment", z.object({ type: z.literal("increment"), amount: z.number().int().min(1).max(5) }), ({ state, player, playerId }, intent) => {
11 const count = (state.systems.counter as { count: number }).count + intent.amount;
12 const contributions = (player.systems.counter as { contributions: number }).contributions + 1;
13 return {
14 state: {
15 ...state, revision: state.revision + 1,
16 systems: { ...state.systems, counter: { count } },
17 players: { ...state.players, [playerId]: { ...player, systems: { ...player.systems, counter: { contributions } } } },
18 },
19 events: [{ type: "counterChanged", playerId, data: { count } }],
20 };
21 })],
22 });
23