import Config from "./Config.js"; import Logger from "./utils/Logger.js"; import StarGazer from "./game/StarGazer.js"; import FakeGazeDataProvider from "./gaze/FakeGazeDataProvider.js"; import GazeDataProvider from "./gaze/GazeDataProvider.js"; var canvas = document.querySelector("canvas"), starScreen = document.querySelector("#startScreen"), options = { useMouse: false, // Defauls set in HTML document with checked attribute showDebug: false, // Defauls set in HTML document with checked attribute logToConsole: false, // Defauls set in HTML document with checked attribute }; function init() { loadOptions(); if (options.logToConsole === true) { Logger.enable(); } document.querySelector("#versionInfo").innerHTML = `build ${Config.GAME_VERSION}`; document.querySelector("#startButton").addEventListener("click", prepareGame); } function loadOptions() { options.useMouse = document.querySelector("#useMouseInput").checked; options.showDebug = document.querySelector("#showDebugInfo").checked; options.logToConsole = document.querySelector("#logToConsole").checked; } function prepareGame() { loadOptions(); StarGazer.init({ canvas: canvas, fps: Config.TARGET_FPS, version: `Star Gazer, build ${Config.GAME_VERSION}`, showDebug: options.showDebug, width: Config.SCREEN_WIDTH, height: Config.SCREEN_HEIGHT, gazeDataProvider: getDataProvider(), }); canvas.requestFullscreen().then(startGame); } function startGame() { starScreen.classList.add("hidden"); canvas.classList.remove("hidden"); } function getDataProvider() { let provider; if (options.useMouse === true) { provider = new FakeGazeDataProvider(); } else { provider = new GazeDataProvider(); } provider.start(Config.GAZE_SERVER_URL); return provider; } init();