This application is the result of not having the exact tool I want to use, and a few sessions of [vibe-coding](https://www.youtube.com/watch?v=Tw18-4U7mts) with [Google Gemini](https://developers.google.com/gemini-code-assist/docs/overview).
A web-based application designed to help Dungeon Masters (DMs) manage and display combat initiative for tabletop role-playing games (TTRPGs). It features a DM admin interface for controlling encounters and a separate player display view suitable for an external monitor or for players to view on their own devices.
The TTRPG Initiative Tracker is designed for Dungeon Masters to manage combat encounters and display the initiative order to players. Here's a typical workflow:
1.**Admin Interface (DM's View):**
* **Create a Campaign:** Start by creating a new campaign. You can optionally provide a URL for a custom background image that will be shown on the Player Display for this campaign.
* **Add Characters:** Within a campaign, add your player characters to the campaign roster.
* **Create Encounters:** For each combat scenario, create an encounter within the selected campaign.
* **Manage Participants:**
* Add characters from your campaign roster and any monsters to the selected encounter.
* Set their initiative scores and maximum hit points.
* If there are ties in initiative, you can drag and drop participants (before starting the encounter) to set a specific tie-breaker order.
* **Control Player Display:**
* Use the "eyeball" icon next to an encounter to toggle it as "LIVE ON PLAYER DISPLAY". This controls what is shown on the separate Player Display window. Only one encounter can be live at a time.
* Click the "Open Player Window" button in the header to launch a separate, clean window for your players (ideal for an external monitor).
* **Run Combat:**
* Once participants are added and initiative is set (including any manual tie-breaking), click "Start Encounter". This also automatically makes the encounter live on the Player Display.
* Use the "Next Turn" button to advance through the initiative order. The current combatant will be highlighted in both the Admin View and the Player Display.
* Apply damage or healing to participants directly in the Admin View during combat.
* Mark participants as inactive (e.g., if knocked out) using the toggle next to their name.
* Click "End Encounter" when combat is over. This will also deactivate it from the Player Display.
2.**Player Display Window:**
* This window (opened by the DM) shows a simplified view of the active encounter.
* It displays the initiative order, current turn, round number, and participant HP (monster HP values are hidden, only the bar is shown).
* If a custom background URL was set for the campaign, it will be displayed.
* If no encounter is active on the Player Display, it will show a "Game Session Paused" message.
This flow allows the DM to prepare and run encounters efficiently while providing a clear, real-time view for the players.
## Getting Started
### Prerequisites
* **Node.js and npm:** Ensure you have Node.js (which includes npm) installed. You can download it from [nodejs.org](https://nodejs.org/).
* **Firebase Project:** You'll need a Firebase project with Firestore Database and Anonymous Authentication enabled.
* In the root of the project, create a file named `.env.local`.
* Add your Firebase project configuration details to this file. You can find these in your Firebase project settings (Project settings > General > Your apps > Firebase SDK snippet > Config).
* **Important:** This `.env.local` file contains sensitive API keys and should **NOT** be committed to Git. Make sure it's listed in your `.gitignore` file.
*An `.env.example` file is included in the repository as a template.*
#### **Install Dependencies:**
Navigate to the project root in your terminal and run:
```bash
npm install
```
This will install all the necessary packages defined in `package.json` and create a `package-lock.json` file.
#### **Set up Firestore Security Rules:**
* Go to your Firebase project console -> Firestore Database -> Rules.
* Use the following rules for development (allows authenticated users to read/write all data). **For production, you MUST implement more restrictive rules.**
This project includes a `Dockerfile` to containerize the application for deployment. It uses a multi-stage build:
* **Stage 1 (build):** Installs dependencies, copies your `.env.local` (for local testing builds), and builds the static React application using `npm run build`.
* **Stage 2 (nginx):** Uses an Nginx server to serve the static files produced in the build stage.
* Ensure Docker Desktop (or Docker Engine on Linux) is installed and running. Download from [docker.com](https://www.docker.com/products/docker-desktop).
* Make sure your `.env.local` file is present in the project root and correctly configured with your Firebase details. The `Dockerfile` is set up to copy this file as `.env` during the build for local testing.
* **Security Warning:** The image built this way will contain your Firebase API keys from `.env.local`. **Do NOT push this specific image to a public Docker registry.** For production, environment variables should be injected by your hosting platform or CI/CD pipeline at build or runtime.
* When deploying to a production environment (e.g., a cloud provider, your own server), you should **not** copy your `.env.local` file into the Docker image.
* Instead, configure the `REACT_APP_FIREBASE_...` environment variables directly in your hosting platform's settings or pass them to the Docker container at runtime (if your application is set up to read them at runtime, though Create React App bakes them in at build time).
* If your CI/CD pipeline builds the Docker image, ensure these environment variables are securely provided to the build environment.
* **Implement strict Firebase Security Rules** appropriate for a production application to protect your data.