Compare commits

21 Commits

Author SHA1 Message Date
42d70f0817 More readme cleanup. 2025-05-26 10:31:04 -04:00
c6cb37835f Added more images. 2025-05-26 10:14:57 -04:00
4982ff4005 Added screenshots. 2025-05-26 10:09:18 -04:00
69fd462bf5 added background to campain pill 2025-05-26 09:52:53 -04:00
e09739fc01 Removed UUIDs and added delete confirmation boxes. 2025-05-26 09:41:50 -04:00
a317038345 Added README.md 2025-05-26 09:33:12 -04:00
d27f7844a5 reverted the caraosel affect. Didn't like it. 2025-05-26 09:17:53 -04:00
34e40ae769 more view changes. 2025-05-26 09:11:29 -04:00
118804926f Changed view for more combatants. 2025-05-26 09:02:12 -04:00
f530d4303d Changed view for more than 7 combatants 2025-05-26 08:53:26 -04:00
d5b93ac66a refactor 2025-05-26 08:33:39 -04:00
d023da05a5 update text color 2025-05-26 08:18:13 -04:00
085303fbab changing the player display button. 2025-05-26 07:59:05 -04:00
eb114910f8 cleaned up dm eyeball toggle 2025-05-26 07:50:24 -04:00
c7215bb503 Merge branch 'main' of code.draft13.com:robert/ttrpg-initiative-tracker 2025-05-26 07:23:29 -04:00
91980c368f Changed .env.example 2025-05-26 07:18:55 -04:00
962c0bd911 more slight changes. 2025-05-25 23:28:36 -04:00
bfb0f20a25 Things are working now. 2025-05-25 22:48:17 -04:00
6d7f8b182c More work. 2025-05-25 22:21:45 -04:00
290f3816c5 Merge branch 'main' of code.draft13.com:robert/ttrpg-initiative-tracker 2025-05-25 21:21:31 -04:00
0772a3a9e6 More interations. 2025-05-25 21:19:22 -04:00
18 changed files with 21717 additions and 1141 deletions

View File

@ -15,7 +15,7 @@ Dockerfile
# Ignore any local environment files if you have them
.env
.env.local
# .env.local
.env.development.local
.env.test.local
.env.production.local

10
.gitignore vendored
View File

@ -1 +1,9 @@
.env*
# .gitignore
node_modules
build
dist
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

View File

@ -1,71 +1,45 @@
# Dockerfile
# Stage 1: Build the React application
FROM node:18-alpine AS build
# Set the working directory
LABEL stage="build-local-testing"
WORKDIR /app
# Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./
# If using yarn, uncomment the next line and comment out the npm ci line
# COPY yarn.lock ./
# Install dependencies
# If using yarn, replace 'npm ci' with 'yarn install --frozen-lockfile'
RUN npm ci
# Install dependencies using the lock file for consistency
RUN npm install
# Copy the rest of the application source code
COPY . .
# Build the application for production
# The REACT_APP_ID and REACT_APP_FIREBASE_CONFIG build arguments are optional.
# If you set them during your 'docker build' command, they will be baked into your static files.
# Otherwise, the application will rely on the __app_id and __firebase_config global variables
# being available in the environment where the built assets are served, or fall back to
# the hardcoded defaults in the React code if those globals are not present.
ARG REACT_APP_ID
ARG REACT_APP_FIREBASE_CONFIG
ENV VITE_APP_ID=$REACT_APP_ID
ENV VITE_FIREBASE_CONFIG=$REACT_APP_FIREBASE_CONFIG
# --- For Local Testing with .env.local ---
# Copy your .env.local file as .env in the build context.
# Create React App's build script will automatically load variables from this .env file.
# IMPORTANT: Ensure .env.local contains your actual Firebase API keys and other secrets.
# This .env.local file MUST be in your .gitignore and NOT committed to your repository.
# This Docker image, built this way, CONTAINS YOUR SECRETS and should NOT be pushed to a public registry.
COPY .env.local .env
# --- End Local Testing Section ---
# If your project uses Create React App (CRA - typically uses react-scripts build)
# RUN npm run build
# Build the application. react-scripts build will use environment variables
# prefixed with REACT_APP_ (either from the .env file copied above or from the build environment).
# Set NODE_OPTIONS to use the legacy OpenSSL provider for the build step.
RUN NODE_OPTIONS=--openssl-legacy-provider npm run build
# If your project uses Vite (which is common for modern React setups)
# Ensure your package.json's build script uses Vite.
# If you are using Vite, you might need to adjust environment variable prefixing
# (Vite uses VITE_ for env vars to be exposed on client).
# The React code I provided doesn't assume Vite or CRA specifically, but uses
# __app_id and __firebase_config which are meant to be injected at runtime/hosting.
# For a Docker build where these are baked in, you'd typically modify the React code
# to read from process.env.REACT_APP_... (for CRA) or import.meta.env.VITE_... (for Vite).
# Assuming your React app uses environment variables like REACT_APP_ prefixed variables
# (common with Create React App) or VITE_ prefixed for Vite.
# The provided React code uses __app_id and __firebase_config which are expected
# to be injected by the hosting environment. If you want to bake these into the
# Docker image at build time, you would modify the React code to consume them
# from process.env (for CRA) or import.meta.env (for Vite) and then set them here.
# For the current React code, it expects __app_id and __firebase_config to be
# globally available where it runs. If you want to hardcode them during Docker build,
# you'd need to modify the React code to read from standard env vars and then set them
# using ENV in the Dockerfile or pass them as build ARGs.
# Let's assume a standard 'npm run build' script in your package.json
RUN npm run build
# Stage 2: Serve the static files (Optional, if you want the image to be self-contained for serving)
# If you are handling Nginx externally, you might not need this stage.
# You would just copy the /app/build directory from the 'build' stage.
# However, for completeness or if you wanted an image that *can* serve itself:
# Stage 2: Serve the static files using Nginx
FROM nginx:1.25-alpine
LABEL stage="nginx-server"
# Copy the build output from the 'build' stage to Nginx's html directory
COPY --from=build /app/build /usr/share/nginx/html
# Expose port 80 for Nginx
# Expose port 80 (Nginx default)
EXPOSE 80
# Start Nginx when the container launches
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]

196
README.md Normal file
View File

@ -0,0 +1,196 @@
# TTRPG Initiative Tracker
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).
**Use at your own risk.**
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.
## Features
![DM View](images/dm_view.png)
* **Campaign Management:** Create campaigns to organize your game sessions.
* **Character Management:** Add and manage characters (player characters) within each campaign.
* **Encounter Management:**
* Create multiple encounters per campaign.
* Add characters and monsters to encounters with initiative scores and hit points.
* DM controls to start, advance turns, and end encounters.
* **Player Display:**
* A clean interface showing the current initiative order and participant HP (monster HP totals are hidden, only the bar is shown).
* Option to set a custom background image URL for the player display on a per-campaign basis.
* DM can activate/deactivate encounters for the player display.
* Player display can be opened in a separate window.
* **Real-time Updates:** Uses Firebase Firestore for real-time synchronization between DM actions and the player display.
* **Initiative Tie-Breaking:** DMs can drag-and-drop participants with tied initiative scores (before an encounter starts) to set a manual order.
* **Responsive Design:** Styled with Tailwind CSS for usability across different screen sizes.
## Tech Stack
* **Frontend:** React
* **Styling:** Tailwind CSS
* **Backend/Database:** Firebase Firestore (for real-time data)
* **Authentication:** Firebase Anonymous Authentication
## App Usage Overview
![Screenshots](images/header_image.png)
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.
* **Git:** For cloning the repository.
### Local Development Setup (using npm)
#### **Clone the Repository:**
```bash
git clone <your-repository-url>
cd ttrpg-initiative-tracker
```
#### **Create Firebase Configuration File (`.env.local`):**
* 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.
Your `.env.local` should look like this:
```ini
REACT_APP_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY"
REACT_APP_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN"
REACT_APP_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID"
REACT_APP_FIREBASE_STORAGE_BUCKET="YOUR_FIREBASE_STORAGE_BUCKET"
REACT_APP_FIREBASE_MESSAGING_SENDER_ID="YOUR_FIREBASE_MESSAGING_SENDER_ID"
REACT_APP_FIREBASE_APP_ID="YOUR_FIREBASE_APP_ID"
# Used for namespacing Firestore paths, can be any unique string for your app instance
REACT_APP_TRACKER_APP_ID="ttrpg-initiative-tracker-dev"
```
*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.**
```
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
```
* Publish these rules.
#### **Enable Anonymous Authentication:**
* In your Firebase project console -> Authentication -> Sign-in method.
* Enable "Anonymous" as a sign-in provider.
#### **Run the Development Server:**
```bash
npm start
```
This will start the React development server, usually on `http://localhost:3000`. The application will open in your default web browser.
### Deployment with Docker
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.
**1. Prerequisites for Docker:**
* Ensure Docker Desktop (or Docker Engine on Linux) is installed and running. Download from [docker.com](https://www.docker.com/products/docker-desktop).
**2. Building the Docker Image (for Local Testing with `.env.local`):**
* 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.
To build the image, navigate to the project root and run:
```bash
docker build -t ttrpg-initiative-tracker .
```
*(You can replace `ttrpg-initiative-tracker` with your preferred image name/tag).*
**3. Running the Docker Container Locally:**
Once the image is built, run it:
```bash
docker run -p 8080:80 --rm --name ttrpg-tracker-app ttrpg-initiative-tracker
```
* `-p 8080:80`: Maps port 8080 on your host machine to port 80 inside the container (where Nginx is listening).
* `--rm`: Automatically removes the container when it stops.
* `--name ttrpg-tracker-app`: Assigns a name to the running container.
* `ttrpg-initiative-tracker`: The name of the image you built.
You can then access the application at `http://localhost:8080`.
**4. Production Deployment Considerations:**
* 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.
## Project Structure
`ttrpg-initiative-tracker/`
- ` .dockerignore` # Specifies intentionally untracked files that Docker should ignore
- ` .env.example` # Example environment variables
- ` .env.local` # Local environment variables (ignored by Git)
- ` .gitignore` # Specifies intentionally untracked files that Git should ignore
- ` Dockerfile` # Instructions to build the Docker image
- ` package-lock.json` # Records exact versions of dependencies
- ` package.json` # Project metadata and dependencies
- ` postcss.config.js` # PostCSS configuration (for Tailwind CSS)
- ` tailwind.config.js` # Tailwind CSS configuration
- ` public/` # Static assets
- ` favicon.ico`
- ` index.html` # Main HTML template
- ` manifest.json`
- ` src/` # React application source code
- ` App.js` # Main application component
- ` index.css` # Global styles (including Tailwind directives)
- ` index.js` # React entry point
## Contributing
Feel free to fork the repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.

1090
app.js

File diff suppressed because it is too large Load Diff

9
env.example Normal file
View File

@ -0,0 +1,9 @@
# .env.example
REACT_APP_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY_HERE"
REACT_APP_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN_HERE"
REACT_APP_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID_HERE"
REACT_APP_FIREBASE_STORAGE_BUCKET="YOUR_FIREBASE_STORAGE_BUCKET_HERE"
REACT_APP_FIREBASE_MESSAGING_SENDER_ID="YOUR_FIREBASE_MESSAGING_SENDER_ID_HERE"
REACT_APP_FIREBASE_APP_ID="YOUR_FIREBASE_APP_ID_HERE"
REACT_APP_TRACKER_APP_ID="ttrpg-initiative-tracker-default"

BIN
images/dm_view.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

BIN
images/header_image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

20088
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

43
package.json Normal file
View File

@ -0,0 +1,43 @@
{
"name": "ttrpg-initiative-tracker",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"firebase": "^10.12.2",
"lucide-react": "^0.395.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

7
postcss.config.js Normal file
View File

@ -0,0 +1,7 @@
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

0
public/favico.ico Normal file
View File

19
public/index.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#2D3748" /> <meta
name="description"
content="A web-based TTRPG Initiative Tracker"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>TTRPG Initiative Tracker</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

25
public/manifest.json Normal file
View File

@ -0,0 +1,25 @@
{
"short_name": "TTRPG Tracker",
"name": "TTRPG Initiative Tracker",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#2D3748",
"background_color": "#1A202C"
}

1249
src/App.js Normal file

File diff suppressed because it is too large Load Diff

25
src/index.css Normal file
View File

@ -0,0 +1,25 @@
/* src/index.css */
/* If using Tailwind CSS, you would typically import its base styles, components, and utilities here */
/* For example, if you followed Tailwind's setup guide for Create React App: */
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* background-color: #1A202C; /* Tailwind Slate 900 */
/* color: #E2E8F0; /* Tailwind Slate 200 */
/* These will likely be overridden by the App component's Tailwind classes */
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
/* Add any other global base styles here */

11
src/index.js Normal file
View File

@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css'; // Your global styles / Tailwind imports
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

12
tailwind.config.js Normal file
View File

@ -0,0 +1,12 @@
// tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}", // Standard for CRA
"./public/index.html"
],
theme: {
extend: {},
},
plugins: [],
}