2020-04-03 14:56:21 +02:00
|
|
|
import 'phaser';
|
|
|
|
import GameConfig = Phaser.Types.Core.GameConfig;
|
2021-03-18 12:37:05 +01:00
|
|
|
import "../dist/resources/style/index.scss";
|
|
|
|
|
2021-04-14 17:47:26 +02:00
|
|
|
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
|
2020-05-24 23:14:12 +02:00
|
|
|
import {LoginScene} from "./Phaser/Login/LoginScene";
|
2020-05-23 15:43:26 +02:00
|
|
|
import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
|
2020-05-25 23:26:27 +02:00
|
|
|
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";
|
2020-10-07 18:03:34 +02:00
|
|
|
import {ResizableScene} from "./Phaser/Login/ResizableScene";
|
2020-10-12 18:59:49 +02:00
|
|
|
import {EntryScene} from "./Phaser/Login/EntryScene";
|
2020-10-27 16:59:12 +01:00
|
|
|
import {coWebsiteManager} from "./WebRtc/CoWebsiteManager";
|
2020-12-04 11:30:35 +01:00
|
|
|
import {MenuScene} from "./Phaser/Menu/MenuScene";
|
2021-03-19 15:40:07 +01:00
|
|
|
import {HelpCameraSettingsScene} from "./Phaser/Menu/HelpCameraSettingsScene";
|
2020-12-04 11:30:35 +01:00
|
|
|
import {localUserStore} from "./Connexion/LocalUserStore";
|
2021-01-17 20:34:35 +01:00
|
|
|
import {ErrorScene} from "./Phaser/Reconnecting/ErrorScene";
|
2021-03-04 19:00:00 +01:00
|
|
|
import {iframeListener} from "./Api/IframeListener";
|
2021-05-04 11:29:37 +02:00
|
|
|
import {HdpiManager} from "./Phaser/Services/HdpiManager";
|
|
|
|
import {waScaleManager} from "./Phaser/Services/WaScaleManager";
|
2020-08-13 18:21:48 +02:00
|
|
|
|
2020-10-27 16:59:12 +01:00
|
|
|
const {width, height} = coWebsiteManager.getGameSize();
|
2020-04-07 20:41:35 +02:00
|
|
|
|
2020-12-04 11:30:35 +01: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.
|
|
|
|
*/
|
2020-11-27 16:24:07 +01:00
|
|
|
min: valueGameQuality,
|
2020-11-25 01:19:19 +01:00
|
|
|
/**
|
|
|
|
* The optimum rendering rate, in frames per second.
|
|
|
|
*/
|
2020-11-27 16:24:07 +01:00
|
|
|
target: valueGameQuality,
|
2020-11-25 01:19:19 +01:00
|
|
|
/**
|
|
|
|
* Use setTimeout instead of requestAnimationFrame to run the game loop.
|
|
|
|
*/
|
2021-04-19 20:19:40 +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
|
|
|
|
}
|
2020-11-27 16:24:07 +01:00
|
|
|
|
2021-01-25 11:18:48 +01:00
|
|
|
// 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");
|
2021-01-25 11:18:48 +01:00
|
|
|
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"');
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:08:40 +02:00
|
|
|
const hdpiManager = new HdpiManager(640*480, 196*196);
|
2021-05-04 11:29:37 +02:00
|
|
|
const { game: gameSize, real: realSize } = hdpiManager.getOptimalGameSize({width, height});
|
2021-01-25 11:18:48 +01:00
|
|
|
|
2020-04-03 14:56:21 +02:00
|
|
|
const config: GameConfig = {
|
2021-01-25 11:18:48 +01:00
|
|
|
type: mode,
|
2020-08-11 22:32:55 +02:00
|
|
|
title: "WorkAdventure",
|
2021-05-04 11:29:37 +02:00
|
|
|
scale: {
|
|
|
|
parent: "game",
|
|
|
|
width: gameSize.width,
|
|
|
|
height: gameSize.height,
|
|
|
|
zoom: realSize.width / gameSize.width,
|
|
|
|
autoRound: true,
|
|
|
|
resizeInterval: 999999999999
|
|
|
|
},
|
2021-04-02 23:00:51 +02:00
|
|
|
scene: [EntryScene, LoginScene, SelectCharacterScene, SelectCompanionScene, EnableCameraScene, ReconnectingScene, ErrorScene, CustomizeScene, MenuScene, HelpCameraSettingsScene],
|
2021-05-04 11:29:37 +02:00
|
|
|
//resolution: window.devicePixelRatio / 2,
|
2020-11-25 01:19:19 +01:00
|
|
|
fps: fps,
|
2020-12-04 11:30:35 +01:00
|
|
|
dom: {
|
|
|
|
createContainer: true
|
|
|
|
},
|
2021-02-02 12:04:50 +01:00
|
|
|
render: {
|
|
|
|
pixelArt: true,
|
|
|
|
roundPixels: true,
|
|
|
|
antialias: false
|
|
|
|
},
|
2020-04-11 18:17:36 +02:00
|
|
|
physics: {
|
2020-04-12 16:12:08 +02:00
|
|
|
default: "arcade",
|
|
|
|
arcade: {
|
2020-11-25 00:47:21 +01:00
|
|
|
debug: DEBUG_MODE,
|
2020-04-12 16:12:08 +02:00
|
|
|
}
|
2020-07-15 23:44:01 +02:00
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
postBoot: game => {
|
2021-01-27 11:18:07 +01:00
|
|
|
// Commented out to try to fix MacOS bug
|
|
|
|
/*const renderer = game.renderer;
|
2021-01-13 18:39:28 +01:00
|
|
|
if (renderer instanceof WebGLRenderer) {
|
|
|
|
renderer.pipelines.add(OutlinePipeline.KEY, new OutlinePipeline(game));
|
2021-01-27 11:18:07 +01:00
|
|
|
}*/
|
2020-07-15 23:44:01 +02:00
|
|
|
}
|
2020-04-12 16:12:08 +02:00
|
|
|
}
|
2020-04-03 14:56:21 +02:00
|
|
|
};
|
|
|
|
|
2020-06-09 23:13:26 +02:00
|
|
|
const game = new Phaser.Game(config);
|
2020-04-03 18:41:06 +02:00
|
|
|
|
2021-05-04 11:29:37 +02:00
|
|
|
waScaleManager.setScaleManager(game.scale);
|
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
window.addEventListener('resize', function (event) {
|
2021-03-18 15:05:15 +01:00
|
|
|
coWebsiteManager.resetStyle();
|
2021-05-04 11:29:37 +02:00
|
|
|
|
|
|
|
waScaleManager.applyNewSize();
|
2020-10-07 18:03:34 +02:00
|
|
|
|
|
|
|
// Let's trigger the onResize method of any active scene that is a ResizableScene
|
|
|
|
for (const scene of game.scene.getScenes(true)) {
|
|
|
|
if (scene instanceof ResizableScene) {
|
|
|
|
scene.onResize(event);
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 18:21:48 +02:00
|
|
|
});
|
2020-11-27 16:24:07 +01:00
|
|
|
|
2021-03-18 15:05:15 +01:00
|
|
|
coWebsiteManager.onResize.subscribe(() => {
|
2021-05-04 11:29:37 +02:00
|
|
|
waScaleManager.applyNewSize();
|
2020-05-13 16:17:58 +02:00
|
|
|
});
|
2021-03-04 19:00:00 +01:00
|
|
|
|
|
|
|
iframeListener.init();
|