Added collapsible Characters.
This commit is contained in:
parent
dda3453d79
commit
8cf3a49a76
270
README.md
270
README.md
@ -1,31 +1,39 @@
|
|||||||
# TTRPG Initiative Tracker
|
# TTRPG Initiative Tracker (v0.2.1)
|
||||||
|
|
||||||
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).
|
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.**
|
**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.
|
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.
|
||||||
|
|
||||||
Have you tried it? Got feedback or questions? Discuss here: [https://discourse.draft13.com/c/ttrpg-initiative-tracker/16](https://discourse.draft13.com/c/ttrpg-initiative-tracker/16)
|
Have you tried it? Got feedback or questions? Discuss here: [https://discourse.draft13.com/c/ttrpg-initiative-tracker/16](https://discourse.draft13.com/c/ttrpg-initiative-tracker/16)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||

|
* **Campaign Management:**
|
||||||
|
* Create campaigns to organize game sessions.
|
||||||
* **Campaign Management:** Create campaigns to organize your game sessions.
|
* Option to set a custom background image URL for the player display on a per-campaign basis.
|
||||||
* **Character Management:** Add and manage characters (player characters) within each campaign.
|
* Campaign cards display the number of characters and encounters.
|
||||||
|
* **Character Management:**
|
||||||
|
* Add and manage characters (player characters) within each campaign.
|
||||||
|
* Set default Max HP and default Initiative Modifier for each campaign character.
|
||||||
* **Encounter Management:**
|
* **Encounter Management:**
|
||||||
* Create multiple encounters per campaign.
|
* Create multiple encounters per campaign.
|
||||||
* Add characters and monsters to encounters with initiative scores and hit points.
|
* Add characters from the campaign roster (with auto-rolled initiative based on their modifier and HP pre-filled from campaign defaults) or add custom monsters.
|
||||||
* DM controls to start, advance turns, and end encounters.
|
* Monsters have an editable default initiative modifier (pre-filled at +2) and can be marked as NPCs.
|
||||||
|
* "Add All Campaign Characters" button for quickly populating encounters with initiative rolls.
|
||||||
|
* DM controls to start, pause/resume, advance turns, and end encounters.
|
||||||
|
* Visual feedback for rolled initiative when adding individual participants.
|
||||||
* **Player Display:**
|
* **Player Display:**
|
||||||
* A clean interface showing the current initiative order and participant HP (monster HP totals are hidden, only the bar is shown).
|
* A clean interface showing the current initiative order, participant HP (monster HP totals are hidden, only the bar is shown), and current turn.
|
||||||
* Option to set a custom background image URL for the player display on a per-campaign basis.
|
* NPCs (monster-type) are visually distinct from hostile monsters.
|
||||||
* DM can activate/deactivate encounters for the player display.
|
* Displays custom campaign background if set.
|
||||||
* Player display can be opened in a separate window.
|
* Shows a "Game Session Paused" message when no encounter is active or if the current encounter is paused by the DM.
|
||||||
|
* Player display is opened in a separate window via a button in the DM's header.
|
||||||
* **Real-time Updates:** Uses Firebase Firestore for real-time synchronization between DM actions and the player display.
|
* **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.
|
* **Initiative Tie-Breaking:** DMs can drag-and-drop participants with tied initiative scores (before an encounter starts or while paused) to set a manual order.
|
||||||
* **Responsive Design:** Styled with Tailwind CSS for usability across different screen sizes.
|
* **Responsive Design:** Styled with Tailwind CSS.
|
||||||
|
* **Confirmation Modals:** Implemented for destructive actions like deleting campaigns, characters, encounters, or ending combat.
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
@ -36,33 +44,37 @@ Have you tried it? Got feedback or questions? Discuss here: [https://discourse.d
|
|||||||
|
|
||||||
## App Usage Overview
|
## App Usage Overview
|
||||||
|
|
||||||

|

|
||||||
|
*(Replace with an actual screenshot of your DM view)*
|
||||||
|
|
||||||
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:
|
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):**
|
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.
|
* **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. Campaign cards will show a preview of this background.
|
||||||
* **Add Characters:** Within a campaign, add your player characters to the campaign roster.
|
* **Add Characters:** Within a campaign, add your player characters. For each, set their name, default maximum HP, and a default initiative modifier. This section is collapsible to save screen space.
|
||||||
* **Create Encounters:** For each combat scenario, create an encounter within the selected campaign.
|
* **Create Encounters:** For each combat scenario, create an encounter within the selected campaign.
|
||||||
* **Manage Participants:**
|
* **Manage Participants:**
|
||||||
* Add characters from your campaign roster and any monsters to the selected encounter.
|
* Add characters from your campaign roster. Their Max HP will pre-fill from their campaign default, and their initiative will be automatically rolled (d20 + their default modifier).
|
||||||
* Set their initiative scores and maximum hit points.
|
* Add monsters. Provide a name, Max HP, and an initiative modifier (defaults to +2 but is editable). Mark if the monster is an "NPC" for different styling. Their initiative will be automatically rolled (d20 + specified modifier).
|
||||||
* If there are ties in initiative, you can drag and drop participants (before starting the encounter) to set a specific tie-breaker order.
|
* Use the "Add All From Campaign (Roll Init)" button to quickly add all campaign characters not yet in the encounter, with their initiative rolled and HP set from defaults.
|
||||||
|
* If there are ties in initiative, you can drag and drop participants (before starting the encounter or while it's paused) to set a specific tie-breaker order.
|
||||||
* **Control Player Display:**
|
* **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). This window's content is controlled by the DM.
|
||||||
* Click the "Open Player Window" button in the header to launch a separate, clean window for your players (ideal for an external monitor).
|
* Use the "eyeball" icon next to an encounter to toggle it as "LIVE ON PLAYER DISPLAY". This controls what is shown on the Player Display window. Only one encounter can be live at a time.
|
||||||
* **Run Combat:**
|
* **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.
|
* Once participants are added and initiative is set, 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.
|
* Use the "Pause" button to temporarily halt combat. While paused, you can adjust HP and re-order tied initiatives. Click "Resume" to continue.
|
||||||
* Apply damage or healing to participants directly in the Admin View during combat.
|
* Use the "Next Turn" button (disabled when paused) to advance through the initiative order. The current combatant will be highlighted.
|
||||||
|
* Apply damage or healing to participants directly in the Admin View.
|
||||||
* Mark participants as inactive (e.g., if knocked out) using the toggle next to their name.
|
* 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.
|
* Click "End Encounter" (with confirmation) when combat is over. This also deactivates it from the Player Display.
|
||||||
|
|
||||||
2. **Player Display Window:**
|
2. **Player Display Window:**
|
||||||
* This window (opened by the DM) shows a simplified view of the active encounter.
|
* This window (opened by the DM via `/?playerView=true` URL) shows a simplified, header-less 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).
|
* It displays the initiative order, current turn, round number, and participant HP (monster/NPC HP values are hidden, only the bar is shown).
|
||||||
|
* NPCs are styled with a muted gray background, distinct from hostile monsters (custom reddish-brown) and player characters (blueish).
|
||||||
* If a custom background URL was set for the campaign, it will be displayed.
|
* 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.
|
* If no encounter is active on the Player Display, or if the current encounter is paused by the DM, it will show an appropriate message ("Game Session Paused" or "Combat Paused").
|
||||||
|
|
||||||
This flow allows the DM to prepare and run encounters efficiently while providing a clear, real-time view for the players.
|
This flow allows the DM to prepare and run encounters efficiently while providing a clear, real-time view for the players.
|
||||||
|
|
||||||
@ -71,67 +83,65 @@ This flow allows the DM to prepare and run encounters efficiently while providin
|
|||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
* **Node.js and npm:** Ensure you have Node.js (which includes npm) installed. You can download it from [nodejs.org](https://nodejs.org/).
|
* **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.
|
* **Firebase Project:** You'll need a Firebase project with:
|
||||||
|
* Firestore Database created and initialized.
|
||||||
|
* Anonymous Authentication enabled in the "Authentication" > "Sign-in method" tab.
|
||||||
* **Git:** For cloning the repository.
|
* **Git:** For cloning the repository.
|
||||||
|
|
||||||
### Local Development Setup (using npm)
|
### Local Development Setup (using npm)
|
||||||
|
|
||||||
#### **Clone the Repository:**
|
1. **Clone the Repository:**
|
||||||
```bash
|
```bash
|
||||||
git clone https://code.draft13.com/robert/ttrpg-initiative-tracker.git
|
git clone <your-repository-url>
|
||||||
cd ttrpg-initiative-tracker
|
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 {
|
2. **Create Firebase Configuration File (`.env.local`):**
|
||||||
match /databases/{database}/documents {
|
* In the root of the project, create a file named `.env.local`.
|
||||||
match /{document=**} {
|
* 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).
|
||||||
allow read, write: if request.auth != null;
|
* **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"
|
||||||
```
|
```
|
||||||
* Publish these rules.
|
*An `.env.example` file is included in the repository as a template.*
|
||||||
|
|
||||||
#### **Enable Anonymous Authentication:**
|
3. **Install Dependencies:**
|
||||||
* In your Firebase project console -> Authentication -> Sign-in method.
|
Navigate to the project root in your terminal and run:
|
||||||
* Enable "Anonymous" as a sign-in provider.
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
This will install all the necessary packages defined in `package.json` and create a `package-lock.json` file.
|
||||||
|
|
||||||
#### **Run the Development Server:**
|
4. **Set up Firestore Security Rules:**
|
||||||
```bash
|
* Go to your Firebase project console -> Firestore Database -> Rules.
|
||||||
npm start
|
* Use the following rules for development (allows authenticated users to read/write all data). **For production, you MUST implement more restrictive rules.**
|
||||||
```
|
```
|
||||||
This will start the React development server, usually on `http://localhost:3000`. The application will open in your default web browser.
|
rules_version = '2';
|
||||||
|
service cloud.firestore {
|
||||||
|
match /databases/{database}/documents {
|
||||||
|
match /{document=**} {
|
||||||
|
allow read, write: if request.auth != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* Publish these rules.
|
||||||
|
|
||||||
|
5. **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
|
### Deployment with Docker
|
||||||
|
|
||||||
@ -139,60 +149,62 @@ This project includes a `Dockerfile` to containerize the application for deploym
|
|||||||
* **Stage 1 (build):** Installs dependencies, copies your `.env.local` (for local testing builds), and builds the static React application using `npm run 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.
|
* **Stage 2 (nginx):** Uses an Nginx server to serve the static files produced in the build stage.
|
||||||
|
|
||||||
**1. Prerequisites for Docker:**
|
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).
|
* 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`):**
|
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.
|
* 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.
|
* **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:
|
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).*
|
||||||
|
|
||||||
```bash
|
3. **Running the Docker Container Locally:**
|
||||||
docker build -t ttrpg-initiative-tracker .
|
Once the image is built, run it:
|
||||||
```
|
```bash
|
||||||
*(You can replace `ttrpg-initiative-tracker` with your preferred image name/tag).*
|
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.
|
||||||
|
|
||||||
**3. Running the Docker Container Locally:**
|
You can then access the application at `http://localhost:8080`.
|
||||||
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.
|
||||||
**4. Production Deployment Considerations:**
|
* 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.
|
||||||
* 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.
|
* **Implement strict Firebase Security Rules** appropriate for a production application to protect your data.
|
||||||
* 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
|
## Project Structure
|
||||||
|
|
||||||
`ttrpg-initiative-tracker/`
|
<pre>
|
||||||
- ` .dockerignore` # Specifies intentionally untracked files that Docker should ignore
|
|
||||||
- ` .env.example` # Example environment variables
|
ttrpg-initiative-tracker/
|
||||||
- ` .env.local` # Local environment variables (ignored by Git)
|
├── .dockerignore # Specifies intentionally untracked files that Docker should ignore
|
||||||
- ` .gitignore` # Specifies intentionally untracked files that Git should ignore
|
├── .env.example # Example environment variables
|
||||||
- ` Dockerfile` # Instructions to build the Docker image
|
├── .env.local # Local environment variables (ignored by Git)
|
||||||
- ` package-lock.json` # Records exact versions of dependencies
|
├── .gitignore # Specifies intentionally untracked files that Git should ignore
|
||||||
- ` package.json` # Project metadata and dependencies
|
├── Dockerfile # Instructions to build the Docker image
|
||||||
- ` postcss.config.js` # PostCSS configuration (for Tailwind CSS)
|
├── package-lock.json # Records exact versions of dependencies
|
||||||
- ` tailwind.config.js` # Tailwind CSS configuration
|
├── package.json # Project metadata and dependencies
|
||||||
- ` public/` # Static assets
|
├── postcss.config.js # PostCSS configuration (for Tailwind CSS)
|
||||||
- ` favicon.ico`
|
├── tailwind.config.js # Tailwind CSS configuration
|
||||||
- ` index.html` # Main HTML template
|
├── public/ # Static assets
|
||||||
- ` manifest.json`
|
│ ├── favicon.ico
|
||||||
- ` src/` # React application source code
|
│ ├── index.html # Main HTML template
|
||||||
- ` App.js` # Main application component
|
│ └── manifest.json
|
||||||
- ` index.css` # Global styles (including Tailwind directives)
|
└── src/ # React application source code
|
||||||
- ` index.js` # React entry point
|
├── App.js # Main application component
|
||||||
|
├── index.css # Global styles (including Tailwind directives)
|
||||||
|
└── index.js # React entry point
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
## Contributing
|
## 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.
|
If you want to contribute, send me a message here: [https://discourse.draft13.com/c/ttrpg-initiative-tracker/16](https://discourse.draft13.com/c/ttrpg-initiative-tracker/16), and I can add to this Gitea instance and you can feel free to fork the repository and submit pull requests. For major changes, please pose a topic to the Discourse instance above linked above first to discuss what you would like to change.
|
||||||
|
107
src/App.js
107
src/App.js
@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef, useMemo } from 'react';
|
|||||||
import { initializeApp } from 'firebase/app';
|
import { initializeApp } from 'firebase/app';
|
||||||
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from 'firebase/auth';
|
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from 'firebase/auth';
|
||||||
import { getFirestore, doc, setDoc, getDoc, getDocs, collection, onSnapshot, updateDoc, deleteDoc, query, writeBatch } from 'firebase/firestore';
|
import { getFirestore, doc, setDoc, getDoc, getDocs, collection, onSnapshot, updateDoc, deleteDoc, query, writeBatch } from 'firebase/firestore';
|
||||||
import { PlusCircle, Users, Swords, Trash2, Eye, Edit3, Save, XCircle, ChevronsUpDown, UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle, Play as PlayIcon, Pause as PauseIcon, SkipForward as SkipForwardIcon, StopCircle as StopCircleIcon, Users2, Dices } from 'lucide-react';
|
import { PlusCircle, Users, Swords, Trash2, Eye, Edit3, Save, XCircle, ChevronsUpDown, UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle, Play as PlayIcon, Pause as PauseIcon, SkipForward as SkipForwardIcon, StopCircle as StopCircleIcon, Users2, Dices, ChevronDown, ChevronUp } from 'lucide-react'; // Added ChevronDown, ChevronUp
|
||||||
|
|
||||||
// --- Firebase Configuration ---
|
// --- Firebase Configuration ---
|
||||||
const firebaseConfig = {
|
const firebaseConfig = {
|
||||||
@ -214,16 +214,13 @@ function App() {
|
|||||||
{!isAuthReady && !error && <p>Authenticating...</p>}
|
{!isAuthReady && !error && <p>Authenticating...</p>}
|
||||||
</main>
|
</main>
|
||||||
<footer className="bg-slate-900 p-4 text-center text-sm text-slate-400 mt-8">
|
<footer className="bg-slate-900 p-4 text-center text-sm text-slate-400 mt-8">
|
||||||
TTRPG Initiative Tracker v0.2.0
|
TTRPG Initiative Tracker v0.2.1
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Confirmation Modal Component ---
|
// --- Confirmation Modal Component ---
|
||||||
// ... (ConfirmationModal, AdminView, CreateCampaignForm, CharacterManager, EncounterManager, CreateEncounterForm, ParticipantManager, EditParticipantModal, InitiativeControls, DisplayView, Modal, Icons remain the same as v0.1.29)
|
|
||||||
// For brevity, only the changed App component's footer is shown. Assume all other components are the same as the last complete code block you received.
|
|
||||||
|
|
||||||
function ConfirmationModal({ isOpen, onClose, onConfirm, title, message }) {
|
function ConfirmationModal({ isOpen, onClose, onConfirm, title, message }) {
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
return (
|
return (
|
||||||
@ -243,6 +240,7 @@ function ConfirmationModal({ isOpen, onClose, onConfirm, title, message }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Admin View Component ---
|
||||||
function AdminView({ userId }) {
|
function AdminView({ userId }) {
|
||||||
const { data: campaignsData, isLoading: isLoadingCampaigns, error: campaignsError } = useFirestoreCollection(getCampaignsCollectionPath());
|
const { data: campaignsData, isLoading: isLoadingCampaigns, error: campaignsError } = useFirestoreCollection(getCampaignsCollectionPath());
|
||||||
const { data: initialActiveInfoData } = useFirestoreDocument(getActiveDisplayDocPath());
|
const { data: initialActiveInfoData } = useFirestoreDocument(getActiveDisplayDocPath());
|
||||||
@ -416,6 +414,8 @@ function CharacterManager({ campaignId, campaignCharacters }) {
|
|||||||
const [editingCharacter, setEditingCharacter] = useState(null);
|
const [editingCharacter, setEditingCharacter] = useState(null);
|
||||||
const [showDeleteCharConfirm, setShowDeleteCharConfirm] = useState(false);
|
const [showDeleteCharConfirm, setShowDeleteCharConfirm] = useState(false);
|
||||||
const [itemToDelete, setItemToDelete] = useState(null);
|
const [itemToDelete, setItemToDelete] = useState(null);
|
||||||
|
const [isCharactersSectionOpen, setIsCharactersSectionOpen] = useState(true); // ADDED THIS LINE
|
||||||
|
|
||||||
const handleAddCharacter = async () => {
|
const handleAddCharacter = async () => {
|
||||||
if (!db ||!characterName.trim() || !campaignId) return;
|
if (!db ||!characterName.trim() || !campaignId) return;
|
||||||
const hp = parseInt(defaultMaxHp, 10);
|
const hp = parseInt(defaultMaxHp, 10);
|
||||||
@ -445,52 +445,69 @@ function CharacterManager({ campaignId, campaignCharacters }) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="p-4 bg-slate-800 rounded-lg shadow">
|
<div className="p-4 bg-slate-800 rounded-lg shadow">
|
||||||
<h3 className="text-xl font-semibold text-sky-300 mb-3 flex items-center"><Users size={24} className="mr-2" /> Campaign Characters</h3>
|
<div className="flex justify-between items-center mb-3"> {/* ADDED THIS DIV FOR HEADER AND TOGGLE */}
|
||||||
<form onSubmit={(e) => { e.preventDefault(); handleAddCharacter(); }} className="grid grid-cols-1 sm:grid-cols-3 gap-2 mb-4 items-end">
|
<h3 className="text-xl font-semibold text-sky-300 flex items-center"><Users size={24} className="mr-2" /> Campaign Characters</h3>
|
||||||
<div className="sm:col-span-1">
|
<button
|
||||||
<label htmlFor="characterName" className="block text-xs font-medium text-slate-400">Name</label>
|
onClick={() => setIsCharactersSectionOpen(!isCharactersSectionOpen)}
|
||||||
<input type="text" id="characterName" value={characterName} onChange={(e) => setCharacterName(e.target.value)} placeholder="New character name" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
className="p-1 text-slate-400 hover:text-slate-200"
|
||||||
</div>
|
aria-label={isCharactersSectionOpen ? "Collapse Characters Section" : "Expand Characters Section"}
|
||||||
<div className="w-full sm:w-auto">
|
>
|
||||||
<label htmlFor="defaultMaxHp" className="block text-xs font-medium text-slate-400">Default HP</label>
|
{isCharactersSectionOpen ? <ChevronUp size={20} /> : <ChevronDown size={20} />}
|
||||||
<input type="number" id="defaultMaxHp" value={defaultMaxHp} onChange={(e) => setDefaultMaxHp(e.target.value)} placeholder="HP" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full sm:w-auto">
|
|
||||||
<label htmlFor="defaultInitMod" className="block text-xs font-medium text-slate-400">Init Mod</label>
|
{isCharactersSectionOpen && ( // ADDED CONDITIONAL RENDERING
|
||||||
<input type="number" id="defaultInitMod" value={defaultInitMod} onChange={(e) => setDefaultInitMod(e.target.value)} placeholder="+0" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
<>
|
||||||
</div>
|
<form onSubmit={(e) => { e.preventDefault(); handleAddCharacter(); }} className="grid grid-cols-1 sm:grid-cols-3 gap-2 mb-4 items-end">
|
||||||
<button type="submit" className="sm:col-span-3 sm:w-auto sm:justify-self-end px-4 py-2 text-sm font-medium text-white bg-sky-500 hover:bg-sky-600 rounded-md transition-colors flex items-center justify-center"><PlusCircle size={18} className="mr-1" /> Add Character</button>
|
<div className="sm:col-span-1">
|
||||||
</form>
|
<label htmlFor="characterName" className="block text-xs font-medium text-slate-400">Name</label>
|
||||||
{campaignCharacters.length === 0 && <p className="text-sm text-slate-400">No characters added.</p>}
|
<input type="text" id="characterName" value={characterName} onChange={(e) => setCharacterName(e.target.value)} placeholder="New character name" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
||||||
<ul className="space-y-2">
|
</div>
|
||||||
{campaignCharacters.map(character => (
|
<div className="w-full sm:w-auto">
|
||||||
<li key={character.id} className="flex justify-between items-center p-3 bg-slate-700 rounded-md">
|
<label htmlFor="defaultMaxHp" className="block text-xs font-medium text-slate-400">Default HP</label>
|
||||||
{editingCharacter && editingCharacter.id === character.id ? (
|
<input type="number" id="defaultMaxHp" value={defaultMaxHp} onChange={(e) => setDefaultMaxHp(e.target.value)} placeholder="HP" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
||||||
<form onSubmit={(e) => {e.preventDefault(); handleUpdateCharacter(character.id, editingCharacter.name, editingCharacter.defaultMaxHp, editingCharacter.defaultInitMod);}} className="flex-grow flex flex-wrap gap-2 items-center">
|
</div>
|
||||||
<input type="text" value={editingCharacter.name} onChange={(e) => setEditingCharacter({...editingCharacter, name: e.target.value})} className="flex-grow min-w-[100px] px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white"/>
|
<div className="w-full sm:w-auto">
|
||||||
<input type="number" value={editingCharacter.defaultMaxHp} onChange={(e) => setEditingCharacter({...editingCharacter, defaultMaxHp: e.target.value})} className="w-20 px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white" title="Default Max HP"/>
|
<label htmlFor="defaultInitMod" className="block text-xs font-medium text-slate-400">Init Mod</label>
|
||||||
<input type="number" value={editingCharacter.defaultInitMod} onChange={(e) => setEditingCharacter({...editingCharacter, defaultInitMod: e.target.value})} className="w-20 px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white" title="Default Init Mod"/>
|
<input type="number" id="defaultInitMod" value={defaultInitMod} onChange={(e) => setDefaultInitMod(e.target.value)} placeholder="+0" className="w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
|
||||||
<button type="submit" className="p-1 text-green-400 hover:text-green-300"><Save size={18}/></button>
|
</div>
|
||||||
<button type="button" onClick={() => setEditingCharacter(null)} className="p-1 text-slate-400 hover:text-slate-200"><XCircle size={18}/></button>
|
<button type="submit" className="sm:col-span-3 sm:w-auto sm:justify-self-end px-4 py-2 text-sm font-medium text-white bg-sky-500 hover:bg-sky-600 rounded-md transition-colors flex items-center justify-center"><PlusCircle size={18} className="mr-1" /> Add Character</button>
|
||||||
</form>
|
</form>
|
||||||
) : (
|
{campaignCharacters.length === 0 && <p className="text-sm text-slate-400">No characters added.</p>}
|
||||||
<>
|
<ul className="space-y-2">
|
||||||
<span className="text-slate-100">{character.name} <span className="text-xs text-slate-400">(HP: {character.defaultMaxHp || 'N/A'}, Init Mod: {character.defaultInitMod !== undefined ? (character.defaultInitMod >= 0 ? `+${character.defaultInitMod}` : character.defaultInitMod) : 'N/A'})</span></span>
|
{campaignCharacters.map(character => (
|
||||||
<div className="flex space-x-2">
|
<li key={character.id} className="flex justify-between items-center p-3 bg-slate-700 rounded-md">
|
||||||
<button onClick={() => setEditingCharacter({id: character.id, name: character.name, defaultMaxHp: character.defaultMaxHp || 10, defaultInitMod: character.defaultInitMod || 0})} className="p-1 rounded transition-colors text-yellow-400 hover:text-yellow-300 bg-slate-600 hover:bg-slate-500" aria-label="Edit character"><Edit3 size={18} /></button>
|
{editingCharacter && editingCharacter.id === character.id ? (
|
||||||
<button onClick={() => requestDeleteCharacter(character.id, character.name)} className="p-1 rounded transition-colors text-red-400 hover:text-red-300 bg-slate-600 hover:bg-slate-500" aria-label="Delete character"><Trash2 size={18} /></button>
|
<form onSubmit={(e) => {e.preventDefault(); handleUpdateCharacter(character.id, editingCharacter.name, editingCharacter.defaultMaxHp, editingCharacter.defaultInitMod);}} className="flex-grow flex flex-wrap gap-2 items-center">
|
||||||
</div>
|
<input type="text" value={editingCharacter.name} onChange={(e) => setEditingCharacter({...editingCharacter, name: e.target.value})} className="flex-grow min-w-[100px] px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white"/>
|
||||||
</>
|
<input type="number" value={editingCharacter.defaultMaxHp} onChange={(e) => setEditingCharacter({...editingCharacter, defaultMaxHp: e.target.value})} className="w-20 px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white" title="Default Max HP"/>
|
||||||
)}
|
<input type="number" value={editingCharacter.defaultInitMod} onChange={(e) => setEditingCharacter({...editingCharacter, defaultInitMod: e.target.value})} className="w-20 px-2 py-1 bg-slate-600 border border-slate-500 rounded-md text-white" title="Default Init Mod"/>
|
||||||
</li>
|
<button type="submit" className="p-1 text-green-400 hover:text-green-300"><Save size={18}/></button>
|
||||||
))}
|
<button type="button" onClick={() => setEditingCharacter(null)} className="p-1 text-slate-400 hover:text-slate-200"><XCircle size={18}/></button>
|
||||||
</ul>
|
</form>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="text-slate-100">{character.name} <span className="text-xs text-slate-400">(HP: {character.defaultMaxHp || 'N/A'}, Init Mod: {character.defaultInitMod !== undefined ? (character.defaultInitMod >= 0 ? `+${character.defaultInitMod}` : character.defaultInitMod) : 'N/A'})</span></span>
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<button onClick={() => setEditingCharacter({id: character.id, name: character.name, defaultMaxHp: character.defaultMaxHp || 10, defaultInitMod: character.defaultInitMod || 0})} className="p-1 rounded transition-colors text-yellow-400 hover:text-yellow-300 bg-slate-600 hover:bg-slate-500" aria-label="Edit character"><Edit3 size={18} /></button>
|
||||||
|
<button onClick={() => requestDeleteCharacter(character.id, character.name)} className="p-1 rounded transition-colors text-red-400 hover:text-red-300 bg-slate-600 hover:bg-slate-500" aria-label="Delete character"><Trash2 size={18} /></button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ConfirmationModal isOpen={showDeleteCharConfirm} onClose={() => setShowDeleteCharConfirm(false)} onConfirm={confirmDeleteCharacter} title="Delete Character?" message={`Are you sure you want to remove the character "${itemToDelete?.name}" from this campaign?`}/>
|
<ConfirmationModal isOpen={showDeleteCharConfirm} onClose={() => setShowDeleteCharConfirm(false)} onConfirm={confirmDeleteCharacter} title="Delete Character?" message={`Are you sure you want to remove the character "${itemToDelete?.name}" from this campaign?`}/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... (EncounterManager, CreateEncounterForm, ParticipantManager, EditParticipantModal, InitiativeControls, DisplayView, Modal, Icons)
|
||||||
|
// The rest of the components are assumed to be the same as v0.1.30 for this update.
|
||||||
|
|
||||||
function EncounterManager({ campaignId, initialActiveEncounterId, campaignCharacters }) {
|
function EncounterManager({ campaignId, initialActiveEncounterId, campaignCharacters }) {
|
||||||
const {data: encountersData, isLoading: isLoadingEncounters } = useFirestoreCollection(campaignId ? getEncountersCollectionPath(campaignId) : null);
|
const {data: encountersData, isLoading: isLoadingEncounters } = useFirestoreCollection(campaignId ? getEncountersCollectionPath(campaignId) : null);
|
||||||
const {data: activeDisplayInfoFromHook } = useFirestoreDocument(getActiveDisplayDocPath());
|
const {data: activeDisplayInfoFromHook } = useFirestoreDocument(getActiveDisplayDocPath());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user