big style update + new log system
This commit is contained in:
parent
3e6c3fda60
commit
45c7b29a96
13 changed files with 1059 additions and 894 deletions
|
|
@ -13,9 +13,10 @@ export class Cyclist {
|
|||
cps = 1; // TODO
|
||||
getTime;
|
||||
phase = 0;
|
||||
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
||||
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1, onLog }) {
|
||||
this.getTime = getTime;
|
||||
this.onToggle = onToggle;
|
||||
this.onLog = onLog;
|
||||
this.latency = latency;
|
||||
const round = (x) => Math.round(x * 1000) / 1000;
|
||||
this.clock = createClock(
|
||||
|
|
@ -56,14 +57,17 @@ export class Cyclist {
|
|||
if (!this.pattern) {
|
||||
throw new Error('Scheduler: no pattern set! call .setPattern first.');
|
||||
}
|
||||
this.onLog?.('start');
|
||||
this.clock.start();
|
||||
this.setStarted(true);
|
||||
}
|
||||
pause() {
|
||||
this.onLog?.('pause');
|
||||
this.clock.pause();
|
||||
this.setStarted(false);
|
||||
}
|
||||
stop() {
|
||||
this.onLog?.('stop');
|
||||
this.clock.stop();
|
||||
this.setStarted(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export function repl({
|
|||
getTime,
|
||||
transpiler,
|
||||
onToggle,
|
||||
onLog,
|
||||
}) {
|
||||
const scheduler = new Cyclist({
|
||||
interval,
|
||||
|
|
@ -25,6 +26,7 @@ export function repl({
|
|||
onError: onSchedulerError,
|
||||
getTime,
|
||||
onToggle,
|
||||
onLog: (message) => onLog?.(`[clock] ${message}`),
|
||||
});
|
||||
const evaluate = async (code, autostart = true) => {
|
||||
if (!code) {
|
||||
|
|
@ -33,11 +35,13 @@ export function repl({
|
|||
try {
|
||||
beforeEval({ code });
|
||||
const { pattern } = await _evaluate(code, transpiler);
|
||||
onLog?.(`[eval] code updated`);
|
||||
scheduler.setPattern(pattern, autostart);
|
||||
afterEval({ code, pattern });
|
||||
return pattern;
|
||||
} catch (err) {
|
||||
console.warn(`eval error: ${err.message}`);
|
||||
// console.warn(`[repl] eval error: ${err.message}`);
|
||||
onLog?.(`[eval] error: ${err.message}`, 'error');
|
||||
onEvalError?.(err);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue