@moonbase-machines/c64 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser.js CHANGED
@@ -4,7 +4,9 @@
4
4
  // frame painted on a canvas doubled; and the machine run 50 frames a second, keeping up with the
5
5
  // clock, two frames at most at a time.
6
6
  //
7
- // const keys = keyboard(m, { ignore, onKey, log }) ignore(e): a key the page keeps (a pane's)
7
+ // const keys = keyboard(m, { ignore, onKey, log, listen }) ignore(e): a key the page keeps (a pane's); listen(type,
8
+ // f), where its keys come from (the window's, unless a player gives
9
+ // its own)
8
10
  // keys.press(column, row, frames) a key held for so many frames (RUN/STOP)
9
11
  // const draw = painter(canvas) draw(m.vic.frame)
10
12
  // pace(m, after) the frames run; after() each animation frame
@@ -13,7 +15,7 @@ import { PALETTE, WIDTH, HEIGHT } from './vic.js';
13
15
 
14
16
  const PAD_DEAD = 0.4; // a stick pushed less far than this is at rest (the dead zone)
15
17
 
16
- export function keyboard(m, { ignore = () => false, onKey = () => {}, log = false } = {}) {
18
+ export function keyboard(m, { ignore = () => false, onKey = () => {}, log = false, listen = (type, f) => window.addEventListener(type, f) } = {}) {
17
19
  // (a letter by the key it is, not the character the browser makes of it: in the C64's first
18
20
  // character set, capitals and graphics, a letter is a letter, Shift or Caps Lock or not, and
19
21
  // Option with it is its graphic, the C64's shifted letter; in the second, small letters and
@@ -29,7 +31,7 @@ export function keyboard(m, { ignore = () => false, onKey = () => {}, log = fals
29
31
  if (since >= 2) { m.key(key[0], key[1], false); if (shift) m.key(1, 7, false); return; }
30
32
  held.push([key[0], key[1], 2 - since]); if (shift) held.push([1, 7, 2 - since]);
31
33
  };
32
- window.addEventListener('keydown', e => {
34
+ listen('keydown', e => {
33
35
  if (ignore(e)) return;
34
36
  onKey(e);
35
37
  if (e.metaKey || e.repeat) return;
@@ -49,7 +51,7 @@ export function keyboard(m, { ignore = () => false, onKey = () => {}, log = fals
49
51
  if (log) console.log('key', JSON.stringify(e.key), '-> column', key[0], 'row', key[1]);
50
52
  e.preventDefault();
51
53
  });
52
- window.addEventListener('keyup', e => {
54
+ listen('keyup', e => {
53
55
  if (MODIFIERS[e.key]) m.key(...MODIFIERS[e.key], false);
54
56
  if (JOYSTICK[e.key]) { m.joystick &= ~JOYSTICK[e.key]; const cur = CURSOR[e.key]; if (cur) { m.key(cur[0], cur[1], false); if (cur[2]) m.key(1, 7, false); } return; }
55
57
  const key = down.get(e.code);