Files
dragonroll/backend/src/models/Actor.js
Gitea OpenCode Agent 8418b5c254
Some checks failed
Test / test (push) Failing after 2s
Fix issue #64: More modifications to the character sheet
2026-10-15 15:01:35 +00:00

66 lines
2.6 KiB
JavaScript

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ActorSchema = new Schema({
name: { type: String, required: true, trim: true },
type: { type: String, enum: ['character', 'npc', 'creature'], default: 'character' },
species: { type: String, default: '' },
className: { type: String, default: '' },
subclass: { type: String, default: '' },
level: { type: Number, min: 1, max: 20, default: 1 },
background: { type: String, default: '' },
challengeRating: { type: String, default: '' },
description: { type: String, default: '' },
image: { type: String, default: '' },
abilityScores: {
str: { type: Number, min: 1, max: 30, default: 10 },
dex: { type: Number, min: 1, max: 30, default: 10 },
con: { type: Number, min: 1, max: 30, default: 10 },
int: { type: Number, min: 1, max: 30, default: 10 },
wis: { type: Number, min: 1, max: 30, default: 10 },
cha: { type: Number, min: 1, max: 30, default: 10 }
},
armorClass: { type: Number, min: 0, default: 10 },
speed: { type: Number, min: 0, default: 30 },
// The two pools the sheet draws as bars under the portrait (Syndria98/dragonroll#64): the bar
// fills `current` of `max`, so both travel together. `current` is kept below `max` by whoever
// writes them (routes/actor.js), the same way the sheet clamps the bar.
hitPoints: {
current: { type: Number, min: 0, default: 10 },
max: { type: Number, min: 0, default: 10 }
},
hitDice: {
current: { type: Number, min: 0, default: 1 },
max: { type: Number, min: 0, default: 1 }
},
proficiencies: { type: String, default: '' },
inventory: [{
name: { type: String, trim: true, default: '' },
quantity: { type: Number, min: 1, default: 1 },
weight: { type: Number, min: 0, default: 0 }
}],
traits: { type: String, default: '' },
spells: { type: String, default: '' },
campaign: {
type: Schema.Types.ObjectId,
ref: 'Campaign',
required: true
},
// The folder this actor stands in: a Folder of the same campaign whose target is
// 'actor' (null = the root of the actor list).
folder: {
type: Schema.Types.ObjectId,
ref: 'Folder',
default: null
},
foundryActorId: { type: String },
date: { type: Date, default: Date.now }
});
ActorSchema.index(
{ campaign: 1, foundryActorId: 1 },
{ unique: true, partialFilterExpression: { foundryActorId: { $type: 'string' } } }
);
module.exports = mongoose.model('Actor', ActorSchema);