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.
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
// Mythic Oracle — shared fetch wrapper, all API calls
|
|
|
|
const BASE_URL = '/api';
|
|
|
|
async function request(path, options = {}) {
|
|
const response = await fetch(`${BASE_URL}${path}`, {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
...options,
|
|
});
|
|
|
|
if (!response.ok) {
|
|
let message = `Request failed: ${response.status}`;
|
|
try {
|
|
const body = await response.json();
|
|
if (body.error) message = body.error;
|
|
} catch {
|
|
// no JSON body on the error response
|
|
}
|
|
throw new Error(message);
|
|
}
|
|
|
|
if (response.status === 204) {
|
|
return null;
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
export function getCampaigns() {
|
|
return request('/campaigns');
|
|
}
|
|
|
|
export function createCampaign(data) {
|
|
return request('/campaigns', { method: 'POST', body: JSON.stringify(data) });
|
|
}
|
|
|
|
export function getCampaign(id) {
|
|
return request(`/campaigns/${id}`);
|
|
}
|
|
|
|
export function updateCampaign(id, data) {
|
|
return request(`/campaigns/${id}`, { method: 'PATCH', body: JSON.stringify(data) });
|
|
}
|
|
|
|
export function deleteCampaign(id) {
|
|
return request(`/campaigns/${id}`, { method: 'DELETE' });
|
|
}
|
|
|
|
export function getSystems() {
|
|
return request('/systems');
|
|
}
|
|
|
|
export function getTable(name) {
|
|
return request(`/tables/${name}`);
|
|
}
|