Built: - Client: trade screen, world/end-game screen (landing sites, shipping, node build, final ranking), report sharing + alliance reports tab, alert describers for all notification types, error-code strings (en+nb) for every server CODE. - tools/bot.js (+ tools/bot/): 50 headless bots against the real server in-process with a fake clock; resource/unit conservation ledger, exit 1 on broken invariants. docs/BALANCE.md has method and every run behind a number. - Balance changes (evidence in docs/BALANCE.md): secondQueueCoreLevel 10 -> 3, TRANSPORT.capacityPerLink 500 -> 1000 (end game was shipping-limited in bot runs). - Server fixes: POST /reports/:id/share 500 without a pending reportCleanup; bounced link shipments were silent about cargo overflow. Tested: npm test 207/207 (new: bot determinism + invariants, client alerts/world/i18n over CODES, two regression tests that failed before their fix); openapi check up to date. Real-browser scratch runs (not in repo): WebSocket push shows an incoming-attack banner ~214 ms after launch, polling fallback ~52 s, 15 scripted flows, 71 screenshots. NOT tested: Playwright suite (e2e/ still empty), real devices/Safari, nginx proxy websockets, throttled networks, HTTP-level bot load. NOT claimed: balance. Bots are not humans; open balance items (loot waste, escrow refund clipping, no garrisons at landing sites, end game not scaling with world speed) are listed in docs/BALANCE.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
152 lines
8.4 KiB
JavaScript
152 lines
8.4 KiB
JavaScript
'use strict';
|
|
/*
|
|
* Movements: what is on the wire right now. Incoming movements of other operators come first and are deliberately loud
|
|
* (the server hides their type and units: origin and ETA only); your own outgoing legs and returns follow, with live
|
|
* countdowns and a Recall button during the first 90 seconds. Also registers the incoming-warning banner on the POP screen.
|
|
* Data comes from App.mil.moves (milstate.js), which push, the poll and the ticker keep current.
|
|
*/
|
|
(function () {
|
|
const { h, clear, icon, toast } = UI;
|
|
const Mil = UpstreamMil;
|
|
|
|
let box, listEl, visible = false, offTick = null, dirty = true;
|
|
|
|
// ------------------------------------------------------------------ rows
|
|
function incomingRow(m) {
|
|
const from = m.from || {};
|
|
const owner = from.owner;
|
|
return h('li', { class: 'mil-row incoming' },
|
|
h('span', { class: 'row-ic bad' }, icon('alert')),
|
|
h('span', { class: 'row-main' },
|
|
h('span', { class: 'row-title' }, h('b', { text: App.t('mov.incoming.title', { town: (m.to && m.to.name) || '?' }) })),
|
|
h('span', { class: 'row-sub wrap' }, owner ? App.t('mov.incoming.from', { operator: owner.name }) + ' · ' : '', mil().endLink(from)),
|
|
h('span', { class: 'row-sub wrap', text: App.t('mov.incoming.hint') })),
|
|
h('span', { class: 'mil-when' }, mil().countdown(m.arriveAt, { cls: 'big' }), h('small', { text: mil().clockTime(m.arriveAt) })));
|
|
}
|
|
|
|
const mil = () => App.mil;
|
|
|
|
function outgoingRow(m, now) {
|
|
const type = m.type;
|
|
const sub = [];
|
|
if (m.units && Mil.sumUnits(m.units) > 0) sub.push(h('span', { class: 'row-sub wrap', text: mil().unitsText(m.units) }));
|
|
if (m.cargo && Object.keys(m.cargo).some((r) => m.cargo[r] > 0)) sub.push(mil().resChips(m.cargo));
|
|
if (m.target) sub.push(h('span', { class: 'row-sub wrap', text: App.t('mov.target', { name: App.buildingName(m.target) }) }));
|
|
if (m.siteId) sub.push(h('span', { class: 'row-sub wrap', text: App.t('mov.siteShipment') })); // a shipment to a backbone landing site (POST /backbone/:id/ship)
|
|
const recallable = m.recallableUntil && m.recallableUntil > now;
|
|
const bar = h('i');
|
|
const row = h('li', { class: 'mil-row out type-' + type, dataset: { id: m.id } },
|
|
h('span', { class: 'row-ic' }, icon(m.siteId ? 'b-backbone_node' : (Mil.TYPE_ICON[type] || 'move'))),
|
|
h('span', { class: 'row-main' },
|
|
h('span', { class: 'row-title' }, h('b', { text: mil().typeLabel(type) })),
|
|
h('span', { class: 'row-sub wrap' }, mil().endLink(m.from), h('span', { class: 'arrow', 'aria-hidden': 'true' }, icon('move')), mil().endLink(m.to)),
|
|
sub,
|
|
h('span', { class: 'bar mil-bar', 'aria-hidden': 'true' }, bar),
|
|
recallable ? h('button', { class: 'btn small danger mil-recall', type: 'button', dataset: { until: String(m.recallableUntil), id: String(m.id) }, onclick: (ev) => recall(m, ev.currentTarget) },
|
|
icon('return'), h('span', { text: App.t('mov.recall') }), mil().countdown(m.recallableUntil)) : null),
|
|
h('span', { class: 'mil-when' }, mil().countdown(m.arriveAt), h('small', { text: mil().clockTime(m.arriveAt) })));
|
|
row._bar = bar; row._m = m;
|
|
return row;
|
|
}
|
|
|
|
async function recall(m, btn) {
|
|
btn.disabled = true;
|
|
try {
|
|
await App.api.post('/movements/' + m.id + '/recall', {}, { intent: 'recall:' + m.id });
|
|
toast(App.t('mov.recalled'), 'ok');
|
|
} catch (e) {
|
|
toast(App.errMsg(e), 'error');
|
|
}
|
|
App.refreshMovements().catch(() => {});
|
|
App.refreshTown().catch(() => {});
|
|
}
|
|
|
|
// ------------------------------------------------------------------ screen
|
|
function draw() {
|
|
dirty = false;
|
|
clear(listEl);
|
|
const mv = mil().moves, now = App.now();
|
|
const inc = mv.incoming.slice().sort((a, b) => a.arriveAt - b.arriveAt);
|
|
const out = mv.outgoing.slice().sort((a, b) => a.arriveAt - b.arriveAt);
|
|
if (inc.length) {
|
|
listEl.appendChild(h('section', { class: 'card warn-card', role: 'alert' },
|
|
h('div', { class: 'card-head' }, h('h2', null, icon('alert'), App.t('mov.incoming.head', { n: inc.length }))),
|
|
h('ul', { class: 'mil-list' }, inc.map(incomingRow))));
|
|
}
|
|
const allied = (mv.alliedIncoming || []).slice().sort((a, b) => a.arriveAt - b.arriveAt);
|
|
if (allied.length) {
|
|
listEl.appendChild(h('section', { class: 'card' },
|
|
h('div', { class: 'card-head' }, h('h2', null, icon('handshake'), App.t('mov.allied.head'))),
|
|
h('ul', { class: 'mil-list' }, allied.map((m) => h('li', { class: 'mil-row' },
|
|
h('span', { class: 'row-ic' }, icon('shield')),
|
|
h('span', { class: 'row-main' },
|
|
h('span', { class: 'row-title' }, h('b', { text: App.t('mov.allied.title', { operator: m.toOperator ? m.toOperator.name : '?', town: (m.to && m.to.name) || '?' }) })),
|
|
h('span', { class: 'row-sub wrap' }, m.from && m.from.owner ? App.t('mov.incoming.from', { operator: m.from.owner.name }) + ' · ' : '', mil().endLink(m.from))),
|
|
h('span', { class: 'mil-when' }, mil().countdown(m.arriveAt), h('small', { text: mil().clockTime(m.arriveAt) })))))));
|
|
}
|
|
listEl.appendChild(h('section', { class: 'card' },
|
|
h('div', { class: 'card-head' }, h('h2', null, icon('move'), App.t('mov.outgoing.head')), h('span', { class: 'pill', text: String(out.length) })),
|
|
out.length ? h('ul', { class: 'mil-list' }, out.map((m) => outgoingRow(m, now))) : h('p', { class: 'empty', text: mv.loaded ? App.t('mov.empty') : App.t('common.loading') })));
|
|
tick(now);
|
|
}
|
|
|
|
function tick(now) {
|
|
if (!listEl) return;
|
|
for (const row of listEl.querySelectorAll('li.out')) {
|
|
if (!row._m) continue;
|
|
row._bar.style.setProperty('--p', String(mil().progress(row._m, now)));
|
|
}
|
|
for (const b of listEl.querySelectorAll('.mil-recall')) if (Number(b.dataset.until) <= now) b.remove();
|
|
}
|
|
|
|
App.registerScreen({
|
|
id: 'movements', titleKey: 'screen.movements', navKey: 'nav.movements', icon: 'move', hud: false,
|
|
render(container) {
|
|
box = container;
|
|
listEl = h('div', { class: 'mil-sections' });
|
|
box.appendChild(h('div', { class: 'page' },
|
|
h('div', { class: 'card-head page-head' }, h('h1', { text: App.t('screen.movements') }),
|
|
h('div', { class: 'head-actions' },
|
|
h('button', { class: 'btn small primary', type: 'button', onclick: () => App.openSend({}) }, icon('target'), App.t('mov.send')),
|
|
h('button', { class: 'icon-btn', type: 'button', 'aria-label': App.t('common.retry'), onclick: () => App.refreshMovements().catch((e) => toast(App.errMsg(e), 'error')) }, icon('refresh')))),
|
|
listEl));
|
|
App.on('movements', () => { if (visible) draw(); else dirty = true; });
|
|
App.on('lang', () => { if (box) box.querySelector('h1').textContent = App.t('screen.movements'); });
|
|
},
|
|
onShow() {
|
|
visible = true;
|
|
box.querySelector('h1').textContent = App.t('screen.movements');
|
|
draw();
|
|
App.refreshMovements().catch(() => {});
|
|
if (offTick) offTick();
|
|
offTick = App.onTick(tick);
|
|
},
|
|
onHide() { visible = false; if (offTick) offTick(); offTick = null; },
|
|
});
|
|
|
|
// ------------------------------------------------------------------ incoming banner on the POP screen
|
|
function fillBanner(el) {
|
|
clear(el);
|
|
const inc = mil().moves.incoming.slice().sort((a, b) => a.arriveAt - b.arriveAt);
|
|
el.hidden = !inc.length;
|
|
if (!inc.length) return;
|
|
const next = inc[0];
|
|
el.appendChild(h('div', { class: 'row-ic bad' }, icon('alert')));
|
|
el.appendChild(h('div', { class: 'row-main' },
|
|
h('b', { text: App.t('mov.banner.title', { n: inc.length }) }),
|
|
h('span', { class: 'row-sub wrap' }, App.t('mov.banner.next', { town: (next.to && next.to.name) || '?', operator: next.from && next.from.owner ? next.from.owner.name : '?' }) + ' '),
|
|
h('span', { class: 'row-sub wrap' }, App.t('mov.banner.in') + ' ', mil().countdown(next.arriveAt))));
|
|
el.appendChild(h('button', { class: 'btn small', type: 'button', onclick: () => App.go('movements') }, App.t('mov.banner.details')));
|
|
}
|
|
|
|
App.popSections.push({
|
|
slot: 'top',
|
|
render() {
|
|
const el = h('section', { class: 'card warn-card mil-banner', role: 'alert', 'aria-live': 'assertive' });
|
|
fillBanner(el);
|
|
return el;
|
|
},
|
|
});
|
|
App.on('movements', () => { for (const el of document.querySelectorAll('.mil-banner')) fillBanner(el); });
|
|
App.on('lang', () => { for (const el of document.querySelectorAll('.mil-banner')) fillBanner(el); });
|
|
}());
|