index.js 1.57 KB
Newer Older
1
import GameConfig from "./config/GameConfiguration.js";
Alexander Bazo committed
2 3
import Logger from "./utils/Logger.js";
import StarGazer from "./game/StarGazer.js";
4 5
import FakeGazeDataProvider from "./gaze/FakeGazeDataProvider.js";
import GazeDataProvider from "./gaze/GazeDataProvider.js";
Alexander Bazo committed
6

7
var canvas = document.querySelector("canvas"),
8
  starScreen = document.querySelector("#startScreen");
Alexander Bazo committed
9

Alexander Bazo committed
10
function init() {
11
  loadOptions();
12
  if (GameConfig.getShowVerboseDebugInfoInConsole() === true) {
13 14
    Logger.enable();
  }
15 16
  document.querySelector("#versionInfo").innerHTML =
    `build ${GameConfig.getVersion()}`;
17 18
  document.querySelector("#startButton").addEventListener("click",
    prepareGame);
Alexander Bazo committed
19 20
}

21
function loadOptions() {
22 23 24 25 26 27
  let useMouse = document.querySelector("#useMouseInput").checked,
    showDebug = document.querySelector("#showDebugInfo").checked,
    logToConsole = document.querySelector("#logToConsole").checked;
  GameConfig.setUseMouseInput(useMouse);
  GameConfig.setShowDebugInfoOnScreen(showDebug);
  GameConfig.setShowVerboseDebugInfoInConsole(logToConsole);
28 29
}

30
function prepareGame() {
31
  loadOptions();
Alexander Bazo committed
32
  StarGazer.init({
33
    canvas: canvas,
34
    gazeDataProvider: getDataProvider(),
Alexander Bazo committed
35
  });
36
  canvas.requestFullscreen().then(startGame);
Alexander Bazo committed
37 38
}

39
function startGame() {
40 41
  starScreen.classList.add("hidden");
  canvas.classList.remove("hidden");
Alexander Bazo committed
42 43
}

44 45
function getDataProvider() {
  let provider;
46
  if (GameConfig.getUseMouseInput() === true) {
47 48 49 50
    provider = new FakeGazeDataProvider();
  } else {
    provider = new GazeDataProvider();
  }
51
  provider.start(GameConfig.getGazeServerURL());
52
  return provider;
Alexander Bazo committed
53 54 55
}

init();