import Logger from "../utils/Logger.js"; import NetClient from "../com/NetClient.js"; import GameManager from "./GameManager.js"; var stage, client, provider; function init(options) { Logger.log("Starting StarGazer game", "Game"); initGazeProvider(options); initStage(options); initConnection(options); } function initGazeProvider(options) { provider = options.gazeDataProvider; provider.addEventListener("dataavailable", onGazeUpdate); } function initStage(options) { stage = options.canvas; GameManager.init(stage); } function initConnection(options) { client = new NetClient(); client.addEventListener("connect", onConnect); client.addEventListener("stateupdate", onStateUpdate) client.connect(options.gameServerURL); client.joinGame(); } function onConnect(event) { Logger.log("Connected to game server", "Game"); GameManager.start(event.ownID); } function onStateUpdate(event) { GameManager.syncState(event.state); } function onGazeUpdate(event) { let gazePoint = event.data; gazePoint.linkTo(stage); if (gazePoint.hasLink) { client.sendGazeData(gazePoint); //GameManager.addGazePoint(gazePoint); } } export default { init: init, };