Upstream/public/js/screens/cargo-ui.js
jvanvik 931f59e11e Phase 3: trade/end-game client, bot simulator, first balance pass
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
2026-10-11 20:24:41 +02:00

40 lines
2.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/*
* Cargo pickers shared by the trade and end game screens (window.CargoUI): one slider + stepper + number box per resource.
* The server decides everything (capacity per link, stock, links); this only keeps the numbers inside what the POP holds.
*/
(function () {
const { h } = UI;
const D = UpstreamData;
const num = (n) => App.fmt.num(n);
// One row: label, "/ have", slider, -/+ buttons, number box, "all". onChange(v) gets the clamped integer.
function pickRow(label, have, cur, onChange, sub) {
have = Math.max(0, Math.floor(have));
const range = h('input', { type: 'range', min: '0', max: String(have), step: '1', value: String(cur), 'aria-label': label });
const numIn = h('input', { type: 'number', inputmode: 'numeric', min: '0', max: String(have), value: String(cur), class: 'mil-num', 'aria-label': label });
const set = (v) => { v = Math.max(0, Math.min(have, Math.floor(Number(v)) || 0)); range.value = String(v); numIn.value = String(v); onChange(v); };
range.addEventListener('input', () => set(range.value));
numIn.addEventListener('input', () => set(numIn.value));
return h('div', { class: 'mil-pick' },
h('div', { class: 'row' }, h('span', null, h('b', { text: label }), h('span', { class: 'dimmer', text: ' / ' + num(have) })), sub || null),
h('div', { class: 'pick-ctl' },
h('button', { class: 'btn small', type: 'button', 'aria-label': '-1', onclick: () => set(Number(numIn.value) - 1) }, '−'),
range,
h('button', { class: 'btn small', type: 'button', 'aria-label': '+1', onclick: () => set(Number(numIn.value) + 1) }, '+'),
numIn,
h('button', { class: 'btn small', type: 'button', onclick: () => set(have) }, App.t('send.all'))));
}
// Pickers for fiber / hardware / capital writing into `cargo` ({res: n}, zero entries removed). have = { fiber, hardware, capital }.
function cargoPickers(cargo, have, onChange) {
return D.RESOURCES.map((r) => pickRow(App.resName(r), Math.floor(have[r] || 0), cargo[r] || 0, (v) => {
if (v > 0) cargo[r] = v; else delete cargo[r];
if (onChange) onChange();
}));
}
const cargoTotal = (cargo) => Object.keys(cargo).reduce((s, k) => s + (cargo[k] || 0), 0);
window.CargoUI = { pickRow, cargoPickers, cargoTotal };
}());