index.js 1.67 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
    document.querySelector("#startButton").addEventListener("click", prepareGame);
Alexander Bazo committed
18 19
}

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

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

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

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

init();