partey_workadventure/front/src/index.ts

159 lines
4.6 KiB
TypeScript
Raw Normal View History

2020-04-03 14:56:21 +02:00
import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig;
import "../style/index.scss";
import {DEBUG_MODE, isMobile} from "./Enum/EnvironmentVariable";
import {LoginScene} from "./Phaser/Login/LoginScene";
import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
import {SelectCharacterScene} from "./Phaser/Login/SelectCharacterScene";
2021-04-02 23:00:51 +02:00
import {SelectCompanionScene} from "./Phaser/Login/SelectCompanionScene";
2020-06-23 12:24:36 +02:00
import {EnableCameraScene} from "./Phaser/Login/EnableCameraScene";
2020-07-28 11:06:08 +02:00
import {CustomizeScene} from "./Phaser/Login/CustomizeScene";
2021-05-26 20:31:33 +02:00
import WebFontLoaderPlugin from 'phaser3-rex-plugins/plugins/webfontloader-plugin.js';
import {EntryScene} from "./Phaser/Login/EntryScene";
import {coWebsiteManager} from "./WebRtc/CoWebsiteManager";
import {MenuScene} from "./Phaser/Menu/MenuScene";
import {localUserStore} from "./Connexion/LocalUserStore";
import {ErrorScene} from "./Phaser/Reconnecting/ErrorScene";
import {iframeListener} from "./Api/IframeListener";
import {HdpiManager} from "./Phaser/Services/HdpiManager";
import {waScaleManager} from "./Phaser/Services/WaScaleManager";
import {Game} from "./Phaser/Game/Game";
2021-05-11 17:37:21 +02:00
import App from './Components/App.svelte';
import {HtmlUtils} from "./WebRtc/HtmlUtils";
const {width, height} = coWebsiteManager.getGameSize();
2020-04-07 20:41:35 +02:00
const valueGameQuality = localUserStore.getGameQualityValue();
2020-11-25 01:19:19 +01:00
const fps : Phaser.Types.Core.FPSConfig = {
/**
* The minimum acceptable rendering rate, in frames per second.
*/
min: valueGameQuality,
2020-11-25 01:19:19 +01:00
/**
* The optimum rendering rate, in frames per second.
*/
target: valueGameQuality,
2020-11-25 01:19:19 +01:00
/**
* Use setTimeout instead of requestAnimationFrame to run the game loop.
*/
2021-04-21 10:37:20 +02:00
forceSetTimeOut: false,
2020-11-25 01:19:19 +01:00
/**
* Calculate the average frame delta from this many consecutive frame intervals.
*/
deltaHistory: 120,
/**
* The amount of frames the time step counts before we trust the delta values again.
*/
panicMax: 20,
/**
* Apply delta smoothing during the game update to help avoid spikes?
*/
smoothStep: false
}
// the ?phaserMode=canvas parameter can be used to force Canvas usage
2021-01-25 12:02:00 +01:00
const params = new URLSearchParams(document.location.search.substring(1));
const phaserMode = params.get("phaserMode");
let mode: number;
switch (phaserMode) {
case 'auto':
case null:
mode = Phaser.AUTO;
break;
case 'canvas':
mode = Phaser.CANVAS;
break;
case 'webgl':
mode = Phaser.WEBGL;
break;
default:
throw new Error('phaserMode parameter must be one of "auto", "canvas" or "webgl"');
}
const hdpiManager = new HdpiManager(640*480, 196*196);
const { game: gameSize, real: realSize } = hdpiManager.getOptimalGameSize({width, height});
2020-04-03 14:56:21 +02:00
const config: GameConfig = {
type: mode,
title: "WorkAdventure",
scale: {
parent: "game",
width: gameSize.width,
height: gameSize.height,
zoom: realSize.width / gameSize.width,
autoRound: true,
resizeInterval: 999999999999
},
scene: [EntryScene,
LoginScene,
2021-05-26 18:46:25 +02:00
SelectCharacterScene,
SelectCompanionScene,
EnableCameraScene,
ReconnectingScene,
ErrorScene,
CustomizeScene,
MenuScene,
],
//resolution: window.devicePixelRatio / 2,
2020-11-25 01:19:19 +01:00
fps: fps,
dom: {
createContainer: true
},
render: {
pixelArt: true,
roundPixels: true,
antialias: false
2021-05-26 20:31:33 +02:00
},
plugins: {
global: [{
key: 'rexWebFontLoader',
plugin: WebFontLoaderPlugin,
start: true
}]
},
2020-04-11 18:17:36 +02:00
physics: {
default: "arcade",
arcade: {
debug: DEBUG_MODE,
}
},
// Instruct systems with 2 GPU to choose the low power one. We don't need that extra power and we want to save battery
powerPreference: "low-power",
callbacks: {
postBoot: game => {
// Commented out to try to fix MacOS bug
/*const renderer = game.renderer;
if (renderer instanceof WebGLRenderer) {
renderer.pipelines.add(OutlinePipeline.KEY, new OutlinePipeline(game));
}*/
}
}
2020-04-03 14:56:21 +02:00
};
//const game = new Phaser.Game(config);
const game = new Game(config);
waScaleManager.setGame(game);
window.addEventListener('resize', function (event) {
coWebsiteManager.resetStyle();
waScaleManager.applyNewSize();
});
coWebsiteManager.onResize.subscribe(() => {
waScaleManager.applyNewSize();
2020-05-13 16:17:58 +02:00
});
iframeListener.init();
2021-05-11 17:37:21 +02:00
const app = new App({
target: HtmlUtils.getElementByIdOrFail('svelte-overlay'),
2021-05-31 12:06:11 +02:00
props: {
game: game
},
2021-05-11 17:37:21 +02:00
})
export default app