New node type 13: bounded field drawing the mounted CSTR with a blinking caret when focused (click to focus). Typed input flows through the new optional KryBackend.text_key (codepoints, 0x08 backspace): kry_sw queues via KrySwText (drained per frame by Advance), the raylib surface backend maps GetCharPressed, SDL maps SDL_TEXTINPUT/BACKSPACE, krb-web exports krb_web_text from keypress events. UTF-8 runes append and strip correctly. k2b compiles TextField(x,y,w,h,&state.field). Verified: click-focus, typing with backspace, and that unfocused fields ignore keys.
105 lines
3.5 KiB
HTML
105 lines
3.5 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>krb player</title>
|
|
<style>
|
|
html, body { margin: 0; height: 100%; background: #101014; color: #f0f0f2;
|
|
font: 14px system-ui, sans-serif; display: flex;
|
|
flex-direction: column; align-items: center;
|
|
justify-content: center; gap: 12px; }
|
|
canvas { image-rendering: pixelated; max-width: 96vw; max-height: 80vh; }
|
|
#drop { border: 1px dashed #8a8a93; border-radius: 8px; padding: 14px 22px;
|
|
cursor: pointer; }
|
|
#drop.hot { border-color: #f0f0f2; background: #1c1c22; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="drop">drop a .krb cartridge here, or click to pick one</div>
|
|
<input id="file" type="file" accept=".krb" hidden>
|
|
<canvas id="krb" width="800" height="600"></canvas>
|
|
<script>
|
|
var Module = {
|
|
canvas: document.getElementById('krb')
|
|
};
|
|
(function() {
|
|
const canvas = Module.canvas;
|
|
const drop = document.getElementById('drop');
|
|
const input = document.getElementById('file');
|
|
|
|
function start(file) {
|
|
file.arrayBuffer().then(function(buf) {
|
|
Module.FS.writeFile('/app.krb', new Uint8Array(buf));
|
|
drop.textContent = file.name + ' — drop another .krb to switch';
|
|
Module._krb_web_start();
|
|
});
|
|
}
|
|
drop.addEventListener('click', function() { input.click(); });
|
|
input.addEventListener('change', function() {
|
|
if (input.files.length > 0)
|
|
start(input.files[0]);
|
|
});
|
|
['dragover', 'dragenter'].forEach(function(ev) {
|
|
drop.addEventListener(ev, function(e) {
|
|
e.preventDefault();
|
|
drop.classList.add('hot');
|
|
});
|
|
});
|
|
['dragleave', 'drop'].forEach(function(ev) {
|
|
drop.addEventListener(ev, function(e) {
|
|
e.preventDefault();
|
|
drop.classList.remove('hot');
|
|
});
|
|
});
|
|
drop.addEventListener('drop', function(e) {
|
|
e.preventDefault();
|
|
if (e.dataTransfer.files.length > 0)
|
|
start(e.dataTransfer.files[0]);
|
|
});
|
|
function pos(e) {
|
|
const r = canvas.getBoundingClientRect();
|
|
return [Math.round((e.clientX - r.left) * canvas.width / r.width),
|
|
Math.round((e.clientY - r.top) * canvas.height / r.height)];
|
|
}
|
|
window.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Backspace' && Module._krb_web_text) {
|
|
e.preventDefault();
|
|
Module._krb_web_text(8);
|
|
}
|
|
});
|
|
window.addEventListener('keypress', function(e) {
|
|
if (Module._krb_web_text && e.charCode > 31)
|
|
Module._krb_web_text(e.charCode);
|
|
});
|
|
canvas.addEventListener('wheel', function(e) {
|
|
e.preventDefault();
|
|
if (Module._krb_web_wheel)
|
|
Module._krb_web_wheel(Math.round(-e.deltaY / 2));
|
|
}, { passive: false });
|
|
canvas.addEventListener('mousemove', function(e) {
|
|
if (Module._krb_web_mouse) {
|
|
const p = pos(e);
|
|
Module._krb_web_mouse(p[0], p[1]);
|
|
}
|
|
});
|
|
canvas.addEventListener('mousedown', function(e) {
|
|
if (Module._krb_web_button) {
|
|
const p = pos(e);
|
|
Module._krb_web_mouse(p[0], p[1]);
|
|
Module._krb_web_button(0, 1);
|
|
}
|
|
});
|
|
canvas.addEventListener('mouseup', function(e) {
|
|
if (Module._krb_web_button) {
|
|
const p = pos(e);
|
|
Module._krb_web_mouse(p[0], p[1]);
|
|
Module._krb_web_button(0, 0);
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
{{{ SCRIPT }}}
|
|
</body>
|
|
</html>
|