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.
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
// Mythic Oracle — Meaning tables (Action + Descriptor)
|
|
|
|
import { getTable } from './api.js';
|
|
|
|
let actionEntries = null;
|
|
let descriptorEntries = null;
|
|
|
|
async function loadTables() {
|
|
if (!actionEntries) {
|
|
actionEntries = (await getTable('action')).entries;
|
|
}
|
|
if (!descriptorEntries) {
|
|
descriptorEntries = (await getTable('descriptor')).entries;
|
|
}
|
|
}
|
|
|
|
function renderWord(elId, word) {
|
|
const el = document.getElementById(elId);
|
|
el.textContent = word;
|
|
el.classList.remove('animate');
|
|
void el.offsetWidth;
|
|
el.classList.add('animate');
|
|
}
|
|
|
|
async function rollAction() {
|
|
await loadTables();
|
|
const word = actionEntries[Math.floor(Math.random() * actionEntries.length)];
|
|
renderWord('meaningAction', word);
|
|
}
|
|
|
|
async function rollDescriptor() {
|
|
await loadTables();
|
|
const word = descriptorEntries[Math.floor(Math.random() * descriptorEntries.length)];
|
|
renderWord('meaningDescriptor', word);
|
|
}
|
|
|
|
async function rollMeaning() {
|
|
await rollAction();
|
|
await rollDescriptor();
|
|
}
|
|
|
|
function init() {
|
|
document.getElementById('meaningRollBtn').addEventListener('click', rollMeaning);
|
|
document.getElementById('actionRollBtn').addEventListener('click', rollAction);
|
|
document.getElementById('descriptorRollBtn').addEventListener('click', rollDescriptor);
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', init);
|