Archived
V1.0.1: Aldenfell campaign seed, content library, party overview
- Seed now resets the database and seeds the Aldenfell campaign from the campaign book: admin DM user, default weapons, locations, bestiary, pre-built encounters, and DM/shared notes - Default weapon/spell/monster library, character profile fields, locations and dice mode (new migration) - Party overview page, pagination, info tips, build preview calc - Remove stale demo-login hint; notes preserve line breaks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "DiceMode" AS ENUM ('DIGITAL', 'PHYSICAL');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "characters" ADD COLUMN "appearance" TEXT,
|
||||
ADD COLUMN "background" TEXT,
|
||||
ADD COLUMN "currentLocationId" TEXT,
|
||||
ADD COLUMN "diceMode" "DiceMode" NOT NULL DEFAULT 'DIGITAL',
|
||||
ADD COLUMN "privateNotes" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "locations" (
|
||||
"id" TEXT NOT NULL,
|
||||
"campaignId" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "locations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "locations" ADD CONSTRAINT "locations_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "campaigns"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "characters" ADD CONSTRAINT "characters_currentLocationId_fkey" FOREIGN KEY ("currentLocationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -101,6 +101,11 @@ enum NoteVisibility {
|
||||
SHARED
|
||||
}
|
||||
|
||||
enum DiceMode {
|
||||
DIGITAL
|
||||
PHYSICAL
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Identity & campaigns
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -141,10 +146,24 @@ model Campaign {
|
||||
monsters Monster[]
|
||||
encounters Encounter[]
|
||||
notes Note[]
|
||||
locations Location[]
|
||||
|
||||
@@map("campaigns")
|
||||
}
|
||||
|
||||
model Location {
|
||||
id String @id @default(cuid())
|
||||
campaignId String
|
||||
name String
|
||||
description String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||||
characters Character[]
|
||||
|
||||
@@map("locations")
|
||||
}
|
||||
|
||||
model CampaignMember {
|
||||
id String @id @default(cuid())
|
||||
campaignId String
|
||||
@@ -195,15 +214,24 @@ model Character {
|
||||
specialAbilities String? // free-text list shown in the quick-stats panel
|
||||
gold Int @default(0)
|
||||
|
||||
background String? // free-text story background, player-editable
|
||||
appearance String? // free-text character look/description, player-editable
|
||||
privateNotes String? // visible to the owning player only — not even the DM
|
||||
|
||||
diceMode DiceMode @default(DIGITAL) // chosen once, before the first build roll
|
||||
|
||||
currentLocationId String?
|
||||
|
||||
buildStage BuildStage @default(NOT_STARTED)
|
||||
buildState Json? // in-progress dice rolls / pending choices while building
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||||
user User? @relation("PlayerCharacters", fields: [userId], references: [id])
|
||||
createdBy User @relation("CreatedBy", fields: [createdById], references: [id])
|
||||
campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade)
|
||||
user User? @relation("PlayerCharacters", fields: [userId], references: [id])
|
||||
createdBy User @relation("CreatedBy", fields: [createdById], references: [id])
|
||||
currentLocation Location? @relation(fields: [currentLocationId], references: [id], onDelete: SetNull)
|
||||
|
||||
skillProficiencies CharacterSkillProficiency[]
|
||||
saveProficiencies CharacterSaveProficiency[]
|
||||
|
||||
+81
-41
@@ -1,8 +1,12 @@
|
||||
// Seeds a demo campaign for local dev. Species/classes/skills are NOT seeded
|
||||
// as rows — they're fixed game-rule tables ported into src/game/data/*.js and
|
||||
// used directly by the calculation engine. Weapons ARE seeded, but only into
|
||||
// this demo campaign (weapons are per-campaign in the schema, since a DM can
|
||||
// add homebrew weapons).
|
||||
// Resets the database and seeds the Aldenfell campaign (see
|
||||
// docs/Aldenfell - Full Campaign Book.docx and seed-data/aldenfell.js).
|
||||
//
|
||||
// DESTRUCTIVE: every user, campaign, character, note, etc. is deleted first.
|
||||
//
|
||||
// Species/classes/skills are NOT seeded as rows — they're fixed game-rule
|
||||
// tables ported into src/game/data/*.js, as is the default weapon/spell/monster
|
||||
// library DMs pull from. The default weapons (seed-data/weapons.json) ARE
|
||||
// seeded, into the campaign, since weapons are per-campaign in the schema.
|
||||
const path = require('path');
|
||||
const bcrypt = require('bcrypt');
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
@@ -10,54 +14,90 @@ const { generateInviteCode } = require('../src/utils/inviteCode');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const weapons = require(path.join(__dirname, '..', 'seed-data', 'weapons.json'));
|
||||
const aldenfell = require(path.join(__dirname, '..', 'seed-data', 'aldenfell.js'));
|
||||
|
||||
const ADMIN_EMAIL = 'joshua@crosscode.co.za';
|
||||
const ADMIN_PASSWORD = '12345678';
|
||||
|
||||
async function resetDatabase() {
|
||||
// Truncating the two roots cascades through every table that references them.
|
||||
await prisma.$executeRawUnsafe('TRUNCATE TABLE "users", "campaigns" RESTART IDENTITY CASCADE');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const passwordHash = await bcrypt.hash('password123', 12);
|
||||
await resetDatabase();
|
||||
|
||||
const dm = await prisma.user.upsert({
|
||||
where: { email: 'dm@example.com' },
|
||||
update: {},
|
||||
create: { email: 'dm@example.com', passwordHash, displayName: 'Dungeon Master' },
|
||||
const admin = await prisma.user.create({
|
||||
data: {
|
||||
email: ADMIN_EMAIL,
|
||||
passwordHash: await bcrypt.hash(ADMIN_PASSWORD, 12),
|
||||
displayName: 'Joshua',
|
||||
},
|
||||
});
|
||||
|
||||
const player = await prisma.user.upsert({
|
||||
where: { email: 'player@example.com' },
|
||||
update: {},
|
||||
create: { email: 'player@example.com', passwordHash, displayName: 'Test Player' },
|
||||
const campaign = await prisma.campaign.create({
|
||||
data: {
|
||||
...aldenfell.campaign,
|
||||
inviteCode: generateInviteCode(),
|
||||
ownerId: admin.id,
|
||||
members: { create: { userId: admin.id, role: 'DM' } },
|
||||
},
|
||||
});
|
||||
|
||||
let campaign = await prisma.campaign.findFirst({ where: { name: 'The Sunken Reach (Demo)' } });
|
||||
if (!campaign) {
|
||||
campaign = await prisma.campaign.create({
|
||||
data: {
|
||||
name: 'The Sunken Reach (Demo)',
|
||||
description: 'A demo campaign seeded for local development.',
|
||||
inviteCode: generateInviteCode(),
|
||||
startingGold: 15,
|
||||
startingItemCount: 2,
|
||||
startingSpellCount: 2,
|
||||
ownerId: dm.id,
|
||||
members: {
|
||||
create: [
|
||||
{ userId: dm.id, role: 'DM' },
|
||||
{ userId: player.id, role: 'PLAYER' },
|
||||
],
|
||||
},
|
||||
},
|
||||
await prisma.weapon.createMany({ data: weapons.map((w) => ({ ...w, campaignId: campaign.id })) });
|
||||
|
||||
await prisma.location.createMany({
|
||||
data: aldenfell.locations.map((l) => ({ ...l, campaignId: campaign.id })),
|
||||
});
|
||||
|
||||
const monsterByName = {};
|
||||
for (const monster of aldenfell.monsters) {
|
||||
const created = await prisma.monster.create({ data: { ...monster, campaignId: campaign.id } });
|
||||
monsterByName[created.name] = created;
|
||||
}
|
||||
|
||||
for (const enc of aldenfell.encounters) {
|
||||
const participants = [];
|
||||
for (const [name, count] of enc.monsters) {
|
||||
const monster = monsterByName[name];
|
||||
if (!monster) throw new Error(`Encounter "${enc.name}" references unknown monster "${name}"`);
|
||||
for (let i = 1; i <= count; i++) {
|
||||
participants.push({
|
||||
monsterId: monster.id,
|
||||
displayName: count > 1 ? `${monster.name} #${i}` : monster.name,
|
||||
currentHp: monster.maxHp,
|
||||
maxHp: monster.maxHp,
|
||||
isMonster: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
await prisma.encounter.create({
|
||||
data: { campaignId: campaign.id, name: enc.name, participants: { create: participants } },
|
||||
});
|
||||
}
|
||||
|
||||
for (const weapon of weapons) {
|
||||
const existing = await prisma.weapon.findFirst({ where: { campaignId: campaign.id, name: weapon.name } });
|
||||
if (!existing) {
|
||||
await prisma.weapon.create({ data: { ...weapon, campaignId: campaign.id } });
|
||||
}
|
||||
}
|
||||
// Notes list newest-first, so stamp them in reverse to keep book order on screen.
|
||||
const allNotes = [
|
||||
...aldenfell.sharedNotes.map((body) => ({ body, visibility: 'SHARED' })),
|
||||
...aldenfell.dmNotes.map((body) => ({ body, visibility: 'DM_ONLY' })),
|
||||
];
|
||||
const now = Date.now();
|
||||
await prisma.note.createMany({
|
||||
data: allNotes.map((n, i) => ({
|
||||
...n,
|
||||
campaignId: campaign.id,
|
||||
authorId: admin.id,
|
||||
createdAt: new Date(now - i * 1000),
|
||||
})),
|
||||
});
|
||||
|
||||
console.log('Seed complete.');
|
||||
console.log(` DM login: dm@example.com / password123`);
|
||||
console.log(` Player login: player@example.com / password123`);
|
||||
console.log(` Campaign invite code: ${campaign.inviteCode}`);
|
||||
console.log(` Admin/DM login: ${ADMIN_EMAIL} / ${ADMIN_PASSWORD}`);
|
||||
console.log(` Campaign: ${campaign.name} — invite code ${campaign.inviteCode}`);
|
||||
console.log(
|
||||
` ${weapons.length} weapons, ${aldenfell.locations.length} locations, ${aldenfell.monsters.length} monsters, ` +
|
||||
`${aldenfell.encounters.length} encounters, ${allNotes.length} notes`,
|
||||
);
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user