ec28933623
Ports the four core Mythic GME tools from reference/index.html into the modular structure. Fate Check and Random Event Check preserve the exact probability matrix and roll logic, now reading chaos factor live from the active campaign instead of local state. Meaning and UNE tables are served from data/tables/ via a new tables route. UNE motivation uses the published verb+noun tables instead of the reference's flattened phrase list. Dice (pool builder, custom roll, percentile, ability score) is ported verbatim as pure frontend logic.
36 lines
881 B
JavaScript
36 lines
881 B
JavaScript
const express = require('express');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const router = express.Router();
|
|
|
|
const TABLES_DIR = path.join(__dirname, '..', '..', 'data', 'tables');
|
|
const NAME_PATTERN = /^[a-z0-9-]+$/;
|
|
|
|
router.get('/:name', (req, res) => {
|
|
const { name } = req.params;
|
|
|
|
if (!NAME_PATTERN.test(name)) {
|
|
return res.status(400).json({ error: 'invalid table name' });
|
|
}
|
|
|
|
const filePath = path.join(TABLES_DIR, `${name}.json`);
|
|
|
|
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
if (err.code === 'ENOENT') {
|
|
return res.status(404).json({ error: 'table not found' });
|
|
}
|
|
return res.status(500).json({ error: 'failed to read table' });
|
|
}
|
|
|
|
try {
|
|
res.json(JSON.parse(data));
|
|
} catch {
|
|
res.status(500).json({ error: 'invalid table data' });
|
|
}
|
|
});
|
|
});
|
|
|
|
module.exports = router;
|