### Troubleshooting Package Installation Issues Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Guidance for resolving package installation problems, emphasizing the use of `bun install`, clearing the cache, and checking the `packageManager` field in `package.json`. ```bash bun pm cache rm ``` -------------------------------- ### Install Dependencies and Run Development Server (Bash) Source: https://github.com/thecardgoat/tcg-engines/blob/main/apps/content-mgmt/README.md This snippet outlines the steps to set up and run the development environment for the Content Management Service. It includes installing dependencies, configuring environment variables, setting up the database, and starting the development server. ```bash bun install cp .env.example .env docker-compose up -d postgres-content bun run db:push bun run dev ``` -------------------------------- ### Install Project Dependencies with Bun Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Installs all project dependencies using Bun, the primary package manager for this project. This command should be run from the project's root directory. ```bash bun install ``` -------------------------------- ### Verification Commands Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md A set of commands to verify the correct installation and versions of Node.js, npm, Bun, and fnm, as well as to install dependencies and run a check-types command. ```bash node -v npm -v bun -v fnm --version bun install bun run check-types ``` -------------------------------- ### Quick Start: Card Management Tooling with TypeScript Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/core/docs/guides/card-tooling.md Demonstrates a quick start for building card management tools using @tcg/core/tooling. It shows defining card types, creating parsers and generators, and using a FileWriter to save formatted TypeScript code. ```typescript import { CardParser, CardGenerator, FileWriter, formatTypeScript, generateVariableName, } from '@tcg/core/tooling'; // 1. Define your card type type MyCard = { name: string; type: 'creature' | 'spell'; cost: number; text: string; }; // 2. Create a parser class MyCardParser extends CardParser { protected doParse(text: string): ParserResult { // Parse logic here return { success: true, data: card, warnings: [] }; } } // 3. Create a generator class MyCardGenerator extends CardGenerator { protected generateContent(card: MyCard): string { return `export const ${generateVariableName(card.name)} = ${JSON.stringify(card, null, 2)};`; } protected generateFileName(card: MyCard): string { return `${card.name.toLowerCase()}.ts`; } } // 4. Use them together const parser = new MyCardParser(); const generator = new MyCardGenerator(); const writer = new FileWriter('./cards'); const result = parser.parse('Fireball|spell|3|Deal 3 damage'); if (result.success) { const code = generator.generate(result.data); const formatted = await formatTypeScript(code); await writer.write(generator.generateFileName(result.data), formatted); } ``` -------------------------------- ### Install and Use Node.js 24 with fnm Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Installs Node.js version 24 using fnm and sets it as the active version. Includes verification commands for Node.js and npm. ```bash fnm install 24 fnm use 24 node -v npm -v ``` -------------------------------- ### Common Project Commands Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md A list of frequently used commands for the TCG Engines project, covering dependency installation, type checking, testing, linting, formatting, CI checks, and building. ```bash bun install bun run check-types bun test bun run lint bun run format bun run ci-check bun run build ``` -------------------------------- ### Install Bun Package Manager Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Installs the Bun JavaScript runtime and package manager. After installation, restart the terminal or source the shell configuration. ```bash curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Automated Setup Script Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Executes the automated setup script for the TCG Engines project. This is the quickest way to configure the development environment. ```bash chmod +x setup.sh ./setup.sh ``` -------------------------------- ### Start Svelte development server Source: https://github.com/thecardgoat/tcg-engines/blob/main/apps/operating-system/README.md These commands start the development server for a Svelte project after dependencies have been installed. The `--open` flag automatically opens the application in a new browser tab. ```shell npm run dev # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Client Setup for MultiplayerEngine in TypeScript Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/core/src/engine/MULTIPLAYER.md Sets up the MultiplayerEngine in client mode. It applies patches received from the server to maintain synchronized state and provides methods to get the current state, player-specific views, and check valid moves. ```typescript import { MultiplayerEngine } from "@tcg/core"; const client = new MultiplayerEngine(gameDefinition, players, { mode: "client", // Callback when patches are applied onPatchesApplied: (patches) => { console.log(`Applied ${patches.length} patches from server`); updateUI(); // Refresh your game UI }, }); // Receive and apply patches from server websocket.on("message", (data) => { if (data.type === "PATCH_UPDATE") { client.applyServerPatches(data.patches); } }); // Get current state const state = client.getState(); // Get player-specific view (hides private information) const playerView = client.getPlayerView(playerId); // Check valid moves for UI (enable/disable buttons) const validMoves = client.getValidMoves(playerId); const canDraw = client.canExecuteMove("drawCard", { playerId }); ``` -------------------------------- ### AI Agent Package Management Commands Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Demonstrates the correct Bun commands for package management, emphasizing their use over npm equivalents for AI agents working with this project. ```bash bun install bun add bun remove ``` -------------------------------- ### Troubleshooting fnm Not Found Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Provides steps to resolve the 'fnm not found' issue after installation, including restarting the terminal, sourcing shell configuration, and checking the PATH. ```bash source ~/.bashrc # or source ~/.zshrc echo $PATH | grep fnm ``` -------------------------------- ### Troubleshooting Bun Not Found Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Instructions to resolve 'bun not found' errors, such as restarting the terminal, manually adding Bun to the PATH, and verifying the installation. ```bash export PATH="$HOME/.bun/bin:$PATH" which bun ``` -------------------------------- ### Configure Game Definition with Setup, Moves, and End Conditions Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/template-engine/README.md This TypeScript example demonstrates how to configure the overall game definition, including the initial setup, the defined moves, win/loss conditions, and player-specific views. This is essential for setting up your custom game. ```typescript export const yourGameDefinition: GameDefinition = { name: "Your Game Name", setup: (players) => ({ // Initialize game state }), moves, endIf: (state) => { // Check win conditions if (someCondition) { return { winner: winnerId, reason: "Victory condition met" }; } return undefined; }, playerView: (state, playerId) => ({ // Filter state for each player // Hide opponent secrets }), }; ``` -------------------------------- ### Illustrate Card Definition vs. Instance in TypeScript Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/core/docs/ENGINE_INTEGRATION.md Provides examples of a static `CardDefinition` and a runtime `CardInstance` in TypeScript. The definition outlines what a card is, while the instance represents its current state in the game. ```typescript // Definition (in code) const definition: CardDefinition = { id: "card-001", name: "Example", power: 3, }; // Instance (in game state) const instance: CardInstance = { definitionId: "card-001", instanceId: "game-123-card-456", ownerId: "player1", zone: "play", // Current state damage: 1, tapped: true, }; ``` -------------------------------- ### Troubleshooting Node.js Version Issues Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Steps to fix incorrect Node.js versions, including ensuring fnm is configured, manually switching versions, and checking the `.node-version` file. ```bash fnm use 24 ``` -------------------------------- ### Server Setup for MultiplayerEngine in TypeScript Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/core/src/engine/MULTIPLAYER.md Sets up the MultiplayerEngine in server mode. It executes moves authoritatively, generates Immer patches, and broadcasts them to clients via a callback. It also handles rejected moves. ```typescript import { MultiplayerEngine } from "@tcg/core"; const server = new MultiplayerEngine(gameDefinition, players, { mode: "server", seed: "game-123-seed", // Callback when moves generate patches onPatchBroadcast: (broadcast) => { // Send patches to all connected clients via your network layer websocket.broadcast({ type: "PATCH_UPDATE", patches: broadcast.patches, historyIndex: broadcast.historyIndex, }); }, // Callback when moves are rejected onMoveRejected: (moveId, error, errorCode) => { console.error(`Move ${moveId} rejected: ${error}`); }, }); // Execute moves (server only) const result = server.executeMove("playCard", { playerId: createPlayerId("p1"), data: { cardId: "card-123" }, }); // Patches are automatically broadcast via onPatchBroadcast callback ``` -------------------------------- ### Install Dependencies and Run Checks with Bun Source: https://github.com/thecardgoat/tcg-engines/blob/main/README.md This snippet shows how to install project dependencies and run a CI check using the Bun package manager. It's a crucial first step for setting up the development environment. ```bash bun install bun run ci-check # Ensure everything passes ``` -------------------------------- ### Install fnm (Fast Node Manager) Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Installs fnm, a tool for managing Node.js versions. After installation, it's recommended to restart the terminal or source the shell configuration. ```bash curl -o- https://fnm.vercel.app/install | bash source ~/.bashrc # or source ~/.zshrc ``` -------------------------------- ### Quick Start: Testing Game Engine Moves and State Source: https://github.com/thecardgoat/tcg-engines/blob/main/packages/core/docs/guides/testing-utilities.md Demonstrates the basic TDD workflow: setting up a test engine, executing a move, and asserting state changes. It also shows how to use deterministic RNG for reproducible tests. ```typescript import { expectMoveSuccess, expectStateProperty, createTestCard, createTestDeck, withSeed, } from '@tcg/core/testing'; import { RuleEngine } from '@tcg/core'; // 1. Create test game setup const gameDefinition = { /* your game */ }; const engine = new RuleEngine(gameDefinition, players, { seed: 'test' }); // 2. Execute and test moves expectMoveSuccess(engine, 'playCard', { playerId: 'p1', data: { cardId: 'card-123' } }); // 3. Verify state changes expectStateProperty(engine, 'players[0].hand.length', 6); expectStateProperty(engine, 'field.length', 1); // 4. Test with deterministic RNG const shuffled = withSeed('test-seed', (rng) => { return rng.shuffle([1, 2, 3, 4, 5]); }); ``` -------------------------------- ### AI Agent Script Execution with Bun Source: https://github.com/thecardgoat/tcg-engines/blob/main/agents.md Shows how AI agents should execute scripts and packages using Bun, including running scripts from package.json and using `bunx` for package execution. ```bash bun run