File size: 1,507 Bytes
052f728
6b2de60
052f728
5e46a10
 
 
 
b0f6cf1
6b2de60
b0f6cf1
052f728
6b2de60
 
 
 
5e46a10
6b2de60
5e46a10
b0f6cf1
5e46a10
 
b0f6cf1
6b2de60
 
 
 
5e46a10
 
 
 
 
 
 
b0f6cf1
 
5e46a10
 
 
 
 
 
 
b0f6cf1
5e46a10
 
b0f6cf1
5e46a10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Practice mode: no robot, no auth — the on-screen puppet runs programs.
// Also the harness for e2e tests via the window.__reachy hooks.
import "./app/styles.css";
import type * as Blockly from "blockly";
import { bootApp, type App } from "./app/boot";
import type { CommandLog } from "./util/log";
import type { RobotAdapter } from "./robot/adapter";
import type { Runner } from "./interpreter/runner";
import { VirtualRobotAdapter } from "./robot/virtual";
import { makeEmotionSource, makeSoundSource } from "./emotions/sources";

declare global {
  interface Window {
    __reachy?: {
      version: number;
      robot: RobotAdapter;
      log: CommandLog;
      workspace: Blockly.WorkspaceSvg;
      runner: Runner;
      app: App;
      loadProgram(state: object): void;
      setRandom(fn: () => number): void;
    };
  }
}

const params = new URLSearchParams(window.location.search);
const theme = document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";

const app = bootApp(document.getElementById("root")!, {
  theme,
  fresh: params.get("fresh") === "1",
  attachRobot: (puppetHost, log) => new VirtualRobotAdapter(puppetHost, log),
  emotions: makeEmotionSource({ stub: params.get("emotions") === "stub" }),
  sounds: makeSoundSource(),
});

window.__reachy = {
  version: 1,
  robot: app.robot,
  log: app.log,
  workspace: app.workspace,
  runner: app.runner,
  app,
  loadProgram: (state) => app.loadProgram(state),
  setRandom: (fn) => app.setRandom(fn),
};