jevstrudel.git / website / src / jev / jev.mjs
jev.mjsannotatedjev.mjssource25 lines · 1.3 KB · raw
1// What songs see: `jev`, the SDK's question builders `choice`, `score`
2// and `noul`, and `walk` (a form's rules, in code), in the REPL's scope (repl/util.mjs evaluates every export of
3// this module into it, so export nothing else). The API is in jevCore.mjs;
4// here it is wired to the site's relay (ask.mjs) and to every listener's
5// reactions (reactions.mjs).
6import { askJev } from './ask.mjs';
7import { nowPlaying } from './client.mjs';
8import { tallyFor } from './reactions.mjs';
9import { hear } from './meter.mjs';
10import { choice, createJev, noul, score, walk } from './jevCore.mjs';
11
12// How long until cycle `begins`, from the playing scheduler (null when the
13// song is not playing, as before its opening): the relay logs it per call.
14const secondsUntil = (begins) => {
15  const scheduler = globalThis.strudelMirror?.repl?.scheduler;
16  if (!scheduler?.started || !(scheduler.cps > 0) || typeof begins !== 'number') return null;
17  return (begins - scheduler.now()) / scheduler.cps;
18};
19
20export const jev = createJev(
21  (state, questions, { begins } = {}) => askJev(questions, state, { secondsToSection: () => secondsUntil(begins) }),
22  // every listener's reactions to the playing song (reactions.mjs)
23  { hear, listeners: () => tallyFor(nowPlaying.get()) },
24);
25export { choice, noul, score, walk };