Phase 2: client military/social screens, WebSocket push, trade + endgame, review findings pending
Built: units/movements/reports/send/expansion screens, alliance/messages/rankings screens, ws client + server /ws push (docs/PROTOCOL.md), Internet exchange trade, backbone endgame + world end, shared reports, buildDone relative levels. Tested: npm test 175/175. Two adversarial reviews found issues (trade-leg recall exploit, __proto__ via validate.js, rankings DoS, static headers, ...): fixes follow in the next commit. NOT done: bots/balance, e2e suite, real-device checks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
249818a7aa
commit
b18645dca1
87 changed files with 10201 additions and 71 deletions
151
public/js/screens/movements.js
Normal file
151
public/js/screens/movements.js
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
'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) }) }));
|
||||
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(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); });
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue