Files
dragonroll/backend/src/models/Map.js
Gitea OpenCode Agent d567b5d171
All checks were successful
Test / test (push) Successful in 2s
Fix issue #38: Implement tokens on maps
2026-10-14 18:41:17 +00:00

39 lines
1.6 KiB
JavaScript

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const MapSchema = new Schema({
name: { type: String, required: true, trim: true },
// Uploaded image, served from /api/public/<filename>
image: { type: String, default: '' },
// Grid cell size in image pixels
gridSize: { type: Number, min: 1, default: 50 },
// Grid origin, in image pixels from the top left corner of the image
offsetX: { type: Number, default: 0 },
offsetY: { type: Number, default: 0 },
// Distance each grid cell stands for (feet, metres...)
scale: { type: Number, min: 0.01, default: 5 },
// Notes pinned onto the map like markers. x/y are image pixels from the top left corner of the
// image, so a pin keeps its place whatever the zoom or the grid settings are.
pins: [{
note: { type: Schema.Types.ObjectId, ref: 'Note', required: true },
x: { type: Number, default: 0 },
y: { type: Number, default: 0 }
}],
// Actors dragged onto the map to stand on it as tokens. x/y are image pixels of the centre of the
// token, like a pin, and the viewer keeps them snapped onto a grid cell so a token sits where the
// square it stands in is.
tokens: [{
actor: { type: Schema.Types.ObjectId, ref: 'Actor', required: true },
x: { type: Number, default: 0 },
y: { type: Number, default: 0 }
}],
campaign: {
type: Schema.Types.ObjectId,
ref: 'Campaign',
required: true
},
date: { type: Date, default: Date.now }
});
module.exports = mongoose.model('Map', MapSchema);