init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// Downlink viewer: hex dump of the ship's transmit buffer, with download.
|
||||
|
||||
import { api } from './api.js';
|
||||
import { h, clear, toast, download } from './dom.js';
|
||||
import { hexView } from './hexview.js';
|
||||
|
||||
export function downlinkView(ctx) {
|
||||
const ship = ctx.ship;
|
||||
const body = h('div', { class: 'panel-body' }, h('p', { class: 'dim' }, ship ? 'ACQUIRING SIGNAL...' : 'YOU HAVE NO SHIP.'));
|
||||
const meta = h('span', { class: 'dim' });
|
||||
const dl = h('button', { class: 'btn', type: 'button', disabled: true }, 'DOWNLOAD .BIN');
|
||||
const refresh = h('button', { class: 'btn', type: 'button', disabled: !ship }, 'REFRESH');
|
||||
|
||||
let current = null;
|
||||
async function fetchIt() {
|
||||
if (!ship) return;
|
||||
refresh.disabled = true;
|
||||
try {
|
||||
const { bytes, day } = await api.downlink(ship.id);
|
||||
current = { bytes, day };
|
||||
const allZero = bytes.every((b) => b === 0);
|
||||
meta.textContent = `SHIP #${ship.id} // FROM THE RUN OF DAY ${day} // ${bytes.length} BYTES`;
|
||||
dl.disabled = false;
|
||||
clear(body).append(
|
||||
...(allZero ? [h('p', { class: 'warn' }, 'BUFFER IS ALL ZEROS: THE SHIP HAS NOT WRITTEN ANYTHING TO ITS DOWNLINK BUFFER.')] : []),
|
||||
hexView(bytes).el,
|
||||
h('p', { class: 'hint' }, 'OFFSETS ARE INTO THE 1 KB DOWNLINK BUFFER (SHIP RAM 1024-2047). MULTI-BYTE VALUES ARE LITTLE-ENDIAN.'),
|
||||
);
|
||||
} catch (e) {
|
||||
current = null;
|
||||
dl.disabled = true;
|
||||
meta.textContent = '';
|
||||
clear(body).append(
|
||||
e.status === 404
|
||||
? h('div', { class: 'nosignal' },
|
||||
h('p', { class: 'big' }, 'NO SIGNAL'),
|
||||
h('p', { class: 'dim' }, 'THIS SHIP HAS NOT TRANSMITTED YET. A SHIP\'S FIRST DOWNLINK ARRIVES AFTER ITS FIRST DAY IN THE BELT.'))
|
||||
: h('p', { class: 'bad' }, `ERROR: ${e.message}`),
|
||||
);
|
||||
} finally {
|
||||
refresh.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Reloading the account too keeps the ship's status and the day current.
|
||||
refresh.addEventListener('click', () => ctx.refresh().catch((e) => toast(e.message, 'err')));
|
||||
dl.addEventListener('click', () => {
|
||||
if (!current) return;
|
||||
download(`ship-${ship.id}-day-${current.day}-downlink.bin`, current.bytes);
|
||||
toast(`SAVED ${current.bytes.length} BYTES`);
|
||||
});
|
||||
fetchIt();
|
||||
|
||||
return h('section', { class: 'panel' },
|
||||
h('div', { class: 'panel-title' }, 'DOWNLINK RECEIVER', h('span', { class: 'spacer' }), meta),
|
||||
h('div', { class: 'toolbar pad' }, refresh, h('span', { class: 'spacer' }), dl),
|
||||
body,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user