partey_workadventure/front/src/index.ts

65 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-04-03 14:56:21 +02:00
import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig;
2020-08-31 12:18:00 +02:00
import {DEBUG_MODE, JITSI_URL, RESOLUTION} from "./Enum/EnvironmentVariable";
2020-04-14 20:04:55 +02:00
import {cypressAsserter} from "./Cypress/CypressAsserter";
import {LoginScene} from "./Phaser/Login/LoginScene";
import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
import {SelectCharacterScene} from "./Phaser/Login/SelectCharacterScene";
2020-06-23 12:24:36 +02:00
import {EnableCameraScene} from "./Phaser/Login/EnableCameraScene";
import {FourOFourScene} from "./Phaser/Reconnecting/FourOFourScene";
import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer;
import {OutlinePipeline} from "./Phaser/Shaders/OutlinePipeline";
2020-07-28 11:06:08 +02:00
import {CustomizeScene} from "./Phaser/Login/CustomizeScene";
import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager";
2020-09-17 18:08:20 +02:00
import {redirectIfToken} from "./register";
//CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com');
2020-09-18 16:29:53 +02:00
let connectionData //todo: do something with this data
redirectIfToken().then(res => connectionData = res);
2020-08-31 12:18:00 +02:00
// Load Jitsi if the environment variable is set.
if (JITSI_URL) {
const jitsiScript = document.createElement('script');
jitsiScript.src = 'https://' + JITSI_URL + '/external_api.js';
document.head.appendChild(jitsiScript);
}
const {width, height} = CoWebsiteManager.getGameSize();
2020-04-07 20:41:35 +02:00
2020-04-03 14:56:21 +02:00
const config: GameConfig = {
title: "WorkAdventure",
width: width / RESOLUTION,
height: height / RESOLUTION,
2020-04-03 14:56:21 +02:00
parent: "game",
2020-07-28 15:53:44 +02:00
scene: [LoginScene, SelectCharacterScene, EnableCameraScene, ReconnectingScene, FourOFourScene, CustomizeScene],
zoom: RESOLUTION,
2020-04-11 18:17:36 +02:00
physics: {
default: "arcade",
arcade: {
2020-04-13 19:40:10 +02:00
debug: DEBUG_MODE
}
},
callbacks: {
postBoot: game => {
// FIXME: we should fore WebGL in the config.
2020-07-23 18:47:28 +02:00
const renderer = game.renderer as WebGLRenderer;
renderer.addPipeline(OutlinePipeline.KEY, new OutlinePipeline(game));
}
}
2020-04-03 14:56:21 +02:00
};
2020-04-14 20:04:55 +02:00
cypressAsserter.gameStarted();
2020-06-09 23:13:26 +02:00
const game = new Phaser.Game(config);
window.addEventListener('resize', function (event) {
const {width, height} = CoWebsiteManager.getGameSize();
game.scale.resize(width / RESOLUTION, height / RESOLUTION);
});
CoWebsiteManager.onStateChange(() => {
const {width, height} = CoWebsiteManager.getGameSize();
game.scale.resize(width / RESOLUTION, height / RESOLUTION);
2020-05-13 16:17:58 +02:00
});