Complete player stats inventory and Control content editors

This commit is contained in:
dingo
2026-09-08 06:02:13 -04:00
parent 2df1f6ab38
commit b6ce3bc292
27 changed files with 960 additions and 267 deletions
+11 -4
View File
@@ -1,5 +1,7 @@
import './portal.css';
import { permanentTitles, progressionSummary } from './progression';
import { statsBreakdown, equipmentDetails } from './character-stats';
import { showCatalog, hasCatalogDraft } from './content-editor';
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 };
@@ -45,6 +47,7 @@ function detail(r: RecordCharacter) {
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);
parent.append(el('h3', 'Progression'), progressionSummary(v), el('h3', 'Permanent titles'), permanentTitles(v.titles));
parent.append(el('h3','Full stats'),statsBreakdown(v),el('h3','Equipment'),equipmentDetails(v));
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();
}
@@ -52,12 +55,15 @@ 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();
const parent = $('records');
document.querySelector<HTMLElement>('.table-tools')!.hidden = tab === 'content';
if (tab === 'content') { showCatalog(parent); $('record-count').textContent = ''; $('table-note').textContent = 'Content changes are versioned and audited.'; return; }
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 row = body.insertRow(); const link = el('a', w.id, 'record-link'); link.href = gameURL(w.id); const worldName = el('div'); worldName.append(link, el('small', `Catalog ${w.catalogVersion ?? 0}`, 'muted block')); cell(row, worldName);
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');
@@ -107,8 +113,9 @@ async function refresh() {
} finally { busy = false; icons(); }
}
document.querySelectorAll<HTMLButtonElement>('[data-tab]').forEach(button => button.onclick = () => {
if (hasCatalogDraft()) { notify('Finish or cancel the open content draft before leaving.'); return; }
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';
$('view-title').textContent = tab === 'content' ? 'Game content' : 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');
@@ -122,4 +129,4 @@ $<HTMLFormElement>('command-form').onsubmit = async event => {
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);
icons(); void refresh(); setInterval(() => { if (!document.hidden && !hasCatalogDraft() && !$<HTMLDialogElement>('command-dialog').open && !$<HTMLDialogElement>('character-dialog').open) void refresh(); }, 5000);