Merge control portal work from RPGTheory/aeternalis-portal
RPGTheory/aeternalis-portal had diverged from this repo (the git/CI/CD copy) with an in-progress control portal feature that was never synced back here, so none of it had gone through CI or been deployed: - New site/game/control routing split: index.html becomes a world directory landing page (site.ts), game.html is the renamed former index.html (main.ts), control.html is a new admin panel (control.ts, portal-shared.ts, portal.css). - Server: new internal/store/portal.go (character/world registry, command queue, admin grants) and internal/transport/control.go (portal API routes), plus a new internal/gitops package that lets the portal provision new worlds via a GitOps repo commit. - game.World gains BornAt/DiedAt/DeathReason and an operator Control() path (close/open admissions, awaken boss, end world, per-character rename/heal/unstuck/retire); death no longer reuses the same character id on rejoin, matching the "new life" permadeath model in Plan.md rather than the old bypass-prevention test's expectations. - deploy/: new control-egress network policy and portal/control values (admin role, GitOps repo/branch/values file/CIDRs). - New e2e coverage: tests/portal.spec.ts, tools/capture-world.mjs. Verified this repo's own independent commits (800ms movement-staleness window, 20s boss-attack poll, SRS/TLS deploy values, ubuntu-22.04 runner pin, DOCKER_HOST fix) were already present in the portal copy before merging, so nothing here regresses them. `tsc --noEmit`, the vite client build, and the protocol contract check all pass; no go.mod changes. Could not run `go build`/`go test` locally (no Go toolchain on PATH, Docker daemon not running) — every new/changed Go symbol was manually cross-referenced and resolves, but this should still be built and tested in CI before merging to master. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#122b24"/><title>Aeternalis | Control</title><link rel="icon" href="data:,"/></head>
|
||||
<body class="control-site">
|
||||
<aside class="control-sidebar"><a class="wordmark" href="/">AETERNALIS<span>Control</span></a><nav aria-label="Control navigation"><button class="nav-item active" data-tab="worlds"><i data-lucide="globe-2"></i>Worlds</button><button class="nav-item" data-tab="characters"><i data-lucide="users"></i>Characters</button><button class="nav-item" data-tab="audit"><i data-lucide="scroll-text"></i>Audit log</button></nav><div class="sidebar-bottom"><a href="/"><i data-lucide="arrow-up-right"></i>Public site</a><a href="/game"><i data-lucide="play"></i>Game</a></div></aside>
|
||||
<main class="control-main"><header class="control-header"><div><p class="eyebrow">OPERATIONS</p><h1 id="view-title">Worlds</h1></div><div class="heading-tools"><span id="updated" class="muted"></span><button id="refresh" class="icon-button" title="Refresh" aria-label="Refresh"><i data-lucide="refresh-cw"></i></button><button id="create-world" class="button" disabled><i data-lucide="plus"></i>New world</button><button id="admin-signout" class="icon-button" title="Sign out" aria-label="Sign out" hidden><i data-lucide="log-out"></i></button></div></header>
|
||||
<div id="access" class="access-state"><i data-lucide="shield-check"></i><h2 id="access-title">Checking access</h2><p id="access-message"></p><a id="admin-login" class="button" href="/auth/login?return=%2Fcontrol" hidden>Sign in<i data-lucide="log-in"></i></a></div>
|
||||
<div id="workspace" hidden><section class="metrics" aria-label="World summary"><div><span>Worlds online</span><strong id="metric-worlds">0</strong></div><div><span>Living characters</span><strong id="metric-living">0</strong></div><div><span>Fallen characters</span><strong id="metric-dead">0</strong></div><div><span>Pending actions</span><strong id="metric-pending">0</strong></div></section>
|
||||
<div id="control-message" class="message" role="status" hidden></div>
|
||||
<div class="table-tools"><label class="search-field"><i data-lucide="search"></i><input id="search" type="search" aria-label="Search records" placeholder="Search worlds"/></label><label>World<select id="world-filter"><option value="">All worlds</option></select></label><label>State<select id="state-filter"><option value="">All states</option></select></label><span id="record-count" class="muted"></span></div>
|
||||
<section id="records" class="table-wrap" aria-label="Records"></section>
|
||||
<p id="table-note" class="table-note"></p>
|
||||
</div>
|
||||
</main>
|
||||
<dialog id="command-dialog" class="command-dialog"><form id="command-form"><header><h2 id="command-title">New world</h2><button type="button" id="close-command" class="icon-button" aria-label="Close dialog" title="Close"><i data-lucide="x"></i></button></header><p id="command-context" class="muted"></p><label id="world-input-label">World ID<input id="world-input" pattern="[a-z][a-z0-9-]{0,30}" maxlength="31" autocomplete="off"/></label><label id="value-input-label"><span id="value-caption">Seed</span><input id="value-input" autocomplete="off"/></label><label>Reason<textarea id="reason-input" required minlength="5" maxlength="240" rows="3"></textarea></label><label id="confirm-input-label" hidden><span id="confirm-caption">Confirm target</span><input id="confirm-input" autocomplete="off"/></label><p id="command-error" class="error" role="alert"></p><footer><button type="button" id="cancel-command" class="button secondary">Cancel</button><button type="submit" id="submit-command" class="button"><i data-lucide="check"></i><span>Queue action</span></button></footer></form></dialog>
|
||||
<dialog id="character-dialog" class="character-dialog"><header><div><p class="eyebrow">CHARACTER RECORD</p><h2 id="detail-name"></h2></div><button id="close-character" class="icon-button" aria-label="Close character" title="Close"><i data-lucide="x"></i></button></header><div id="character-detail"></div></dialog>
|
||||
<script type="module" src="/src/control.ts"></script>
|
||||
</body></html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#172725" />
|
||||
<title>Aeternalis</title>
|
||||
<link rel="icon" href="data:," />
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="world" aria-label="Aeternalis 3D world"></canvas>
|
||||
<div id="hud">
|
||||
<header class="topbar">
|
||||
<div class="brand"><a class="brand-mark" href="/" title="World directory" aria-label="World directory">A</a><div><strong>AETERNALIS</strong><span id="world-name">The First Reach</span></div></div>
|
||||
<div class="compass"><span>W</span><span>NW</span><b>N</b><span>NE</span><span>E</span></div>
|
||||
<div class="connection"><i id="connection-dot"></i><span id="connection-status">Connecting</span><button id="settings-toggle" class="icon" title="Display settings" aria-label="Display settings"><i data-lucide="settings-2"></i></button></div>
|
||||
</header>
|
||||
<section id="season" class="season"><div><span id="phase-label">THE GATHERING</span><strong id="season-clock">7d 00h</strong></div><span id="season-detail">Until the Harbinger</span><div class="thin-track"><i id="season-progress"></i></div></section>
|
||||
<section id="boss-bar" class="boss-bar" hidden><button id="target-boss" title="Target Harbinger" aria-label="Target Harbinger"><i data-lucide="crosshair"></i> THE HARBINGER</button><div class="bar"><i id="boss-health"></i></div><small id="boss-count"></small></section>
|
||||
<aside id="settings" class="panel settings" hidden><div class="panel-title"><h2>Display</h2><button data-close="settings" class="icon" title="Close" aria-label="Close display settings"><i data-lucide="x"></i></button></div><label>Detail <select id="quality"><option value="high">High</option><option value="low">Low</option></select></label><label>Camera distance <input id="zoom" type="range" min="30" max="100" value="62" /></label><button id="dev-boss" hidden><i data-lucide="flame"></i> Awaken Harbinger</button><button id="logout"><i data-lucide="log-out"></i> Sign out</button></aside>
|
||||
<aside id="inventory" class="panel inventory" hidden><div class="panel-title"><h2>Inventory</h2><button data-close="inventory" class="icon" title="Close" aria-label="Close inventory"><i data-lucide="x"></i></button></div><div id="inventory-items" class="inventory-items"></div><h3>Crafting</h3><div id="recipes"></div><h3>Skills</h3><div id="skills" class="skills"></div></aside>
|
||||
<div id="target" class="target" hidden><span id="target-name"></span><span id="target-health"></span></div>
|
||||
<div id="notice" role="status" class="notice" hidden></div>
|
||||
<footer class="bottom" id="game-controls" hidden>
|
||||
<section class="vitals"><div><strong id="character-name">Traveler</strong><span id="health-number">100 / 100</span></div><div class="bar"><i id="health-fill"></i></div><div class="vital-detail"><span><i data-lucide="hourglass"></i><span id="play-time">2h left today</span></span><span id="kills">0 kills</span></div></section>
|
||||
<nav class="actions" aria-label="Actions"><button id="attack" title="Attack" aria-label="Attack"><i data-lucide="swords"></i></button><button id="gather" title="Gather" aria-label="Gather"><i data-lucide="pickaxe"></i></button><button id="heal" title="Use bandage" aria-label="Use bandage"><i data-lucide="heart-pulse"></i><small id="bandage-count">0</small></button><button id="keystone" title="Return with keystone" aria-label="Return with keystone"><i data-lucide="gem"></i></button><span></span><button id="inventory-toggle" title="Inventory and crafting" aria-label="Inventory and crafting"><i data-lucide="backpack"></i></button></nav>
|
||||
<section class="location"><canvas id="minimap" width="140" height="140" aria-label="World map"></canvas><span id="coordinates">0, 0</span><small id="chunk-count">9 chunks</small></section>
|
||||
</footer>
|
||||
<nav id="movement" class="movement" aria-label="Movement" hidden><button data-move="up" aria-label="Move north"><i data-lucide="chevron-up"></i></button><button data-move="left" aria-label="Move west"><i data-lucide="chevron-left"></i></button><button data-move="down" aria-label="Move south"><i data-lucide="chevron-down"></i></button><button data-move="right" aria-label="Move east"><i data-lucide="chevron-right"></i></button></nav>
|
||||
</div>
|
||||
<dialog id="arrival" open><div class="eyebrow">THE FIRST REACH</div><h1>Aeternalis</h1><p id="arrival-status">One life. A world on borrowed time.</p><form id="join-form"><label for="name">Character name</label><input id="name" name="name" autocomplete="nickname" minlength="2" maxlength="24" placeholder="Traveler" required value="Traveler" /><button id="join" type="submit">Enter world <i data-lucide="arrow-right"></i></button></form><a id="login" class="command" href="/auth/login" hidden>Sign in <i data-lucide="arrow-right"></i></a><div id="passages"></div><p id="arrival-error" class="error" role="alert"></p></dialog>
|
||||
<dialog id="ending"><div class="eyebrow" id="ending-eyebrow">JOURNEY ENDED</div><h1 id="ending-title">Your story remains.</h1><p id="ending-detail"></p><div id="destinations"></div><button id="new-character" hidden>New character <i data-lucide="arrow-right"></i></button><button id="reconnect" hidden>Reconnect <i data-lucide="refresh-cw"></i></button><a href="/" class="command">World directory</a></dialog>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
+10
-33
@@ -1,35 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#172725" />
|
||||
<title>Aeternalis</title>
|
||||
<link rel="icon" href="data:," />
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="world" aria-label="Aeternalis 3D world"></canvas>
|
||||
<div id="hud">
|
||||
<header class="topbar">
|
||||
<div class="brand"><span class="brand-mark">A</span><div><strong>AETERNALIS</strong><span id="world-name">The First Reach</span></div></div>
|
||||
<div class="compass"><span>W</span><span>NW</span><b>N</b><span>NE</span><span>E</span></div>
|
||||
<div class="connection"><i id="connection-dot"></i><span id="connection-status">Connecting</span><button id="settings-toggle" class="icon" title="Display settings" aria-label="Display settings"><i data-lucide="settings-2"></i></button></div>
|
||||
</header>
|
||||
<section id="season" class="season"><div><span id="phase-label">THE GATHERING</span><strong id="season-clock">7d 00h</strong></div><span id="season-detail">Until the Harbinger</span><div class="thin-track"><i id="season-progress"></i></div></section>
|
||||
<section id="boss-bar" class="boss-bar" hidden><button id="target-boss" title="Target Harbinger" aria-label="Target Harbinger"><i data-lucide="crosshair"></i> THE HARBINGER</button><div class="bar"><i id="boss-health"></i></div><small id="boss-count"></small></section>
|
||||
<aside id="settings" class="panel settings" hidden><div class="panel-title"><h2>Display</h2><button data-close="settings" class="icon" title="Close" aria-label="Close display settings"><i data-lucide="x"></i></button></div><label>Detail <select id="quality"><option value="high">High</option><option value="low">Low</option></select></label><label>Camera distance <input id="zoom" type="range" min="30" max="100" value="62" /></label><button id="dev-boss" hidden><i data-lucide="flame"></i> Awaken Harbinger</button><button id="logout"><i data-lucide="log-out"></i> Sign out</button></aside>
|
||||
<aside id="inventory" class="panel inventory" hidden><div class="panel-title"><h2>Inventory</h2><button data-close="inventory" class="icon" title="Close" aria-label="Close inventory"><i data-lucide="x"></i></button></div><div id="inventory-items" class="inventory-items"></div><h3>Crafting</h3><div id="recipes"></div><h3>Skills</h3><div id="skills" class="skills"></div></aside>
|
||||
<div id="target" class="target" hidden><span id="target-name"></span><span id="target-health"></span></div>
|
||||
<div id="notice" role="status" class="notice" hidden></div>
|
||||
<footer class="bottom" id="game-controls" hidden>
|
||||
<section class="vitals"><div><strong id="character-name">Traveler</strong><span id="health-number">100 / 100</span></div><div class="bar"><i id="health-fill"></i></div><div class="vital-detail"><span><i data-lucide="hourglass"></i><span id="play-time">2h left today</span></span><span id="kills">0 kills</span></div></section>
|
||||
<nav class="actions" aria-label="Actions"><button id="attack" title="Attack" aria-label="Attack"><i data-lucide="swords"></i></button><button id="gather" title="Gather" aria-label="Gather"><i data-lucide="pickaxe"></i></button><button id="heal" title="Use bandage" aria-label="Use bandage"><i data-lucide="heart-pulse"></i><small id="bandage-count">0</small></button><button id="keystone" title="Return with keystone" aria-label="Return with keystone"><i data-lucide="gem"></i></button><span></span><button id="inventory-toggle" title="Inventory and crafting" aria-label="Inventory and crafting"><i data-lucide="backpack"></i></button></nav>
|
||||
<section class="location"><canvas id="minimap" width="140" height="140" aria-label="World map"></canvas><span id="coordinates">0, 0</span><small id="chunk-count">9 chunks</small></section>
|
||||
</footer>
|
||||
<nav id="movement" class="movement" aria-label="Movement" hidden><button data-move="up" aria-label="Move north"><i data-lucide="chevron-up"></i></button><button data-move="left" aria-label="Move west"><i data-lucide="chevron-left"></i></button><button data-move="down" aria-label="Move south"><i data-lucide="chevron-down"></i></button><button data-move="right" aria-label="Move east"><i data-lucide="chevron-right"></i></button></nav>
|
||||
</div>
|
||||
<dialog id="arrival" open><div class="eyebrow">THE FIRST REACH</div><h1>Aeternalis</h1><p id="arrival-status">One life. A world on borrowed time.</p><form id="join-form"><label for="name">Character name</label><input id="name" name="name" autocomplete="nickname" minlength="2" maxlength="24" placeholder="Traveler" required value="Traveler" /><button id="join" type="submit">Enter world <i data-lucide="arrow-right"></i></button></form><a id="login" class="command" href="/auth/login" hidden>Sign in <i data-lucide="arrow-right"></i></a><div id="passages"></div><p id="arrival-error" class="error" role="alert"></p></dialog>
|
||||
<dialog id="ending"><div class="eyebrow" id="ending-eyebrow">JOURNEY ENDED</div><h1 id="ending-title">Your story remains.</h1><p id="ending-detail"></p><div id="destinations"></div><button id="reconnect" hidden>Reconnect <i data-lucide="refresh-cw"></i></button></dialog>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
<head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#122b24"/><title>Aeternalis | Worlds</title><link rel="icon" href="data:,"/></head>
|
||||
<body class="public-site">
|
||||
<header class="site-header"><a class="wordmark" href="/">AETERNALIS<span>Survival worlds</span></a><nav aria-label="Main navigation"><a href="#worlds">Worlds</a><a href="#journey">My journey</a><a id="control-link" href="/control" hidden>Control</a><button id="account-button" class="button secondary"><i data-lucide="log-in"></i><span>Sign in</span></button></nav></header>
|
||||
<main>
|
||||
<section class="world-hero"><img src="/images/world.png" alt="The procedural forests and highlands of Aeternalis"/><div class="hero-shade"></div><div class="hero-copy"><p class="eyebrow">A WORLD ON BORROWED TIME</p><h1>Aeternalis</h1><p>The Harbinger is coming. Every life leaves a story.</p><a class="button light" href="#worlds">Choose a world<i data-lucide="arrow-down"></i></a></div><span class="hero-caption">THE FIRST REACH / IN-GAME TERRAIN</span></section>
|
||||
<section id="worlds" class="site-section"><div class="section-heading"><div><p class="eyebrow">THE REALMS</p><h2>Worlds</h2></div><div class="heading-tools"><span id="world-count" class="muted">Loading</span><button id="refresh" class="icon-button" aria-label="Refresh worlds" title="Refresh worlds"><i data-lucide="refresh-cw"></i></button></div></div><div id="site-message" class="message" role="status" hidden></div><div id="world-list" class="world-list" aria-live="polite"><p class="empty">Loading worlds...</p></div></section>
|
||||
<section id="journey" class="site-section journey-section"><div class="section-heading"><div><p class="eyebrow">ONE LIVING CHARACTER</p><h2>Your journey</h2></div></div><div id="active-character"></div><div id="character-history"><p class="empty">Sign in to see your characters.</p></div></section>
|
||||
</main><footer class="site-footer"><span>AETERNALIS</span><span>One character. One life. Another beginning.</span><a href="/control">Control portal</a></footer>
|
||||
<script type="module" src="/src/site.ts"></script>
|
||||
</body></html>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 284 KiB |
@@ -0,0 +1,123 @@
|
||||
import './portal.css';
|
||||
import { $, api, APIError, badge, cell, date, el, gameURL, icons, icon, table, type Command, type RecordCharacter, type World } from './portal-shared';
|
||||
|
||||
type Data = { worlds: World[]; characters: RecordCharacter[]; commands: Command[]; provisioningEnabled: boolean; characterLimit: number; auditLimit: number };
|
||||
type Draft = { id: string; worldId: string; op: string; target: string; value: string };
|
||||
let data: Data;
|
||||
let tab = 'worlds';
|
||||
let busy = false;
|
||||
let draft: Draft;
|
||||
const labels: Record<string, string> = { 'create-world': 'New world', 'close-admissions': 'Close arrivals', 'open-admissions': 'Open arrivals', 'awaken-boss': 'Awaken Harbinger', 'end-world': 'End world permanently', rename: 'Rename character', heal: 'Restore health', unstuck: 'Return to sanctuary', retire: 'Retire character permanently', 'revoke-sessions': 'Revoke account sessions' };
|
||||
function notify(message: string) { $('control-message').textContent = message; $('control-message').hidden = false; }
|
||||
function openCommand(op: string, worldId = '', target = '', value = '') {
|
||||
draft = { id: crypto.randomUUID(), worldId, op, target, value };
|
||||
$<HTMLFormElement>('command-form').reset();
|
||||
const create = op === 'create-world', rename = op === 'rename';
|
||||
$('command-title').textContent = labels[op];
|
||||
$('command-context').textContent = create ? 'Deployment: GitOps / ArgoCD' : `${worldId}${target ? ` / ${target}` : ''}`;
|
||||
$('world-input-label').hidden = !create;
|
||||
$<HTMLInputElement>('world-input').required = create;
|
||||
$('value-input-label').hidden = !create && !rename;
|
||||
$('value-caption').textContent = create ? 'Seed' : 'Character name';
|
||||
const input = $<HTMLInputElement>('value-input'); input.required = create || rename; input.value = create ? String(crypto.getRandomValues(new Uint32Array(1))[0]) : value;
|
||||
input.pattern = create ? '[0-9]{1,15}' : '[A-Za-z0-9][A-Za-z0-9 _-]{1,23}'; input.maxLength = create ? 15 : 24;
|
||||
const dangerous = ['awaken-boss', 'end-world', 'retire'].includes(op);
|
||||
$('confirm-input-label').hidden = !dangerous;
|
||||
$('confirm-caption').textContent = `Confirm ${op === 'retire' ? 'character ID' : 'world ID'}: ${op === 'retire' ? target : worldId}`;
|
||||
$<HTMLInputElement>('confirm-input').required = dangerous;
|
||||
$('submit-command').classList.toggle('danger', dangerous);
|
||||
$('command-error').textContent = '';
|
||||
$<HTMLDialogElement>('command-dialog').showModal();
|
||||
}
|
||||
function actions(world: string, options: string[], target = '', value = '', disabled = false) {
|
||||
const parent = el('div', '', 'row-actions'); const select = el('select'); select.setAttribute('aria-label', `Action for ${target || world}`);
|
||||
select.append(new Option('Actions', ''));
|
||||
for (const op of options) select.append(new Option(labels[op], op));
|
||||
select.disabled = disabled;
|
||||
select.onchange = () => { const op = select.value; select.value = ''; if (op) openCommand(op, world, target, value); };
|
||||
parent.append(select); return parent;
|
||||
}
|
||||
function detail(r: RecordCharacter) {
|
||||
$('detail-name').textContent = r.name;
|
||||
const parent = $('character-detail'); parent.replaceChildren();
|
||||
const list = el('dl', '', 'details'); const v = r.character.view;
|
||||
const pairs: [string, string][] = [['Character ID', r.id], ['Account ID', r.account], ['World', r.worldId], ['State', r.state], ['Health', `${v.entity.hp} / ${v.entity.maxHp}`], ['Position', `${Math.round(v.entity.position.x)}, ${Math.round(v.entity.position.y)}, ${Math.round(v.entity.position.z)}`], ['Played today', `${Math.floor(r.character.dailySeconds / 60)} min`], ['Born', date(r.character.bornAt)], ['Died', r.character.diedAt ? date(r.character.diedAt) : '-'], ['Cause', r.character.deathReason || '-']];
|
||||
for (const [key,value] of pairs) list.append(el('dt', key), el('dd', value)); parent.append(list);
|
||||
for (const [heading, items] of [['Inventory', v.inventory], ['Skills', v.skills]] as const) { parent.append(el('h3', heading)); const section = el('div', '', 'item-list'); for (const [key,value] of Object.entries(items)) { const item = el('span', key.replaceAll('_', ' ')); item.append(el('b', String(value))); section.append(item); } if (!section.children.length) section.append(el('span', 'None', 'muted')); parent.append(section); }
|
||||
$<HTMLDialogElement>('character-dialog').showModal();
|
||||
}
|
||||
function render() {
|
||||
if (!data) return;
|
||||
const search = $<HTMLInputElement>('search').value.trim().toLowerCase(), world = $<HTMLSelectElement>('world-filter').value, state = $<HTMLSelectElement>('state-filter').value;
|
||||
const matches = (fields: string[], recordWorld: string, recordState: string) => (!world || world === recordWorld) && (!state || state === recordState) && fields.join(' ').toLowerCase().includes(search);
|
||||
const parent = $('records'); parent.replaceChildren();
|
||||
let count = 0;
|
||||
if (tab === 'worlds') {
|
||||
const { node, body } = table(['World', 'Status', 'Living / capacity', 'Fallen', 'Harbinger arrives', 'Actions']);
|
||||
for (const w of data.worlds.filter(w => matches([w.id,w.phase], w.id, w.phase))) {
|
||||
const row = body.insertRow(); const link = el('a', w.id, 'record-link'); link.href = gameURL(w.id); cell(row, link);
|
||||
const status = el('div', '', 'badge-group'); status.append(badge(w.phase)); if (!w.available) status.append(badge('offline')); else if (w.closed) status.append(badge('closed'));
|
||||
cell(row, status); cell(row, `${w.living} / ${w.capacity}`); cell(row, String(w.dead)); cell(row, date(w.bossAt));
|
||||
const options = [w.closed ? 'open-admissions' : 'close-admissions']; if (w.phase === 'gathering') options.push('awaken-boss'); options.push('end-world');
|
||||
cell(row, actions(w.id, options, '', '', !w.available || ['won','lost'].includes(w.phase))); count++;
|
||||
}
|
||||
parent.append(node); $('table-note').textContent = 'Availability reflects the world-owner lease. Living counts include offline characters.';
|
||||
} else if (tab === 'characters') {
|
||||
const { node, body } = table(['Character', 'World', 'State', 'Health', 'Played today', 'Actions']);
|
||||
for (const r of data.characters.filter(r => matches([r.id,r.account,r.name,r.worldId], r.worldId,r.state))) {
|
||||
const row = body.insertRow(); const button = el('button', r.name, 'record-link'); button.onclick = () => detail(r); cell(row, button); cell(row, r.worldId); cell(row, badge(r.state)); cell(row, `${Math.ceil(r.character.view.entity.hp)} / ${r.character.view.entity.maxHp}`); cell(row, `${Math.floor(r.character.dailySeconds/60)} min`);
|
||||
const controls = actions(r.worldId, ['rename','heal','unstuck','retire'], r.id, r.name, r.state !== 'alive' || !data.worlds.find(w => w.id === r.worldId)?.available);
|
||||
const revoke = el('button', '', 'icon-button'); revoke.title = `Revoke sessions for ${r.name}`; revoke.setAttribute('aria-label', revoke.title); revoke.append(icon('log-out')); revoke.onclick = () => openCommand('revoke-sessions', r.worldId, r.account); controls.append(revoke); cell(row, controls); count++;
|
||||
}
|
||||
parent.append(node); $('table-note').textContent = `Up to ${data.characterLimit} records per world filter. Dead characters remain in history.`;
|
||||
} else {
|
||||
const { node, body } = table(['Requested', 'Action', 'World / target', 'Status', 'Reason / result']);
|
||||
for (const c of data.commands.filter(c => matches([c.id,c.actor,c.op,c.target,c.reason,c.result], c.worldId === '_provision' ? c.target : c.worldId,c.status))) {
|
||||
const row = body.insertRow(); cell(row, date(c.createdAt)); const op = el('div', labels[c.op] || c.op); op.title = `Request ${c.id}\nActor ${c.actor}`; cell(row, op); const target = el('div', c.worldId === '_provision' ? c.target : c.worldId); if (c.target && c.worldId !== '_provision') target.append(el('small', c.target, 'muted block')); cell(row, target); cell(row, badge(c.status)); const reason = el('div', c.reason); if (c.result) reason.append(el('small', c.result, 'muted block')); cell(row, reason); count++;
|
||||
}
|
||||
parent.append(node); $('table-note').textContent = `Latest ${data.auditLimit} actions. Completed provisioning means committed to Git; world availability confirms startup.`;
|
||||
}
|
||||
if (!count) parent.append(el('p', 'No matching records.', 'empty'));
|
||||
$('record-count').textContent = `${count} records`; icons();
|
||||
}
|
||||
function options(select: HTMLSelectElement, values: string[], all: string) {
|
||||
const current = select.value; select.replaceChildren(new Option(all, '')); for (const v of [...new Set(values)]) select.append(new Option(v, v)); select.value = values.includes(current) ? current : '';
|
||||
}
|
||||
async function refresh() {
|
||||
if (busy) return; busy = true;
|
||||
try {
|
||||
const world = $<HTMLSelectElement>('world-filter').value;
|
||||
data = await api<Data>(`/api/control?world=${encodeURIComponent(world)}`);
|
||||
$('access').hidden = true; $('workspace').hidden = false; $('admin-signout').hidden = false;
|
||||
const create = $<HTMLButtonElement>('create-world'); create.disabled = !data.provisioningEnabled; create.title = data.provisioningEnabled ? 'Provision world through GitOps' : 'GitOps provisioning is not configured';
|
||||
$('metric-worlds').textContent = String(data.worlds.filter(w => w.available).length);
|
||||
$('metric-living').textContent = String(data.worlds.reduce((n,w) => n+w.living, 0)); $('metric-dead').textContent = String(data.worlds.reduce((n,w) => n+w.dead, 0)); $('metric-pending').textContent = String(data.commands.filter(c => c.status === 'pending').length);
|
||||
options($<HTMLSelectElement>('world-filter'), data.worlds.map(w => w.id), 'All worlds');
|
||||
options($<HTMLSelectElement>('state-filter'), tab === 'worlds' ? ['gathering','cataclysm','won','lost'] : tab === 'characters' ? ['alive','dead','eligible'] : ['pending','completed','rejected'], 'All states');
|
||||
$('updated').textContent = `Updated ${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
|
||||
render();
|
||||
} catch (e) {
|
||||
if (!data || (e instanceof APIError && [401,403].includes(e.status))) {
|
||||
$('workspace').hidden = true; $('access').hidden = false; $('create-world').setAttribute('disabled', '');
|
||||
$('access-title').textContent = e instanceof APIError && e.status === 403 ? 'Administrator access required' : e instanceof APIError && e.status === 401 ? 'Sign in to Control' : 'Control unavailable';
|
||||
$('access-message').textContent = (e as Error).message; $('admin-login').hidden = false;
|
||||
} else notify((e as Error).message);
|
||||
} finally { busy = false; icons(); }
|
||||
}
|
||||
document.querySelectorAll<HTMLButtonElement>('[data-tab]').forEach(button => button.onclick = () => {
|
||||
tab = button.dataset.tab!; document.querySelectorAll('[data-tab]').forEach(b => b.classList.toggle('active', b === button));
|
||||
$('view-title').textContent = tab === 'audit' ? 'Audit log' : tab === 'characters' ? 'Characters' : 'Worlds';
|
||||
$<HTMLInputElement>('search').placeholder = `Search ${tab}`; $<HTMLSelectElement>('state-filter').value = ''; void refresh();
|
||||
});
|
||||
$('search').oninput = render; $('state-filter').onchange = render; $('world-filter').onchange = () => void refresh(); $('refresh').onclick = () => void refresh(); $('create-world').onclick = () => openCommand('create-world');
|
||||
for (const id of ['close-command','cancel-command']) $(id).onclick = () => $<HTMLDialogElement>('command-dialog').close();
|
||||
$('close-character').onclick = () => $<HTMLDialogElement>('character-dialog').close();
|
||||
$<HTMLFormElement>('command-form').onsubmit = async event => {
|
||||
event.preventDefault(); const submit = $<HTMLButtonElement>('submit-command'); submit.disabled = true;
|
||||
const body = { ...draft, worldId: draft.op === 'create-world' ? $<HTMLInputElement>('world-input').value : draft.worldId, value: ['rename','create-world'].includes(draft.op) ? $<HTMLInputElement>('value-input').value : '', reason: $<HTMLTextAreaElement>('reason-input').value, confirm: $<HTMLInputElement>('confirm-input').value };
|
||||
try { await api('/api/control/commands', body); $<HTMLDialogElement>('command-dialog').close(); notify('Action queued. Execution status is recorded in the audit log.'); await refresh(); }
|
||||
catch (e) { $('command-error').textContent = (e as Error).message; }
|
||||
finally { submit.disabled = false; }
|
||||
};
|
||||
$('admin-signout').onclick = async () => { try { await api('/auth/logout', {}); location.href = '/'; } catch(e) { notify((e as Error).message); } };
|
||||
icons(); void refresh(); setInterval(() => { if (!document.hidden && !$<HTMLDialogElement>('command-dialog').open && !$<HTMLDialogElement>('character-dialog').open) void refresh(); }, 5000);
|
||||
+12
-3
@@ -21,9 +21,11 @@ let pendingAction: { op: string; target: string } | undefined;
|
||||
let requestedClose = false;
|
||||
const keys = new Set<string>();
|
||||
let view: WorldView;
|
||||
const selectedWorld = new URLSearchParams(location.search).get('world');
|
||||
const worldPrefix = selectedWorld && /^[a-z][a-z0-9-]{0,30}$/.test(selectedWorld) ? `/worlds/${selectedWorld}` : '';
|
||||
|
||||
async function api<T>(path: string, body?: unknown): Promise<T> {
|
||||
const response = await fetch(path, { method: body === undefined ? 'GET' : 'POST', credentials: 'same-origin', headers: body === undefined ? {} : { 'Content-Type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
const response = await fetch(path.startsWith('/api/') ? worldPrefix + path : path, { method: body === undefined ? 'GET' : 'POST', credentials: 'same-origin', headers: body === undefined ? {} : { 'Content-Type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw new Error(result.error ?? `Request failed (${response.status})`);
|
||||
return result as T;
|
||||
@@ -54,7 +56,7 @@ function action(op: string) {
|
||||
function connect() {
|
||||
requestedClose = false; sequence = 0;
|
||||
const ending = $<HTMLDialogElement>('ending'); ending.close();
|
||||
ws = new WebSocket(`${location.protocol === 'https:' ? 'wss:' : 'ws:'}//${location.host}/ws`);
|
||||
ws = new WebSocket(`${location.protocol === 'https:' ? 'wss:' : 'ws:'}//${location.host}${worldPrefix}/ws`);
|
||||
ws.onopen = () => { $('connection-status').textContent = 'Connected'; $('connection-dot').parentElement!.classList.remove('offline'); };
|
||||
ws.onmessage = event => {
|
||||
const value = JSON.parse(event.data) as Snapshot;
|
||||
@@ -84,6 +86,7 @@ function showEnding(title: string, detail: string, survivor: boolean) {
|
||||
}
|
||||
if (survivor && destinations.children.length === 0) { const p = document.createElement('p'); p.textContent = 'Your passage is saved. No destination world is open yet.'; destinations.append(p); }
|
||||
visible('reconnect', false);
|
||||
visible('new-character', snapshot?.self.entity.state === 'dead' && ['gathering','cataclysm'].includes(snapshot.world.phase));
|
||||
$<HTMLDialogElement>('ending').show();
|
||||
}
|
||||
function inventory(c: Character) {
|
||||
@@ -141,6 +144,7 @@ function updateHUD(s: Snapshot) {
|
||||
if (s.message && s.message !== lastNotice) { notice(s.message); lastNotice = s.message; }
|
||||
}
|
||||
async function boot() {
|
||||
$<HTMLAnchorElement>('login').href = `/auth/login?return=${encodeURIComponent(location.pathname + location.search)}`;
|
||||
createIcons({ icons: { Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords, Pickaxe, HeartPulse, Gem, Backpack, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ArrowRight, RefreshCw } });
|
||||
view = new WorldView($<HTMLCanvasElement>('world'));
|
||||
view.start(dt => {
|
||||
@@ -165,7 +169,7 @@ async function boot() {
|
||||
view.addChunks(chunks); view.updateEntities(chunks.flatMap(c => c.resources));
|
||||
$('connection-status').textContent = 'World online';
|
||||
visible('dev-boss', config.development);
|
||||
let me: { character: Character | null } | undefined;
|
||||
let me: { character: Character | null; active?: { worldId: string; state: string; name: string } } | undefined;
|
||||
try { me = await api('/api/me'); } catch { if (config.development) { await api('/auth/dev', {}); me = await api('/api/me'); } }
|
||||
if (!me && !config.development) { visible('join-form', false); visible('login', true); }
|
||||
else if (me?.character) {
|
||||
@@ -174,6 +178,10 @@ async function boot() {
|
||||
else if (me.character.entity.state === 'eligible') showEnding('A passage forward.', 'Your survivor passage is saved.', true);
|
||||
else connect();
|
||||
} else {
|
||||
if (me?.active) {
|
||||
visible('join-form', false);
|
||||
const link = document.createElement('a'); link.href = `/game?world=${encodeURIComponent(me.active.worldId)}`; link.className = 'command'; link.textContent = `Continue ${me.active.name} in ${me.active.worldId}`; $('passages').append(link);
|
||||
}
|
||||
const passages = await api<{ characterId: string; sourceWorld: string; name: string }[]>('/api/passages').catch(() => []);
|
||||
for (const passage of passages.filter(p => p.sourceWorld !== config.worldId)) {
|
||||
const button = document.createElement('button'); button.textContent = `Continue as ${passage.name}`;
|
||||
@@ -193,6 +201,7 @@ async function boot() {
|
||||
$('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; };
|
||||
$('dev-boss').onclick = () => void api('/api/dev/boss', {}).catch(e => notice(e.message));
|
||||
$('reconnect').onclick = () => location.reload();
|
||||
$('new-character').onclick = () => { requestedClose = true; ws?.close(); location.reload(); };
|
||||
$('logout').onclick = async () => { requestedClose = true; await api('/auth/logout', {}); ws?.close(); location.reload(); };
|
||||
$<HTMLSelectElement>('quality').onchange = event => view.quality((event.target as HTMLSelectElement).value === 'high');
|
||||
$<HTMLInputElement>('zoom').oninput = event => { view.distance = Number((event.target as HTMLInputElement).value); view.resize(); };
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createIcons, ArrowDown, ArrowRight, ArrowUpRight, Check, Globe2, HeartPulse, LogIn, LogOut, MapPin, MoreHorizontal, Play, Plus, RefreshCw, ScrollText, Search, ShieldCheck, Users, X } from 'lucide';
|
||||
import type { Character } from './generated';
|
||||
|
||||
export type RecordCharacter = { id: string; account: string; worldId: string; name: string; state: string; character: { view: Character; bornAt: string; diedAt?: string; deathReason?: string; dailySeconds: number } };
|
||||
export type World = { id: string; phase: string; living: number; dead: number; capacity: number; createdAt: string; bossAt: string; closed: boolean; available: boolean; revision: number };
|
||||
export type Command = { id: string; worldId: string; actor: string; op: string; target: string; value: string; reason: string; status: string; result: string; createdAt: number; completedAt: number };
|
||||
export const $ = <T extends HTMLElement = HTMLElement>(id: string) => document.getElementById(id) as T;
|
||||
export const el = <K extends keyof HTMLElementTagNameMap>(tag: K, text = '', className = '') => { const node = document.createElement(tag); node.textContent = text; node.className = className; return node; };
|
||||
export function icons() { createIcons({ icons: { ArrowDown, ArrowRight, ArrowUpRight, Check, Globe2, HeartPulse, LogIn, LogOut, MapPin, MoreHorizontal, Play, Plus, RefreshCw, ScrollText, Search, ShieldCheck, Users, X } }); }
|
||||
export function icon(name: string) { const node = el('i'); node.dataset.lucide = name; return node; }
|
||||
export function badge(state: string) { return el('span', state.replaceAll('-', ' '), `badge state-${state}`); }
|
||||
export function date(value: string | number) { return value ? new Date(typeof value === 'number' ? value * 1000 : value).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }) : 'Unknown'; }
|
||||
export function gameURL(world: string) { return `/game?world=${encodeURIComponent(world)}`; }
|
||||
export class APIError extends Error { constructor(message: string, public status: number) { super(message); } }
|
||||
export async function api<T>(path: string, body?: unknown): Promise<T> {
|
||||
const response = await fetch(path, { method: body === undefined ? 'GET' : 'POST', credentials: 'same-origin', signal: AbortSignal.timeout(15000), headers: body === undefined ? {} : { 'Content-Type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
const value = await response.json().catch(() => ({ error: `Request failed (${response.status})` }));
|
||||
if (!response.ok) throw new APIError(value.error || `Request failed (${response.status})`, response.status);
|
||||
return value;
|
||||
}
|
||||
export function table(headers: string[]) { const node = el('table'); const head = node.createTHead().insertRow(); for (const label of headers) { const th = el('th', label); th.scope = 'col'; head.append(th); } const body = node.createTBody(); return { node, body }; }
|
||||
export function cell(row: HTMLTableRowElement, content: string | Node) { const td = row.insertCell(); typeof content === 'string' ? td.textContent = content : td.append(content); return td; }
|
||||
@@ -0,0 +1,10 @@
|
||||
:root { font-family: Inter, 'Segoe UI', sans-serif; color: #202923; background: #f8faf9; font-synthesis: none; letter-spacing: 0; --line: #dce3df; --muted: #66736d; --green: #215944; --red: #a83543; }
|
||||
* { box-sizing: border-box; } body { margin: 0; } [hidden] { display: none !important; } button, input, select, textarea { font: inherit; } button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; } a { color: inherit; text-decoration: none; } button { cursor: pointer; } button:disabled, .disabled { opacity: .45; cursor: not-allowed; } :focus-visible { outline: 3px solid #81b9a3; outline-offset: 3px; } h1,h2,h3,p { margin: 0; } h1 { font-size: 28px; } h2 { font-size: 25px; font-weight: 600; } h3 { font-size: 18px; font-weight: 600; } svg { width: 18px; height: 18px; flex-shrink: 0; } .muted { color: var(--muted); font-size: 13px; } .block { display: block; margin-top: 5px; } .eyebrow { font-size: 11px; font-weight: 650; color: var(--muted); margin-bottom: 9px; } .button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; padding: 10px 17px; border: 1px solid transparent; border-radius: 5px; background: var(--green); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; } .button:hover:not(:disabled):not(.disabled) { background: #183e30; } .button.secondary { background: #fff; color: #253c31; border-color: var(--line); } .button.secondary:hover { background: #edf3ef; } .button.light { background: #fff; color: #233d30; } .button.danger { background: var(--red); } .icon-button { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: #48564d; flex-shrink: 0; } .icon-button:hover { background: #edf3ef; } .heading-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } .wordmark { display: block; font-weight: 750; font-size: 18px; } .wordmark span { display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 4px; } .empty { padding: 32px 0; font-size: 14px; color: var(--muted); } .message { padding: 12px 16px; margin: 16px 0; background: #edf3ef; border-left: 3px solid #408362; font-size: 13px; overflow-wrap: anywhere; } .error { color: var(--red); font-size: 13px; min-height: 20px; }
|
||||
.site-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; padding: 18px 5%; gap: 24px; background: #fff; } .site-header nav { display: flex; align-items: center; gap: 26px; font-size: 13px; } .world-hero { position: relative; height: 420px; max-height: 58vh; min-height: 300px; overflow: hidden; background: #244d3a; color: #fff; } .world-hero > img { width: 100%; height: 100%; object-fit: cover; object-position: center 45%; } .hero-shade { position: absolute; inset: 0; background: linear-gradient(90deg, #071810b8 0%, #07181035 48%, transparent 100%); } .hero-copy { position: absolute; inset: auto 5% 48px; max-width: 560px; } .hero-copy .eyebrow { color: #d6e9dc; } .hero-copy h1 { font-family: Georgia, serif; font-size: 64px; font-weight: 400; line-height: 1.1; } .hero-copy > p:not(.eyebrow) { margin: 14px 0 25px; font-size: 16px; line-height: 1.6; } .hero-caption { position: absolute; bottom: 22px; right: 5%; font-size: 10px; color: #eff8f1; } .site-section { padding: 40px 5%; } .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; } .world-list { border-top: 1px solid var(--line); } .world-row { display: grid; grid-template-columns: 56px minmax(120px, 1fr) minmax(100px, .65fr) minmax(175px, 1fr) auto; gap: 22px; align-items: center; padding: 23px 0; border-bottom: 1px solid var(--line); } .world-emblem { display: grid; place-items: center; width: 52px; height: 52px; background: #e7efe9; border-radius: 5px; color: #366d53; } .world-emblem svg { width: 25px; height: 25px; } .world-name h3 { margin-bottom: 9px; overflow-wrap: anywhere; } .world-stat span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 8px; } .world-stat strong { font-size: 13px; font-weight: 550; } .journey-section { background: #edf2ef; } .active-life { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 0 0 28px; } .active-life p { margin-top: 9px; } .site-footer { display: flex; align-items: center; justify-content: space-between; padding: 30px 5%; gap: 22px; font-size: 12px; color: var(--muted); } .site-footer > span:first-child { font-weight: 700; color: #34483c; }
|
||||
.control-site { display: grid; grid-template-columns: 204px minmax(0, 1fr); min-height: 100vh; background: #fff; } .control-sidebar { border-right: 1px solid var(--line); background: #f5f8f6; display: flex; flex-direction: column; padding: 28px 18px; } .control-sidebar .wordmark { padding: 0 10px; margin-bottom: 42px; } .control-sidebar nav { display: grid; gap: 7px; } .nav-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 12px; background: transparent; color: #657169; border: 0; text-align: left; border-radius: 4px; font-size: 13px; } .nav-item:hover { background: #eaf0ec; } .nav-item.active { background: #dfece4; color: #234b36; font-weight: 600; } .sidebar-bottom { margin-top: auto; padding: 40px 10px 0; display: grid; gap: 18px; } .sidebar-bottom a { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); } .control-main { min-width: 0; padding: 30px 32px; } .control-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 65px; margin-bottom: 28px; } .control-header h1 { font-size: 27px; font-weight: 600; } .metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 24px 0; margin-bottom: 30px; } .metrics > div { padding: 0 22px; border-right: 1px solid var(--line); } .metrics > div:first-child { padding-left: 0; } .metrics > div:last-child { border-right: 0; } .metrics span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; } .metrics strong { font-size: 28px; font-weight: 550; } .table-tools { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding-bottom: 18px; } .table-tools label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); } input,select,textarea { background: #fff; color: #25362b; border: 1px solid #cfdad3; border-radius: 4px; padding: 9px 10px; font-size: 13px; max-width: 100%; } select { min-height: 36px; } .search-field { position: relative; flex: 1; min-width: 160px; max-width: 340px; } .search-field svg { position: absolute; left: 11px; } .search-field input { width: 100%; padding-left: 35px; } .table-tools > .muted { margin-left: auto; } .table-wrap { width: 100%; overflow-x: auto; } table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; } th { color: var(--muted); font-size: 11px; font-weight: 550; background: #f6f8f7; padding: 13px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; } td { padding: 17px 14px; border-bottom: 1px solid #e6ebe8; line-height: 1.5; min-width: 95px; max-width: 360px; overflow-wrap: anywhere; } tbody tr:hover { background: #f8faf9; } .record-link { border: 0; padding: 0; background: none; color: #225e43; font-size: inherit; font-weight: 650; text-align: left; } .record-link:hover { text-decoration: underline; } .row-actions { display: flex; align-items: center; gap: 7px; } .row-actions select { min-width: 110px; max-width: 166px; font-size: 11px; } .badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 7px; background: #eef1ef; color: #56665b; border-radius: 3px; font-size: 10px; white-space: nowrap; text-transform: capitalize; } .badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; } .state-alive,.state-gathering,.state-completed { background: #e4f2e9; color: #28714c; } .state-eligible,.state-won { background: #e3eef6; color: #326e94; } .state-cataclysm,.state-pending,.state-closed { background: #faf0db; color: #986412; } .state-dead,.state-lost,.state-rejected { background: #fae9eb; color: #a24554; } .badge-group { display: flex; flex-wrap: wrap; gap: 5px; } .table-note { padding-top: 18px; font-size: 11px; color: var(--muted); line-height: 1.6; } .access-state { padding: 100px 20px; text-align: center; } .access-state > svg { width: 34px; height: 34px; color: #587864; margin-bottom: 22px; } .access-state h2 { font-size: 23px; } .access-state p { font-size: 13px; color: var(--muted); margin: 16px auto 24px; max-width: 440px; line-height: 1.7; }
|
||||
dialog { width: min(510px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; padding: 26px; color: #24352b; box-shadow: 0 18px 70px #11251a25; } dialog::backdrop { background: #0f211b70; } dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; } dialog h2 { font-size: 21px; overflow-wrap: anywhere; } dialog h3 { font-size: 14px; margin: 24px 0 12px; } dialog label { display: flex; flex-direction: column; gap: 8px; font-size: 12px; margin-top: 20px; overflow-wrap: anywhere; } dialog input,dialog textarea { width: 100%; } dialog footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; } dialog .error { margin-top: 18px; } #command-context { overflow-wrap: anywhere; line-height: 1.6; } .details { display: grid; grid-template-columns: 115px minmax(0,1fr); gap: 14px; font-size: 12px; } .details dt { color: var(--muted); } .details dd { margin: 0; overflow-wrap: anywhere; } .item-list { display: grid; gap: 10px; font-size: 12px; } .item-list span { display: flex; justify-content: space-between; gap: 14px; }
|
||||
@media(min-width:1600px) { .site-section { padding-left: max(5%, calc((100% - 1440px) / 2)); padding-right: max(5%, calc((100% - 1440px) / 2)); } }
|
||||
@media(max-width:1100px) { .control-site { grid-template-columns: 174px minmax(0,1fr); } .control-main { padding: 26px 22px; } .world-row { grid-template-columns: 44px 1fr 100px 180px; gap: 16px; } .world-row > .button { grid-column: 2 / -1; justify-self: start; } .control-header #updated { display: none; } }
|
||||
@media(max-width:720px) { .site-header { padding: 16px 5%; flex-wrap: wrap; gap: 18px; } .site-header nav { gap: 17px; width: 100%; justify-content: space-between; } .site-header nav > a { font-size: 12px; } .wordmark { font-size: 17px; } .world-hero { min-height: 300px; max-height: none; height: 350px; } .hero-copy { bottom: 45px; right: 6%; } .hero-copy h1 { font-size: 47px; } .hero-copy > p:not(.eyebrow) { font-size: 14px; max-width: 260px; } .hero-caption { font-size: 8px; } .site-section { padding-top: 30px; padding-bottom: 30px; } .section-heading h2 { font-size: 23px; } .world-row { grid-template-columns: 42px minmax(0,1fr) auto; gap: 17px 12px; } .world-emblem { width: 38px; height: 42px; } .world-name h3 { font-size: 16px; } .world-row .world-stat:nth-child(4) { grid-column: 2; } .world-row > .button { grid-column: 3; font-size: 11px; padding: 9px; } .world-stat strong { font-size: 12px; } .world-stat span { margin-bottom: 4px; } .active-life { align-items: flex-start; flex-wrap: wrap; } .site-footer { flex-wrap: wrap; } .site-footer > span:nth-child(2) { order: 3; width: 100%; } .control-site { display: block; } .control-sidebar { padding: 18px; border-right: 0; border-bottom: 1px solid var(--line); } .control-sidebar .wordmark { margin-bottom: 18px; padding: 0; } .control-sidebar nav { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 3px; } .nav-item { justify-content: center; padding: 11px 4px; gap: 6px; font-size: 12px; } .sidebar-bottom { display: none; } .control-main { padding: 22px 16px; } .control-header { margin-bottom: 20px; gap: 12px; } .control-header h1 { font-size: 24px; } .control-header .heading-tools { gap: 6px; } #admin-signout { display: none; } #create-world { padding: 10px; font-size: 12px; } .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px 0; padding: 20px 0; margin-bottom: 20px; } .metrics > div { padding: 0 16px; } .metrics > div:nth-child(3) { padding-left: 0; } .metrics > div:nth-child(2) { border-right: 0; } .metrics strong { font-size: 24px; } .metrics span { font-size: 11px; } .table-tools { gap: 12px; } .search-field { flex-basis: 100%; max-width: none; } .table-tools > .muted { font-size: 11px; } .table-tools label { font-size: 11px; } .table-tools select { max-width: 135px; font-size: 12px; } th,td { padding: 12px 10px; } .access-state { padding: 65px 5px; } dialog { padding: 21px; } }
|
||||
.button.secondary:hover:not(:disabled):not(.disabled), .button.light:hover:not(:disabled):not(.disabled) { background: #edf3ef; color: #253c31; }
|
||||
@media(prefers-reduced-motion:reduce) { * { scroll-behavior: auto !important; } }
|
||||
@@ -0,0 +1,58 @@
|
||||
import './portal.css';
|
||||
import { $, api, APIError, badge, cell, date, el, gameURL, icons, icon, table, type RecordCharacter, type World } from './portal-shared';
|
||||
|
||||
type Account = { active: RecordCharacter | null; characters: RecordCharacter[]; admin: boolean };
|
||||
let account: Account | null = null;
|
||||
let development = false;
|
||||
let busy = false;
|
||||
function renderWorlds(worlds: World[]) {
|
||||
const list = $('world-list'); list.replaceChildren();
|
||||
$('world-count').textContent = `${worlds.filter(w => w.available).length} online / ${worlds.length} worlds`;
|
||||
if (!worlds.length) list.append(el('p', 'No worlds are open yet.', 'empty'));
|
||||
for (const world of worlds) {
|
||||
const row = el('article', '', 'world-row');
|
||||
const emblem = el('div', '', 'world-emblem'); emblem.append(icon('globe-2'));
|
||||
const heading = el('div', '', 'world-name'); heading.append(el('h3', world.id), badge(!world.available ? 'offline' : world.phase));
|
||||
const population = el('div', '', 'world-stat'); population.append(el('span', 'Living'), el('strong', `${world.living} / ${world.capacity}`));
|
||||
const clock = el('div', '', 'world-stat'); clock.append(el('span', world.phase === 'gathering' ? 'Harbinger arrives' : 'Season'), el('strong', world.phase === 'gathering' ? date(world.bossAt) : world.phase === 'cataclysm' ? 'The world is collapsing' : 'Ended'));
|
||||
const active = account?.active;
|
||||
const resume = active?.worldId === world.id;
|
||||
const transfer = active?.state === 'eligible' && active.worldId !== world.id && world.phase === 'gathering';
|
||||
const open = world.available && (resume || (!world.closed && world.living < world.capacity && ['gathering', 'cataclysm'].includes(world.phase) && (!active || transfer)));
|
||||
const action = el('a', resume ? 'Continue' : transfer ? 'Use passage' : 'Enter world', `button ${open ? '' : 'disabled'}`);
|
||||
if (open) action.href = gameURL(world.id); else { action.setAttribute('aria-disabled', 'true'); action.title = active && !resume && !transfer ? `Living character in ${active.worldId}` : 'World unavailable for arrivals'; }
|
||||
action.append(icon('arrow-right')); row.append(emblem, heading, population, clock, action); list.append(row);
|
||||
}
|
||||
}
|
||||
function renderAccount() {
|
||||
const parent = $('active-character'); parent.replaceChildren();
|
||||
const history = $('character-history'); history.replaceChildren();
|
||||
$('control-link').hidden = !account?.admin;
|
||||
$('account-button').replaceChildren(icon(account ? 'log-out' : 'log-in'), el('span', account ? 'Sign out' : 'Sign in'));
|
||||
if (!account) { history.append(el('p', 'Sign in to see your characters.', 'empty')); return; }
|
||||
if (account.active) { const r = account.active; const summary = el('div', '', 'active-life'); const title = el('div'); title.append(el('h3', r.name), el('p', `${r.worldId} / ${r.state === 'eligible' ? 'Passage earned' : `${Math.ceil(r.character.view.entity.hp)} health`}`, 'muted')); const link = el('a', 'Continue journey', 'button'); link.href = gameURL(r.worldId); link.append(icon('arrow-right')); summary.append(title, link); parent.append(summary); }
|
||||
else parent.append(el('p', 'Your next life is waiting in an open world.', 'empty'));
|
||||
if (!account.characters.length) return;
|
||||
const { node, body } = table(['Character', 'World', 'State', 'Journey ended', 'Cause']);
|
||||
for (const r of [...account.characters].sort((a,b) => (b.character.diedAt || b.character.bornAt).localeCompare(a.character.diedAt || a.character.bornAt))) {
|
||||
const row = body.insertRow(); cell(row, r.name); cell(row, r.worldId); cell(row, badge(r.state)); cell(row, r.character.diedAt ? date(r.character.diedAt) : '-'); cell(row, r.character.deathReason || '-');
|
||||
}
|
||||
const wrapper = el('div', '', 'table-wrap'); wrapper.append(node); history.append(wrapper);
|
||||
}
|
||||
async function refresh() {
|
||||
if (busy) return; busy = true;
|
||||
try {
|
||||
const worlds = await api<World[]>('/api/worlds');
|
||||
try { account = await api<Account>('/api/account'); } catch (e) { if (e instanceof APIError && e.status === 401) account = null; else throw e; }
|
||||
renderAccount(); renderWorlds(worlds); $('site-message').hidden = true; icons();
|
||||
} catch (e) { $('site-message').textContent = (e as Error).message; $('site-message').hidden = false; }
|
||||
finally { busy = false; }
|
||||
}
|
||||
$('refresh').onclick = () => void refresh();
|
||||
$('account-button').onclick = async () => {
|
||||
try { if (account) { await api('/auth/logout', {}); await refresh(); } else if (development) { await api('/auth/dev', {}); await refresh(); } else location.href = '/auth/login'; }
|
||||
catch (e) { $('site-message').hidden = false; $('site-message').textContent = (e as Error).message; }
|
||||
};
|
||||
icons();
|
||||
void api<{ development: boolean }>('/api/config').then(c => { development = c.development; }).catch(() => {});
|
||||
void refresh(); setInterval(() => { if (!document.hidden) void refresh(); }, 15000);
|
||||
@@ -1,10 +1,11 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
export default defineConfig({
|
||||
root: 'client',
|
||||
build: { outDir: 'dist', target: 'es2022', chunkSizeWarningLimit: 650 },
|
||||
build: { outDir: 'dist', target: 'es2022', chunkSizeWarningLimit: 650, rollupOptions: { input: { site: resolve('client/index.html'), game: resolve('client/game.html'), control: resolve('client/control.html') } } },
|
||||
server: {
|
||||
port: 5175, strictPort: true,
|
||||
proxy: { '/api': 'http://127.0.0.1:18080', '/auth': 'http://127.0.0.1:18080', '/ws': { target: 'ws://127.0.0.1:18080', ws: true } },
|
||||
proxy: { '/worlds': { target: 'http://127.0.0.1:18080', ws: true }, '/api': 'http://127.0.0.1:18080', '/auth': 'http://127.0.0.1:18080', '/ws': { target: 'ws://127.0.0.1:18080', ws: true } },
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user