Compare commits

33 Commits

Author SHA1 Message Date
8cf3a49a76 Added collapsible Characters. 2025-05-28 14:58:54 -04:00
dda3453d79 version bump. 2025-05-28 12:23:10 -04:00
d754f8657c Added small counters in Campaign cards. 2025-05-28 12:15:01 -04:00
9563ce7959 fixed player display on added participant to live encounter 2025-05-27 14:52:04 -04:00
5f8602cd73 changed red color for monster display. 2025-05-27 11:15:32 -04:00
788e3cd1a2 Tightened up the UI a bit. 2025-05-27 11:02:03 -04:00
99a38bb75a Added NPC flag. 2025-05-27 10:51:29 -04:00
9f73dedcad Update README.md
Added link to discourse for feedback, discussion.
2025-05-27 10:22:18 -04:00
893fe49ccb Code clean up and refactor. 2025-05-26 22:42:37 -04:00
6adcd0f8e0 Adding random inits 2025-05-26 22:31:43 -04:00
d631545570 Added defautl HP values. 2025-05-26 21:48:28 -04:00
ad11bbc648 Fixed linting and pause button. 2025-05-26 21:34:37 -04:00
785af983da Fixed the ability to add monsters while a fight is going. 2025-05-26 21:17:42 -04:00
40a798514d updated readme 2025-05-26 11:15:25 -04:00
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
17 changed files with 21522 additions and 1010 deletions

View File

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

946
App.js
View File

@ -1,946 +0,0 @@
import React, { useState, useEffect, useCallback } from 'react';
import { initializeApp } from 'firebase/app';
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from 'firebase/auth';
import { getFirestore, doc, setDoc, addDoc, getDoc, getDocs, collection, onSnapshot, updateDoc, deleteDoc, query, where, writeBatch } from 'firebase/firestore';
import { ArrowLeft, PlusCircle, Users, Swords, Shield, Trash2, Eye, Edit3, Save, XCircle, ChevronsUpDown, ChevronDown, ChevronUp, UserCheck, UserX, HeartCrack, HeartPulse, Zap, Share2, Copy as CopyIcon } from 'lucide-react';
// --- Firebase Configuration ---
// Read from environment variables
const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID
};
// --- Initialize Firebase ---
// Check if all necessary Firebase config values are present
const requiredFirebaseConfigKeys = [
'apiKey', 'authDomain', 'projectId', 'appId'
// storageBucket and messagingSenderId might be optional depending on usage
];
const missingKeys = requiredFirebaseConfigKeys.filter(key => !firebaseConfig[key]);
let app;
if (missingKeys.length > 0) {
console.error(`Missing Firebase config keys from environment variables: ${missingKeys.join(', ')}`);
console.warn("Firebase is not initialized. Please set up your .env.local file with the necessary REACT_APP_FIREBASE_... variables.");
// You might want to render an error message or a fallback UI here
} else {
app = initializeApp(firebaseConfig);
}
const db = app ? getFirestore(app) : null; // Conditionally get Firestore
const auth = app ? getAuth(app) : null; // Conditionally get Auth
// --- Firestore Paths ---
const APP_ID = process.env.REACT_APP_TRACKER_APP_ID || 'ttrpg-initiative-tracker-default';
// ... rest of your code
// --- Helper Functions ---
const generateId = () => crypto.randomUUID();
function getShareableLinkBase() {
return window.location.origin + window.location.pathname;
}
// --- Main App Component ---
function App() {
const [userId, setUserId] = useState(null);
const [isAuthReady, setIsAuthReady] = useState(false);
const [viewMode, setViewMode] = useState('admin');
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [directDisplayParams, setDirectDisplayParams] = useState(null);
useEffect(() => {
const handleHashChange = () => {
const hash = window.location.hash;
if (hash.startsWith('#/display/')) {
const parts = hash.substring('#/display/'.length).split('/');
if (parts.length === 2 && parts[0] && parts[1]) {
setDirectDisplayParams({ campaignId: parts[0], encounterId: parts[1] });
setViewMode('display');
} else {
setDirectDisplayParams(null);
}
} else {
setDirectDisplayParams(null);
}
};
window.addEventListener('hashchange', handleHashChange);
handleHashChange();
return () => window.removeEventListener('hashchange', handleHashChange);
}, []);
useEffect(() => {
const initAuth = async () => {
try {
if (typeof __initial_auth_token !== 'undefined' && __initial_auth_token) {
await signInWithCustomToken(auth, __initial_auth_token);
} else {
await signInAnonymously(auth);
}
} catch (err) {
console.error("Authentication error:", err);
setError("Failed to authenticate. Please try again later.");
}
};
const unsubscribe = onAuthStateChanged(auth, (user) => {
setUserId(user ? user.uid : null);
setIsAuthReady(true);
setIsLoading(false);
});
initAuth();
return () => unsubscribe();
}, []);
if (isLoading || !isAuthReady) {
return (
<div className="min-h-screen bg-slate-900 text-white flex flex-col items-center justify-center p-4">
<div className="animate-spin rounded-full h-16 w-16 border-t-4 border-blue-500 border-solid"></div>
<p className="mt-4 text-xl">Loading Initiative Tracker...</p>
{error && <p className="mt-2 text-red-400">{error}</p>}
</div>
);
}
return (
<div className="min-h-screen bg-slate-800 text-slate-100 font-sans">
{!directDisplayParams && (
<header className="bg-slate-900 p-4 shadow-lg">
<div className="container mx-auto flex justify-between items-center">
<h1 className="text-3xl font-bold text-sky-400">TTRPG Initiative Tracker</h1>
<div className="flex items-center space-x-4">
{userId && <span className="text-xs text-slate-400">UID: {userId}</span>}
{viewMode !== 'display' && ( // Only show Admin View button if not in display mode (when header is visible)
<button
onClick={() => { setViewMode('admin'); setDirectDisplayParams(null); window.location.hash = '';}}
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors ${viewMode === 'admin' && !directDisplayParams ? 'bg-sky-500 text-white' : 'bg-slate-700 hover:bg-slate-600'}`}
>
Admin View
</button>
)}
{viewMode !== 'admin' && ( // Only show Player Display button if not in admin mode
<button
onClick={() => { setViewMode('display'); setDirectDisplayParams(null); window.location.hash = '';}}
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors ${viewMode === 'display' && !directDisplayParams ? 'bg-teal-500 text-white' : 'bg-slate-700 hover:bg-slate-600'}`}
>
Player Display
</button>
)}
{/* If in admin mode, show player display button. If in player mode, show admin button (unless hidden above) */}
{/* This logic seems a bit complex, let's simplify: always show both if header is visible, style active one */}
{viewMode === 'admin' && ( // Show Player Display button if in Admin mode
<button
onClick={() => { setViewMode('display'); setDirectDisplayParams(null); window.location.hash = '';}}
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors bg-slate-700 hover:bg-slate-600`}
>
Player Display
</button>
)}
</div>
</div>
</header>
)}
<main className={`container mx-auto p-4 md:p-8 ${directDisplayParams ? 'pt-8' : ''}`}>
{directDisplayParams && isAuthReady && (
<DisplayView campaignIdFromUrl={directDisplayParams.campaignId} encounterIdFromUrl={directDisplayParams.encounterId} />
)}
{!directDisplayParams && viewMode === 'admin' && isAuthReady && userId && <AdminView userId={userId} />}
{!directDisplayParams && viewMode === 'display' && isAuthReady && <DisplayView />}
{!isAuthReady && <p>Authenticating...</p>}
</main>
{!directDisplayParams && (
<footer className="bg-slate-900 p-4 text-center text-sm text-slate-400 mt-8">
TTRPG Initiative Tracker v0.1.12
</footer>
)}
</div>
);
}
// --- Admin View Component ---
function AdminView({ userId }) {
const [campaigns, setCampaigns] = useState([]);
const [selectedCampaignId, setSelectedCampaignId] = useState(null);
const [showCreateCampaignModal, setShowCreateCampaignModal] = useState(false);
const [initialActiveInfo, setInitialActiveInfo] = useState(null);
useEffect(() => {
const campaignsCollectionRef = collection(db, CAMPAIGNS_COLLECTION);
const q = query(campaignsCollectionRef);
const unsubscribeCampaigns = onSnapshot(q, (snapshot) => {
setCampaigns(snapshot.docs.map(doc => ({ id: doc.id, ...doc.data(), characters: doc.data().players || [] })));
}, (err) => console.error("Error fetching campaigns:", err));
const activeDisplayRef = doc(db, ACTIVE_DISPLAY_DOC);
const unsubscribeActiveDisplay = onSnapshot(activeDisplayRef, (docSnap) => {
if (docSnap.exists()) {
setInitialActiveInfo(docSnap.data());
} else {
setInitialActiveInfo(null);
}
}, (err) => {
console.error("Error fetching initial active display info for AdminView:", err);
});
return () => {
unsubscribeCampaigns();
unsubscribeActiveDisplay();
};
}, []);
useEffect(() => {
if (initialActiveInfo && initialActiveInfo.activeCampaignId && campaigns.length > 0 && !selectedCampaignId) {
const campaignExists = campaigns.some(c => c.id === initialActiveInfo.activeCampaignId);
if (campaignExists) {
setSelectedCampaignId(initialActiveInfo.activeCampaignId);
}
}
}, [initialActiveInfo, campaigns, selectedCampaignId]);
const handleCreateCampaign = async (name) => {
if (!name.trim()) return;
const newCampaignId = generateId();
try {
await setDoc(doc(db, CAMPAIGNS_COLLECTION, newCampaignId), {
name: name.trim(), ownerId: userId, createdAt: new Date().toISOString(), players: [],
});
setShowCreateCampaignModal(false);
setSelectedCampaignId(newCampaignId);
} catch (err) { console.error("Error creating campaign:", err); }
};
const handleDeleteCampaign = async (campaignId) => {
// TODO: Implement custom confirmation modal for deleting campaigns
console.warn("Attempting to delete campaign without confirmation:", campaignId);
try {
const encountersPath = `${CAMPAIGNS_COLLECTION}/${campaignId}/encounters`;
const encountersSnapshot = await getDocs(collection(db, encountersPath));
const batch = writeBatch(db);
encountersSnapshot.docs.forEach(encounterDoc => batch.delete(encounterDoc.ref));
await batch.commit();
await deleteDoc(doc(db, CAMPAIGNS_COLLECTION, campaignId));
if (selectedCampaignId === campaignId) setSelectedCampaignId(null);
const activeDisplayRef = doc(db, ACTIVE_DISPLAY_DOC);
const activeDisplaySnap = await getDoc(activeDisplayRef);
if (activeDisplaySnap.exists() && activeDisplaySnap.data().activeCampaignId === campaignId) {
await updateDoc(activeDisplayRef, { activeCampaignId: null, activeEncounterId: null });
}
} catch (err) { console.error("Error deleting campaign:", err); }
};
const selectedCampaign = campaigns.find(c => c.id === selectedCampaignId);
return (
<div className="space-y-6">
<div>
<div className="flex justify-between items-center mb-4">
<h2 className="text-2xl font-semibold text-sky-300">Campaigns</h2>
<button onClick={() => setShowCreateCampaignModal(true)} className="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-lg flex items-center transition-colors">
<PlusCircle size={20} className="mr-2" /> Create Campaign
</button>
</div>
{campaigns.length === 0 && <p className="text-slate-400">No campaigns yet.</p>}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{campaigns.map(campaign => (
<div
key={campaign.id}
onClick={() => setSelectedCampaignId(campaign.id)}
className={`p-4 rounded-lg shadow-md cursor-pointer transition-all ${selectedCampaignId === campaign.id ? 'bg-sky-700 ring-2 ring-sky-400' : 'bg-slate-700 hover:bg-slate-600'}`}
>
<h3 className="text-xl font-semibold text-white">{campaign.name}</h3>
<p className="text-xs text-slate-400">ID: {campaign.id}</p>
<button
onClick={(e) => {
e.stopPropagation();
handleDeleteCampaign(campaign.id);
}}
className="mt-2 text-red-400 hover:text-red-300 text-xs flex items-center"
>
<Trash2 size={14} className="mr-1" /> Delete
</button>
</div>
))}
</div>
</div>
{showCreateCampaignModal && <Modal onClose={() => setShowCreateCampaignModal(false)} title="Create New Campaign"><CreateCampaignForm onCreate={handleCreateCampaign} onCancel={() => setShowCreateCampaignModal(false)} /></Modal>}
{selectedCampaign && (
<div className="mt-6 p-6 bg-slate-750 rounded-lg shadow-xl">
<h2 className="text-2xl font-semibold text-amber-300 mb-4">Managing: {selectedCampaign.name}</h2>
<CharacterManager campaignId={selectedCampaignId} campaignCharacters={selectedCampaign.players || []} />
<hr className="my-6 border-slate-600" />
<EncounterManager
campaignId={selectedCampaignId}
initialActiveEncounterId={initialActiveInfo && initialActiveInfo.activeCampaignId === selectedCampaignId ? initialActiveInfo.activeEncounterId : null}
campaignCharacters={selectedCampaign.players || []}
/>
</div>
)}
</div>
);
}
function CreateCampaignForm({ onCreate, onCancel }) {
const [name, setName] = useState('');
return (
<form onSubmit={(e) => { e.preventDefault(); onCreate(name); }} className="space-y-4">
<div>
<label htmlFor="campaignName" className="block text-sm font-medium text-slate-300">Campaign Name</label>
<input type="text" id="campaignName" value={name} onChange={(e) => setName(e.target.value)} className="mt-1 block 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" required />
</div>
<div className="flex justify-end space-x-3">
<button type="button" onClick={onCancel} className="px-4 py-2 text-sm font-medium text-slate-300 bg-slate-600 hover:bg-slate-500 rounded-md transition-colors">Cancel</button>
<button type="submit" className="px-4 py-2 text-sm font-medium text-white bg-green-500 hover:bg-green-600 rounded-md transition-colors">Create</button>
</div>
</form>
);
}
function CharacterManager({ campaignId, campaignCharacters }) {
const [characterName, setCharacterName] = useState('');
const [editingCharacter, setEditingCharacter] = useState(null);
const handleAddCharacter = async () => {
if (!characterName.trim() || !campaignId) return;
const newCharacter = { id: generateId(), name: characterName.trim() };
try {
await updateDoc(doc(db, CAMPAIGNS_COLLECTION, campaignId), { players: [...campaignCharacters, newCharacter] });
setCharacterName('');
} catch (err) { console.error("Error adding character:", err); }
};
const handleUpdateCharacter = async (characterId, newName) => {
if (!newName.trim() || !campaignId) return;
const updatedCharacters = campaignCharacters.map(c => c.id === characterId ? { ...c, name: newName.trim() } : c);
try {
await updateDoc(doc(db, CAMPAIGNS_COLLECTION, campaignId), { players: updatedCharacters });
setEditingCharacter(null);
} catch (err) { console.error("Error updating character:", err); }
};
const handleDeleteCharacter = async (characterId) => {
// TODO: Implement custom confirmation modal for deleting characters
console.warn("Attempting to delete character without confirmation:", characterId);
const updatedCharacters = campaignCharacters.filter(c => c.id !== characterId);
try {
await updateDoc(doc(db, CAMPAIGNS_COLLECTION, campaignId), { players: updatedCharacters });
} catch (err) { console.error("Error deleting character:", err); }
};
return (
<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>
<form onSubmit={(e) => { e.preventDefault(); handleAddCharacter(); }} className="flex gap-2 mb-4">
<input type="text" value={characterName} onChange={(e) => setCharacterName(e.target.value)} placeholder="New character name" className="flex-grow 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="px-4 py-2 text-sm font-medium text-white bg-sky-500 hover:bg-sky-600 rounded-md transition-colors flex items-center"><PlusCircle size={18} className="mr-1" /> Add Character</button>
</form>
{campaignCharacters.length === 0 && <p className="text-sm text-slate-400">No characters added.</p>}
<ul className="space-y-2">
{campaignCharacters.map(character => (
<li key={character.id} className="flex justify-between items-center p-3 bg-slate-700 rounded-md">
{editingCharacter && editingCharacter.id === character.id ? (
<input type="text" defaultValue={character.name} onBlur={(e) => handleUpdateCharacter(character.id, e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handleUpdateCharacter(character.id, e.target.value); if (e.key === 'Escape') setEditingCharacter(null); }} autoFocus className="flex-grow px-3 py-2 bg-slate-600 border border-slate-500 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white"/>
) : ( <span className="text-slate-100">{character.name}</span> )}
<div className="flex space-x-2">
<button onClick={() => setEditingCharacter(character)} 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={() => handleDeleteCharacter(character.id)} 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>
);
}
function EncounterManager({ campaignId, initialActiveEncounterId, campaignCharacters }) {
const [encounters, setEncounters] = useState([]);
const [selectedEncounterId, setSelectedEncounterId] = useState(null);
const [showCreateEncounterModal, setShowCreateEncounterModal] = useState(false);
const [activeDisplayInfo, setActiveDisplayInfo] = useState(null);
const [copiedLinkEncounterId, setCopiedLinkEncounterId] = useState(null);
const encountersPath = `${CAMPAIGNS_COLLECTION}/${campaignId}/encounters`;
const selectedEncounterIdRef = React.useRef(selectedEncounterId); // Ref to track current selection for initial set
useEffect(() => {
selectedEncounterIdRef.current = selectedEncounterId;
}, [selectedEncounterId]);
useEffect(() => {
if (!campaignId) {
setEncounters([]);
setSelectedEncounterId(null);
return;
}
const unsubEncounters = onSnapshot(query(collection(db, encountersPath)), (snapshot) => {
const fetchedEncounters = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
setEncounters(fetchedEncounters);
if (selectedEncounterIdRef.current === null || !fetchedEncounters.some(e => e.id === selectedEncounterIdRef.current)) {
if (initialActiveEncounterId && fetchedEncounters.some(e => e.id === initialActiveEncounterId)) {
setSelectedEncounterId(initialActiveEncounterId);
} else if (activeDisplayInfo && activeDisplayInfo.activeCampaignId === campaignId &&
fetchedEncounters.some(e => e.id === activeDisplayInfo.activeEncounterId)) {
setSelectedEncounterId(activeDisplayInfo.activeEncounterId);
}
}
}, (err) => console.error(`Error fetching encounters for campaign ${campaignId}:`, err));
return () => unsubEncounters();
}, [campaignId, initialActiveEncounterId, activeDisplayInfo]);
useEffect(() => {
const unsub = onSnapshot(doc(db, ACTIVE_DISPLAY_DOC), (docSnap) => {
setActiveDisplayInfo(docSnap.exists() ? docSnap.data() : null);
}, (err) => { console.error("Error fetching active display info:", err); setActiveDisplayInfo(null); });
return () => unsub();
}, []);
const handleCreateEncounter = async (name) => {
if (!name.trim() || !campaignId) return;
const newEncounterId = generateId();
try {
await setDoc(doc(db, encountersPath, newEncounterId), {
name: name.trim(), createdAt: new Date().toISOString(), participants: [], round: 0, currentTurnParticipantId: null, isStarted: false,
});
setShowCreateEncounterModal(false);
setSelectedEncounterId(newEncounterId);
} catch (err) { console.error("Error creating encounter:", err); }
};
const handleDeleteEncounter = async (encounterId) => {
// TODO: Implement custom confirmation modal for deleting encounters
console.warn("Attempting to delete encounter without confirmation:", encounterId);
try {
await deleteDoc(doc(db, encountersPath, encounterId));
if (selectedEncounterId === encounterId) setSelectedEncounterId(null);
if (activeDisplayInfo && activeDisplayInfo.activeEncounterId === encounterId) {
await updateDoc(doc(db, ACTIVE_DISPLAY_DOC), { activeEncounterId: null });
}
} catch (err) { console.error("Error deleting encounter:", err); }
};
const handleSetEncounterAsActiveDisplay = async (encounterId) => {
try {
await setDoc(doc(db, ACTIVE_DISPLAY_DOC), { activeCampaignId: campaignId, activeEncounterId: encounterId }, { merge: true });
console.log("Encounter set as active for DM's main display!");
} catch (err) { console.error("Error setting active display:", err); }
};
const handleCopyToClipboard = (encounterId) => {
const link = `${getShareableLinkBase()}#/display/${campaignId}/${encounterId}`;
navigator.clipboard.writeText(link).then(() => {
setCopiedLinkEncounterId(encounterId);
setTimeout(() => setCopiedLinkEncounterId(null), 2000);
}).catch(err => console.error('Failed to copy link: ', err));
};
const selectedEncounter = encounters.find(e => e.id === selectedEncounterId);
return (
<div className="mt-6 p-4 bg-slate-800 rounded-lg shadow">
<div className="flex justify-between items-center mb-3">
<h3 className="text-xl font-semibold text-sky-300 flex items-center"><Swords size={24} className="mr-2" /> Encounters</h3>
<button onClick={() => setShowCreateEncounterModal(true)} className="px-4 py-2 text-sm font-medium text-white bg-orange-500 hover:bg-orange-600 rounded-md transition-colors flex items-center"><PlusCircle size={18} className="mr-1" /> Create Encounter</button>
</div>
{encounters.length === 0 && <p className="text-sm text-slate-400">No encounters yet.</p>}
<div className="space-y-3">
{encounters.map(encounter => {
const isDmActiveDisplay = activeDisplayInfo && activeDisplayInfo.activeCampaignId === campaignId && activeDisplayInfo.activeEncounterId === encounter.id;
return (
<div key={encounter.id} className={`p-3 rounded-md shadow transition-all ${selectedEncounterId === encounter.id ? 'bg-sky-600 ring-2 ring-sky-400' : 'bg-slate-700 hover:bg-slate-650'} ${isDmActiveDisplay ? 'ring-2 ring-green-500 shadow-md shadow-green-500/30' : ''}`}>
<div className="flex justify-between items-center">
<div onClick={() => setSelectedEncounterId(encounter.id)} className="cursor-pointer flex-grow">
<h4 className="font-medium text-white">{encounter.name}</h4>
<p className="text-xs text-slate-300">Participants: {encounter.participants?.length || 0}</p>
{isDmActiveDisplay && <span className="text-xs text-green-400 font-semibold block mt-1">LIVE ON DM DISPLAY</span>}
</div>
<div className="flex items-center space-x-2">
<button onClick={() => handleSetEncounterAsActiveDisplay(encounter.id)} className={`p-1 rounded transition-colors ${isDmActiveDisplay ? 'bg-green-500 hover:bg-green-600 text-white' : 'text-teal-400 hover:text-teal-300 bg-slate-600 hover:bg-slate-500'}`} title="Set as DM's Active Display"><Eye size={18} /></button>
<button onClick={() => handleCopyToClipboard(encounter.id)} className="p-1 rounded transition-colors text-sky-400 hover:text-sky-300 bg-slate-600 hover:bg-slate-500" title="Copy Share Link for Players"><Share2 size={18} /></button>
{copiedLinkEncounterId === encounter.id && <span className="text-xs text-green-400">Copied!</span>}
<button onClick={(e) => { e.stopPropagation(); handleDeleteEncounter(encounter.id); }} className="p-1 rounded transition-colors text-red-400 hover:text-red-300 bg-slate-600 hover:bg-slate-500" title="Delete Encounter"><Trash2 size={18} /></button>
</div>
</div>
{selectedEncounterId === encounter.id && (
<div className="mt-2 pt-2 border-t border-slate-600">
<p className="text-xs text-slate-400">Shareable Link for Players:</p>
<div className="flex items-center gap-2">
<input type="text" readOnly value={`${getShareableLinkBase()}#/display/${campaignId}/${encounter.id}`} className="text-xs w-full bg-slate-600 px-3 py-2 border border-slate-500 rounded-md shadow-sm focus:outline-none focus:ring-sky-500 focus:border-sky-500 sm:text-sm text-white" />
<button onClick={() => handleCopyToClipboard(encounter.id)} className="px-4 py-2 text-xs font-medium text-slate-300 bg-slate-500 hover:bg-slate-400 rounded-md transition-colors p-1">
{copiedLinkEncounterId === encounter.id ? 'Copied!' : <CopyIcon size={14}/>}
</button>
</div>
</div>
)}
</div>
);
})}
</div>
{showCreateEncounterModal && <Modal onClose={() => setShowCreateEncounterModal(false)} title="Create New Encounter"><CreateEncounterForm onCreate={handleCreateEncounter} onCancel={() => setShowCreateEncounterModal(false)} /></Modal>}
{selectedEncounter && (
<div className="mt-6 p-4 bg-slate-750 rounded-lg shadow-inner">
<h3 className="text-xl font-semibold text-amber-300 mb-3">Managing Encounter: {selectedEncounter.name}</h3>
<ParticipantManager encounter={selectedEncounter} encounterPath={`${encountersPath}/${selectedEncounterId}`} campaignCharacters={campaignCharacters} />
<InitiativeControls campaignId={campaignId} encounter={selectedEncounter} encounterPath={`${encountersPath}/${selectedEncounterId}`} />
</div>
)}
</div>
);
}
function CreateEncounterForm({ onCreate, onCancel }) {
const [name, setName] = useState('');
return (
<form onSubmit={(e) => { e.preventDefault(); onCreate(name); }} className="space-y-4">
<div>
<label htmlFor="encounterName" className="block text-sm font-medium text-slate-300">Encounter Name</label>
<input type="text" id="encounterName" value={name} onChange={(e) => setName(e.target.value)} className="mt-1 block 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" required />
</div>
<div className="flex justify-end space-x-3">
<button type="button" onClick={onCancel} className="px-4 py-2 text-sm font-medium text-slate-300 bg-slate-600 hover:bg-slate-500 rounded-md transition-colors">Cancel</button>
<button type="submit" className="px-4 py-2 text-sm font-medium text-white bg-orange-500 hover:bg-orange-600 rounded-md transition-colors">Create</button>
</div>
</form>
);
}
function ParticipantManager({ encounter, encounterPath, campaignCharacters }) {
const [participantName, setParticipantName] = useState('');
const [participantType, setParticipantType] = useState('monster');
const [selectedCharacterId, setSelectedCharacterId] = useState('');
const [initiative, setInitiative] = useState(10);
const [maxHp, setMaxHp] = useState(10);
const [editingParticipant, setEditingParticipant] = useState(null);
const [hpChangeValues, setHpChangeValues] = useState({});
const [draggedItemId, setDraggedItemId] = useState(null);
const participants = encounter.participants || [];
const handleAddParticipant = async () => {
if ((participantType === 'monster' && !participantName.trim()) || (participantType === 'character' && !selectedCharacterId)) return;
let nameToAdd = participantName.trim();
if (participantType === 'character') {
const character = campaignCharacters.find(c => c.id === selectedCharacterId);
if (!character) { console.error("Selected character not found"); return; }
if (participants.some(p => p.type === 'character' && p.originalCharacterId === selectedCharacterId)) {
alert(`${character.name} is already in this encounter.`); return;
}
nameToAdd = character.name;
}
const newParticipant = {
id: generateId(), name: nameToAdd, type: participantType,
originalCharacterId: participantType === 'character' ? selectedCharacterId : null,
initiative: parseInt(initiative, 10) || 0, maxHp: parseInt(maxHp, 10) || 1, currentHp: parseInt(maxHp, 10) || 1,
conditions: [], isActive: true,
};
try {
await updateDoc(doc(db, encounterPath), { participants: [...participants, newParticipant] });
setParticipantName(''); setInitiative(10); setMaxHp(10); setSelectedCharacterId('');
} catch (err) { console.error("Error adding participant:", err); }
};
const handleUpdateParticipant = async (updatedData) => {
if (!editingParticipant) return;
const { flavorText, ...restOfData } = updatedData;
const updatedParticipants = participants.map(p => p.id === editingParticipant.id ? { ...p, ...restOfData } : p );
try {
await updateDoc(doc(db, encounterPath), { participants: updatedParticipants });
setEditingParticipant(null);
} catch (err) { console.error("Error updating participant:", err); }
};
const handleDeleteParticipant = async (participantId) => {
// TODO: Implement custom confirmation modal for deleting participants
console.warn("Attempting to delete participant without confirmation:", participantId);
const updatedParticipants = participants.filter(p => p.id !== participantId);
try {
await updateDoc(doc(db, encounterPath), { participants: updatedParticipants });
} catch (err) { console.error("Error deleting participant:", err); }
};
const toggleParticipantActive = async (participantId) => {
const pToToggle = participants.find(p => p.id === participantId);
if (!pToToggle) return;
const updatedPs = participants.map(p => p.id === participantId ? { ...p, isActive: !p.isActive } : p);
try { await updateDoc(doc(db, encounterPath), { participants: updatedPs }); }
catch (err) { console.error("Error toggling active state:", err); }
};
const handleHpInputChange = (participantId, value) => setHpChangeValues(prev => ({ ...prev, [participantId]: value }));
const applyHpChange = async (participantId, changeType) => {
const amountStr = hpChangeValues[participantId];
if (amountStr === undefined || amountStr.trim() === '') return;
const amount = parseInt(amountStr, 10);
if (isNaN(amount) || amount === 0) { setHpChangeValues(prev => ({ ...prev, [participantId]: '' })); return; }
const pToChange = participants.find(p => p.id === participantId);
if (!pToChange) return;
let newHp = pToChange.currentHp;
if (changeType === 'damage') newHp = Math.max(0, pToChange.currentHp - amount);
else if (changeType === 'heal') newHp = Math.min(pToChange.maxHp, pToChange.currentHp + amount);
const updatedPs = participants.map(p => p.id === participantId ? { ...p, currentHp: newHp } : p);
try {
await updateDoc(doc(db, encounterPath), { participants: updatedPs });
setHpChangeValues(prev => ({ ...prev, [participantId]: '' }));
} catch (err) { console.error("Error applying HP change:", err); }
};
const handleDragStart = (e, id) => {
setDraggedItemId(id);
e.dataTransfer.effectAllowed = 'move';
};
const handleDragOver = (e) => {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
};
const handleDrop = async (e, targetId) => {
e.preventDefault();
if (draggedItemId === null || draggedItemId === targetId) {
setDraggedItemId(null);
return;
}
const currentParticipants = [...participants];
const draggedItemIndex = currentParticipants.findIndex(p => p.id === draggedItemId);
const targetItemIndex = currentParticipants.findIndex(p => p.id === targetId);
if (draggedItemIndex === -1 || targetItemIndex === -1) {
setDraggedItemId(null); return;
}
const draggedItem = currentParticipants[draggedItemIndex];
const targetItem = currentParticipants[targetItemIndex];
if (draggedItem.initiative !== targetItem.initiative) {
console.log("Cannot drag between different initiative groups for tie-breaking.");
setDraggedItemId(null); return;
}
const reorderedParticipants = [...currentParticipants];
const [removedItem] = reorderedParticipants.splice(draggedItemIndex, 1);
reorderedParticipants.splice(targetItemIndex, 0, removedItem);
try {
await updateDoc(doc(db, encounterPath), { participants: reorderedParticipants });
} catch (err) { console.error("Error updating participants after drag-drop:", err); }
setDraggedItemId(null);
};
const handleDragEnd = () => {
setDraggedItemId(null);
};
const sortedAdminParticipants = [...participants].sort((a, b) => {
if (a.initiative === b.initiative) {
const indexA = participants.findIndex(p => p.id === a.id);
const indexB = participants.findIndex(p => p.id === b.id);
return indexA - indexB;
}
return b.initiative - a.initiative;
});
const initiativeGroups = participants.reduce((acc, p) => {
acc[p.initiative] = (acc[p.initiative] || 0) + 1;
return acc;
}, {});
const tiedInitiatives = Object.keys(initiativeGroups).filter(init => initiativeGroups[init] > 1).map(Number);
return (
<div className="p-3 bg-slate-800 rounded-md mt-4">
<h4 className="text-lg font-medium text-sky-200 mb-3">Participants</h4>
<form onSubmit={(e) => { e.preventDefault(); handleAddParticipant(); }} className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4 p-3 bg-slate-700 rounded">
<div>
<label className="block text-sm font-medium text-slate-300">Type</label>
<select value={participantType} onChange={(e) => setParticipantType(e.target.value)} className="mt-1 w-full px-3 py-2 bg-slate-600 border-slate-500 rounded text-white">
<option value="monster">Monster</option>
<option value="character">Character</option>
</select>
</div>
{participantType === 'monster' && (
<div className="md:col-span-2">
<label className="block text-sm font-medium text-slate-300">Monster Name</label>
<input type="text" value={participantName} onChange={(e) => setParticipantName(e.target.value)} placeholder="e.g., Dire Wolf" className="mt-1 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>
)}
{participantType === 'character' && (<div><label className="block text-sm font-medium text-slate-300">Select Character</label><select value={selectedCharacterId} onChange={(e) => setSelectedCharacterId(e.target.value)} className="mt-1 w-full px-3 py-2 bg-slate-600 border-slate-500 rounded text-white"><option value="">-- Select from Campaign --</option>{campaignCharacters.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}</select></div>)}
<div><label className="block text-sm font-medium text-slate-300">Initiative</label><input type="number" value={initiative} onChange={(e) => setInitiative(e.target.value)} className="mt-1 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>
<div><label className="block text-sm font-medium text-slate-300">Max HP</label><input type="number" value={maxHp} onChange={(e) => setMaxHp(e.target.value)} className="mt-1 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>
<div className="md:col-span-2 flex justify-end">
<button type="submit" className="px-4 py-2 text-sm font-medium text-white bg-green-500 hover:bg-green-600 rounded-md transition-colors flex items-center">
<PlusCircle size={18} className="mr-1" /> Add to Encounter
</button>
</div>
</form>
{participants.length === 0 && <p className="text-sm text-slate-400">No participants.</p>}
<ul className="space-y-2">
{sortedAdminParticipants.map((p, index) => {
const isCurrentTurn = encounter.isStarted && p.id === encounter.currentTurnParticipantId;
const isDraggable = !encounter.isStarted && tiedInitiatives.includes(p.initiative);
return (
<li
key={p.id}
draggable={isDraggable}
onDragStart={isDraggable ? (e) => handleDragStart(e, p.id) : undefined}
onDragOver={isDraggable ? handleDragOver : undefined}
onDrop={isDraggable ? (e) => handleDrop(e, p.id) : undefined}
onDragEnd={isDraggable ? handleDragEnd : undefined}
className={`p-3 rounded-md flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2 transition-all
${isCurrentTurn ? 'bg-green-600 ring-2 ring-green-300 shadow-lg' : (p.type === 'character' ? 'bg-sky-800' : 'bg-red-800')}
${!p.isActive ? 'opacity-50' : ''}
${isDraggable ? 'cursor-grab' : ''}
${draggedItemId === p.id ? 'opacity-50 ring-2 ring-yellow-400' : ''}
`}
>
<div className="flex-1 flex items-center">
{isDraggable && <ChevronsUpDown size={18} className="mr-2 text-slate-400 flex-shrink-0" />}
<div>
<p className={`font-semibold text-lg ${isCurrentTurn ? 'text-white' : 'text-white'}`}>{p.name} <span className="text-xs">({p.type})</span>{isCurrentTurn && <span className="ml-2 px-2 py-0.5 bg-yellow-400 text-black text-xs font-bold rounded-full inline-flex items-center"><Zap size={12} className="mr-1"/> CURRENT</span>}</p>
<p className={`text-sm ${isCurrentTurn ? 'text-green-100' : 'text-slate-200'}`}>Init: {p.initiative} | HP: {p.currentHp}/{p.maxHp}</p>
</div>
</div>
<div className="flex flex-wrap items-center space-x-2 mt-2 sm:mt-0">
{encounter.isStarted && p.isActive && (<div className="flex items-center space-x-1 bg-slate-700 p-1 rounded-md"><input type="number" placeholder="HP" value={hpChangeValues[p.id] || ''} onChange={(e) => handleHpInputChange(p.id, e.target.value)} className="w-16 p-1 text-sm bg-slate-600 border border-slate-500 rounded-md text-white focus:ring-sky-500 focus:border-sky-500" aria-label={`HP change for ${p.name}`}/><button onClick={() => applyHpChange(p.id, 'damage')} className="p-1 bg-red-500 hover:bg-red-600 text-white rounded-md text-xs" title="Damage"><HeartCrack size={16}/></button><button onClick={() => applyHpChange(p.id, 'heal')} className="p-1 bg-green-500 hover:bg-green-600 text-white rounded-md text-xs" title="Heal"><HeartPulse size={16}/></button></div>)}
<button onClick={() => toggleParticipantActive(p.id)} className={`p-1 rounded transition-colors ${p.isActive ? 'text-yellow-400 hover:text-yellow-300 bg-slate-600 hover:bg-slate-500' : 'text-slate-400 hover:text-slate-300 bg-slate-600 hover:bg-slate-500'}`} title={p.isActive ? "Mark Inactive" : "Mark Active"}>{p.isActive ? <UserCheck size={18} /> : <UserX size={18} />}</button>
<button onClick={() => setEditingParticipant(p)} className="p-1 rounded transition-colors text-yellow-400 hover:text-yellow-300 bg-slate-600 hover:bg-slate-500" title="Edit"><Edit3 size={18} /></button>
<button onClick={() => handleDeleteParticipant(p.id)} className="p-1 rounded transition-colors text-red-400 hover:text-red-300 bg-slate-600 hover:bg-slate-500" title="Remove"><Trash2 size={18} /></button>
</div>
</li>
);
})}
</ul>
{editingParticipant && <EditParticipantModal participant={editingParticipant} onClose={() => setEditingParticipant(null)} onSave={handleUpdateParticipant} />}
</div>
);
}
function EditParticipantModal({ participant, onClose, onSave }) {
const [name, setName] = useState(participant.name);
const [initiative, setInitiative] = useState(participant.initiative);
const [currentHp, setCurrentHp] = useState(participant.currentHp);
const [maxHp, setMaxHp] = useState(participant.maxHp);
const handleSubmit = (e) => {
e.preventDefault();
onSave({
name: name.trim(), initiative: parseInt(initiative, 10),
currentHp: parseInt(currentHp, 10), maxHp: parseInt(maxHp, 10),
});
};
return (
<Modal onClose={onClose} title={`Edit ${participant.name}`}>
<form onSubmit={handleSubmit} className="space-y-4">
<div><label className="block text-sm font-medium text-slate-300">Name</label><input type="text" value={name} onChange={(e) => setName(e.target.value)} className="mt-1 block 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>
<div><label className="block text-sm font-medium text-slate-300">Initiative</label><input type="number" value={initiative} onChange={(e) => setInitiative(e.target.value)} className="mt-1 block 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>
<div className="flex gap-4">
<div className="flex-1"><label className="block text-sm font-medium text-slate-300">Current HP</label><input type="number" value={currentHp} onChange={(e) => setCurrentHp(e.target.value)} className="mt-1 block 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>
<div className="flex-1"><label className="block text-sm font-medium text-slate-300">Max HP</label><input type="number" value={maxHp} onChange={(e) => setMaxHp(e.target.value)} className="mt-1 block 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>
</div>
<div className="flex justify-end space-x-3 pt-2">
<button type="button" onClick={onClose} className="px-4 py-2 text-sm font-medium text-slate-300 bg-slate-600 hover:bg-slate-500 rounded-md transition-colors">Cancel</button>
<button type="submit" className="px-4 py-2 text-sm font-medium text-white bg-sky-500 hover:bg-sky-600 rounded-md transition-colors"><Save size={18} className="mr-1 inline-block" /> Save</button>
</div>
</form>
</Modal>
);
}
function InitiativeControls({ campaignId, encounter, encounterPath }) {
const handleStartEncounter = async () => {
if (!encounter.participants || encounter.participants.length === 0) { alert("Add participants first."); return; }
const activePs = encounter.participants.filter(p => p.isActive);
if (activePs.length === 0) { alert("No active participants."); return; }
const sortedPs = [...activePs].sort((a, b) => {
if (a.initiative === b.initiative) {
const indexA = encounter.participants.findIndex(p => p.id === a.id);
const indexB = encounter.participants.findIndex(p => p.id === b.id);
return indexA - indexB;
}
return b.initiative - a.initiative;
});
try {
await updateDoc(doc(db, encounterPath), {
isStarted: true, round: 1, currentTurnParticipantId: sortedPs[0].id, turnOrderIds: sortedPs.map(p => p.id)
// Participants array in DB already reflects D&D order, so no need to update it here again unless sorting changes it.
// The `participants` field in the database should be the source of truth for the D&D order.
// The `turnOrderIds` is derived from this for active combat.
});
await setDoc(doc(db, ACTIVE_DISPLAY_DOC), {
activeCampaignId: campaignId,
activeEncounterId: encounter.id
}, { merge: true });
console.log("Encounter started and set as active display.");
} catch (err) { console.error("Error starting encounter:", err); }
};
const handleNextTurn = async () => {
if (!encounter.isStarted || !encounter.currentTurnParticipantId || !encounter.turnOrderIds || encounter.turnOrderIds.length === 0) return;
const activePsInOrder = encounter.turnOrderIds.map(id => encounter.participants.find(p => p.id === id && p.isActive)).filter(Boolean);
if (activePsInOrder.length === 0) {
alert("No active participants left.");
await updateDoc(doc(db, encounterPath), { isStarted: false, currentTurnParticipantId: null, round: encounter.round }); return;
}
const currentIndex = activePsInOrder.findIndex(p => p.id === encounter.currentTurnParticipantId);
let nextIndex = (currentIndex + 1) % activePsInOrder.length;
let nextRound = encounter.round;
if (nextIndex === 0 && currentIndex !== -1) nextRound += 1;
try {
await updateDoc(doc(db, encounterPath), { currentTurnParticipantId: activePsInOrder[nextIndex].id, round: nextRound });
} catch (err) { console.error("Error advancing turn:", err); }
};
const handleEndEncounter = async () => {
// TODO: Implement custom confirmation modal for ending encounter
console.warn("Attempting to end encounter without confirmation");
try {
await updateDoc(doc(db, encounterPath), { isStarted: false, currentTurnParticipantId: null, round: 0, turnOrderIds: [] });
} catch (err) { console.error("Error ending encounter:", err); }
};
if (!encounter || !encounter.participants) return null;
return (
<div className="mt-6 p-3 bg-slate-800 rounded-md">
<h4 className="text-lg font-medium text-sky-200 mb-3">Combat Controls</h4>
<div className="flex flex-wrap gap-3">
{!encounter.isStarted ? (
<button onClick={handleStartEncounter} className="px-4 py-2 text-sm font-medium text-white bg-green-600 hover:bg-green-700 rounded-md transition-colors flex items-center" disabled={!encounter.participants || encounter.participants.filter(p=>p.isActive).length === 0}><PlayIcon size={18} className="mr-2" /> Start</button>
) : (
<>
<button onClick={handleNextTurn} className="px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors flex items-center" disabled={!encounter.currentTurnParticipantId}><SkipForwardIcon size={18} className="mr-2" /> Next Turn</button>
<button onClick={handleEndEncounter} className="px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-700 rounded-md transition-colors flex items-center"><StopCircleIcon size={18} className="mr-2" /> End</button>
<p className="text-slate-300 self-center">Round: {encounter.round}</p>
</>
)}
</div>
</div>
);
}
function DisplayView({ campaignIdFromUrl, encounterIdFromUrl }) {
const [activeEncounterData, setActiveEncounterData] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
setIsLoading(true); setError(null); setActiveEncounterData(null);
let unsubscribeEncounter;
if (campaignIdFromUrl && encounterIdFromUrl) {
const encounterPath = `${CAMPAIGNS_COLLECTION}/${campaignIdFromUrl}/encounters/${encounterIdFromUrl}`;
unsubscribeEncounter = onSnapshot(doc(db, encounterPath), (encDocSnap) => {
if (encDocSnap.exists()) setActiveEncounterData({ id: encDocSnap.id, ...encDocSnap.data() });
else setError("The requested encounter was not found or is not accessible.");
setIsLoading(false);
}, (err) => { console.error("Error fetching specific encounter for display:", err); setError("Error loading encounter data from link."); setIsLoading(false); });
} else {
const activeDisplayRef = doc(db, ACTIVE_DISPLAY_DOC);
const unsubDisplayConfig = onSnapshot(activeDisplayRef, async (docSnap) => {
if (docSnap.exists()) {
const { activeCampaignId, activeEncounterId } = docSnap.data();
if (activeCampaignId && activeEncounterId) {
const encounterPath = `${CAMPAIGNS_COLLECTION}/${activeCampaignId}/encounters/${activeEncounterId}`;
if(unsubscribeEncounter) unsubscribeEncounter();
unsubscribeEncounter = onSnapshot(doc(db, encounterPath), (encDocSnap) => {
if (encDocSnap.exists()) setActiveEncounterData({ id: encDocSnap.id, ...encDocSnap.data() });
else { setActiveEncounterData(null); setError("Active encounter not found. The DM might have deleted it.");}
setIsLoading(false);
}, (err) => { console.error("Error fetching active encounter details:", err); setError("Error loading active encounter data."); setIsLoading(false);});
} else { setActiveEncounterData(null); setIsLoading(false); }
} else { setActiveEncounterData(null); setIsLoading(false); }
}, (err) => { console.error("Error fetching active display config:", err); setError("Could not load display configuration."); setIsLoading(false); });
return () => { unsubDisplayConfig(); if (unsubscribeEncounter) unsubscribeEncounter(); };
}
return () => { if (unsubscribeEncounter) unsubscribeEncounter(); };
}, [campaignIdFromUrl, encounterIdFromUrl]);
if (isLoading) return <div className="text-center py-10 text-2xl text-slate-300">Loading Player Display...</div>;
if (error) return <div className="text-center py-10 text-2xl text-red-400">{error}</div>;
if (!activeEncounterData) return <div className="text-center py-10 text-3xl text-slate-400">No active encounter to display.</div>;
const { name, participants, round, currentTurnParticipantId, isStarted } = activeEncounterData;
let displayParticipants = [];
if (isStarted && activeEncounterData.turnOrderIds?.length > 0 && participants) {
displayParticipants = activeEncounterData.turnOrderIds
.map(id => participants.find(p => p.id === id)).filter(p => p && p.isActive);
} else if (participants) {
displayParticipants = [...participants].filter(p => p.isActive)
.sort((a, b) => {
if (a.initiative === b.initiative) {
const indexA = participants.findIndex(p => p.id === a.id);
const indexB = participants.findIndex(p => p.id === b.id);
return indexA - indexB;
}
return b.initiative - a.initiative;
});
}
return (
<div className="p-4 md:p-8 bg-slate-900 rounded-xl shadow-2xl">
<h2 className="text-4xl md:text-5xl font-bold text-center text-amber-400 mb-2">{name}</h2>
{isStarted && <p className="text-2xl text-center text-sky-300 mb-6">Round: {round}</p>}
{!isStarted && participants?.length > 0 && <p className="text-2xl text-center text-slate-400 mb-6">Awaiting Start</p>}
{!isStarted && (!participants || participants.length === 0) && <p className="text-2xl text-slate-500 mb-6">No participants.</p>}
{displayParticipants.length === 0 && isStarted && <p className="text-xl text-slate-400">No active participants.</p>}
<div className="space-y-4 max-w-3xl mx-auto">
{displayParticipants.map(p => (
<div key={p.id} className={`p-4 md:p-6 rounded-lg shadow-lg transition-all ${p.id === currentTurnParticipantId && isStarted ? 'bg-green-700 ring-4 ring-green-400 scale-105' : (p.type === 'character' ? 'bg-sky-700' : 'bg-red-700')} ${!p.isActive ? 'opacity-40 grayscale' : ''}`}>
<div className="flex justify-between items-center mb-2">
<h3 className={`text-2xl md:text-3xl font-bold ${p.id === currentTurnParticipantId && isStarted ? 'text-white' : (p.type === 'character' ? 'text-sky-100' : 'text-red-100')}`}>{p.name}{p.id === currentTurnParticipantId && isStarted && <span className="text-yellow-300 animate-pulse ml-2">(Current)</span>}</h3>
<span className={`text-xl md:text-2xl font-semibold ${p.id === currentTurnParticipantId && isStarted ? 'text-green-200' : 'text-slate-200'}`}>Init: {p.initiative}</span>
</div>
<div className="flex justify-between items-center">
<div className="w-full bg-slate-600 rounded-full h-6 md:h-8 relative overflow-hidden border-2 border-slate-500">
<div className={`h-full rounded-full transition-all ${p.currentHp <= p.maxHp / 4 ? 'bg-red-500' : (p.currentHp <= p.maxHp / 2 ? 'bg-yellow-500' : 'bg-green-500')}`} style={{ width: `${Math.max(0, (p.currentHp / p.maxHp) * 100)}%` }}></div>
{p.type !== 'monster' && ( // Only show HP text if not a monster
<span className="absolute inset-0 flex items-center justify-center text-xs md:text-sm font-medium text-white mix-blend-difference px-2">
HP: {p.currentHp} / {p.maxHp}
</span>
)}
</div>
</div>
{p.conditions?.length > 0 && <p className="text-sm text-yellow-300 mt-2">Conditions: {p.conditions.join(', ')}</p>}
{!p.isActive && <p className="text-center text-lg font-semibold text-slate-300 mt-2">(Inactive)</p>}
</div>
))}
</div>
</div>
);
}
function Modal({ onClose, title, children }) {
useEffect(() => {
const handleEsc = (event) => { if (event.key === 'Escape') onClose(); };
window.addEventListener('keydown', handleEsc);
return () => window.removeEventListener('keydown', handleEsc);
}, [onClose]);
return (
<div className="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center p-4 z-50">
<div className="bg-slate-800 p-6 rounded-lg shadow-xl w-full max-w-md">
<div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-semibold text-sky-300">{title}</h2>
<button onClick={onClose} className="text-slate-400 hover:text-slate-200"><XCircle size={24} /></button>
</div>
{children}
</div>
</div>
);
}
const PlayIcon = ({ size = 24, className = '' }) => <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>;
const SkipForwardIcon = ({ size = 24, className = '' }) => <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><polygon points="5 4 15 12 5 20 5 4"></polygon><line x1="19" y1="5" x2="19" y2="19"></line></svg>;
const StopCircleIcon = ({size=24, className=''}) => <svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><circle cx="12" cy="12" r="10"></circle><rect x="9" y="9" width="6" height="6"></rect></svg>;
export default App;

View File

@ -1,71 +1,45 @@
# Dockerfile
# Stage 1: Build the React application # Stage 1: Build the React application
FROM node:18-alpine AS build FROM node:18-alpine AS build
# Set the working directory LABEL stage="build-local-testing"
WORKDIR /app WORKDIR /app
# Copy package.json and package-lock.json (or yarn.lock) # Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./ COPY package*.json ./
# If using yarn, uncomment the next line and comment out the npm ci line
# COPY yarn.lock ./
# Install dependencies # Install dependencies using the lock file for consistency
# If using yarn, replace 'npm ci' with 'yarn install --frozen-lockfile' RUN npm install
RUN npm ci
# Copy the rest of the application source code # Copy the rest of the application source code
COPY . . COPY . .
# Build the application for production # --- For Local Testing with .env.local ---
# The REACT_APP_ID and REACT_APP_FIREBASE_CONFIG build arguments are optional. # Copy your .env.local file as .env in the build context.
# If you set them during your 'docker build' command, they will be baked into your static files. # Create React App's build script will automatically load variables from this .env file.
# Otherwise, the application will rely on the __app_id and __firebase_config global variables # IMPORTANT: Ensure .env.local contains your actual Firebase API keys and other secrets.
# being available in the environment where the built assets are served, or fall back to # This .env.local file MUST be in your .gitignore and NOT committed to your repository.
# the hardcoded defaults in the React code if those globals are not present. # This Docker image, built this way, CONTAINS YOUR SECRETS and should NOT be pushed to a public registry.
ARG REACT_APP_ID COPY .env.local .env
ARG REACT_APP_FIREBASE_CONFIG # --- End Local Testing Section ---
ENV VITE_APP_ID=$REACT_APP_ID
ENV VITE_FIREBASE_CONFIG=$REACT_APP_FIREBASE_CONFIG
# If your project uses Create React App (CRA - typically uses react-scripts build) # Build the application. react-scripts build will use environment variables
# RUN npm run build # 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) # Stage 2: Serve the static files using Nginx
# 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:
FROM nginx:1.25-alpine FROM nginx:1.25-alpine
LABEL stage="nginx-server"
# Copy the build output from the 'build' stage to Nginx's html directory # Copy the build output from the 'build' stage to Nginx's html directory
COPY --from=build /app/build /usr/share/nginx/html COPY --from=build /app/build /usr/share/nginx/html
# Expose port 80 for Nginx # Expose port 80 (Nginx default)
EXPOSE 80 EXPOSE 80
# Start Nginx when the container launches # Start Nginx when the container launches
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

210
README.md Normal file
View File

@ -0,0 +1,210 @@
# 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).
**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.
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
* **Campaign Management:**
* Create campaigns to organize game sessions.
* Option to set a custom background image URL for the player display on a per-campaign basis.
* 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:**
* Create multiple encounters per campaign.
* 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.
* 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:**
* A clean interface showing the current initiative order, participant HP (monster HP totals are hidden, only the bar is shown), and current turn.
* NPCs (monster-type) are visually distinct from hostile monsters.
* Displays custom campaign background if set.
* 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.
* **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.
* **Confirmation Modals:** Implemented for destructive actions like deleting campaigns, characters, encounters, or ending combat.
## Tech Stack
* **Frontend:** React
* **Styling:** Tailwind CSS
* **Backend/Database:** Firebase Firestore (for real-time data)
* **Authentication:** Firebase Anonymous Authentication
## App Usage Overview
![DM View Screenshot Placeholder](images/dm_view.png)
*(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:
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. Campaign cards will show a preview of this background.
* **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.
* **Manage Participants:**
* 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).
* 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).
* 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:**
* 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.
* 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:**
* Once participants are added and initiative is set, click "Start Encounter". This also automatically makes the encounter live on 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.
* 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.
* Click "End Encounter" (with confirmation) when combat is over. This also deactivates it from the Player Display.
2. **Player Display Window:**
* 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/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 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.
## 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 created and initialized.
* Anonymous Authentication enabled in the "Authentication" > "Sign-in method" tab.
* **Git:** For cloning the repository.
### Local Development Setup (using npm)
1. **Clone the Repository:**
```bash
git clone <your-repository-url>
cd ttrpg-initiative-tracker
```
2. **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.*
3. **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.
4. **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.
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
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
<pre>
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
</pre>
## Contributing
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.

View File

@ -1,4 +1,4 @@
# .env.example (This file IS committed to Git) # .env.example
REACT_APP_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY_HERE" REACT_APP_FIREBASE_API_KEY="YOUR_FIREBASE_API_KEY_HERE"
REACT_APP_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN_HERE" REACT_APP_FIREBASE_AUTH_DOMAIN="YOUR_FIREBASE_AUTH_DOMAIN_HERE"
REACT_APP_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID_HERE" REACT_APP_FIREBASE_PROJECT_ID="YOUR_FIREBASE_PROJECT_ID_HERE"

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

View File

@ -3,29 +3,32 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.17.0", // Optional: For testing "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", // Optional: For testing "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", // Optional: For testing "@testing-library/user-event": "^13.5.0",
"firebase": "^10.12.2", // Firebase SDK "firebase": "^10.12.2",
"lucide-react": "^0.395.0", // Icons "lucide-react": "^0.395.0",
"react": "^18.3.1", // React library "react": "^18.3.1",
"react-dom": "^18.3.1", // React DOM for web "react-dom": "^18.3.1",
"react-scripts": "5.0.1", // Scripts and configuration for Create React App "react-scripts": "5.0.1",
"web-vitals": "^2.1.4" // Optional: For measuring web vitals "web-vitals": "^2.1.4",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", // Optional: For testing "test": "react-scripts test",
"eject": "react-scripts eject" // Optional: For Create React App "eject": "react-scripts eject"
}, },
"eslintConfig": { // Optional: Basic ESLint setup "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",
"react-app/jest" "react-app/jest"
] ]
}, },
"browserslist": { // Optional: Defines browser support "browserslist": {
"production": [ "production": [
">0.2%", ">0.2%",
"not dead", "not dead",

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"
}

1084
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: [],
}