merge from develop

This commit is contained in:
arp 2020-10-09 17:10:24 +02:00
commit f550c5a775
14 changed files with 93 additions and 51 deletions

View File

@ -1,5 +1,5 @@
import {URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..." import {URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
import { uuid } from 'uuidv4'; import { v4 } from 'uuid';
import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js"; import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js";
import {BaseController} from "./BaseController"; import {BaseController} from "./BaseController";
import {adminApi, AdminApiData} from "../Services/AdminApi"; import {adminApi, AdminApiData} from "../Services/AdminApi";
@ -50,11 +50,11 @@ export class AuthenticateController extends BaseController {
mapUrlStart = data.mapUrlStart; mapUrlStart = data.mapUrlStart;
newUrl = this.getNewUrlOnAdminAuth(data) newUrl = this.getNewUrlOnAdminAuth(data)
} else if (mapSlug !== null) { } else if (mapSlug !== null) {
userUuid = uuid(); userUuid = v4();
mapUrlStart = mapSlug; mapUrlStart = mapSlug;
newUrl = null; newUrl = null;
} else { } else {
userUuid = uuid(); userUuid = v4();
mapUrlStart = host.replace('api.', 'maps.') + URL_ROOM_STARTED; mapUrlStart = host.replace('api.', 'maps.') + URL_ROOM_STARTED;
newUrl = '_/global/'+mapUrlStart; newUrl = '_/global/'+mapUrlStart;
} }

View File

@ -1,6 +1,6 @@
import {App} from "../Server/sifrr.server"; import {App} from "../Server/sifrr.server";
import {uuid} from "uuidv4"; import {v4} from "uuid";
import {HttpRequest, HttpResponse} from "uWebSockets.js"; import {HttpRequest, HttpResponse} from "uWebSockets.js";
import {BaseController} from "./BaseController"; import {BaseController} from "./BaseController";
import { Readable } from 'stream' import { Readable } from 'stream'
@ -51,7 +51,7 @@ export class FileController extends BaseController {
}) })
try { try {
const audioMessageId = uuid(); const audioMessageId = v4();
const params = await res.formData({ const params = await res.formData({
onFile: (fieldname: string, onFile: (fieldname: string,

View File

@ -36,10 +36,8 @@ export class ConsoleGlobalMessageManager {
} }
initialise() { initialise() {
try { for (const elem of document.getElementsByClassName(CLASS_CONSOLE_MESSAGE)) {
HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE); elem.remove();
}catch (err){
console.error(err);
} }
const typeConsole = document.createElement('input'); const typeConsole = document.createElement('input');

View File

@ -11,7 +11,7 @@ interface LoginApiData {
} }
class ConnectionManager { class ConnectionManager {
private initPromise: Promise<LoginApiData> = Promise.reject(); private initPromise!: Promise<LoginApiData>;
private mapUrlStart: string|null = null; private mapUrlStart: string|null = null;
private authToken:string|null = null; private authToken:string|null = null;

View File

@ -43,6 +43,7 @@ export class RoomConnection implements RoomConnection {
private userId: number|null = null; private userId: number|null = null;
private listeners: Map<string, Function[]> = new Map<string, Function[]>(); private listeners: Map<string, Function[]> = new Map<string, Function[]>();
private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any
private closed: boolean = false;
public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any
RoomConnection.websocketFactory = websocketFactory; RoomConnection.websocketFactory = websocketFactory;
@ -173,6 +174,7 @@ export class RoomConnection implements RoomConnection {
public closeConnection(): void { public closeConnection(): void {
this.socket?.close(); this.socket?.close();
this.closed = true;
} }
private toPositionMessage(x : number, y : number, direction : string, moving: boolean): PositionMessage { private toPositionMessage(x : number, y : number, direction : string, moving: boolean): PositionMessage {
@ -389,6 +391,9 @@ export class RoomConnection implements RoomConnection {
public onServerDisconnected(callback: (event: CloseEvent) => void): void { public onServerDisconnected(callback: (event: CloseEvent) => void): void {
this.socket.addEventListener('close', (event) => { this.socket.addEventListener('close', (event) => {
if (this.closed === true) {
return;
}
console.log('Socket closed with code '+event.code+". Reason: "+event.reason); console.log('Socket closed with code '+event.code+". Reason: "+event.reason);
if (event.code === 1000) { if (event.code === 1000) {
// Normal closure case // Normal closure case

View File

@ -38,4 +38,16 @@ export class TextInput extends Phaser.GameObjects.BitmapText {
getText(): string { getText(): string {
return this.text; return this.text;
} }
setX(x: number): this {
super.setX(x);
this.underLine.x = x;
return this;
}
setY(y: number): this {
super.setY(y);
this.underLine.y = y+1;
return this;
}
} }

View File

@ -45,6 +45,7 @@ import {connectionManager} from "../../Connexion/ConnectionManager";
import {RoomConnection} from "../../Connexion/RoomConnection"; import {RoomConnection} from "../../Connexion/RoomConnection";
import {GlobalMessageManager} from "../../Administration/GlobalMessageManager"; import {GlobalMessageManager} from "../../Administration/GlobalMessageManager";
import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager"; import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager";
import {ResizableScene} from "../Login/ResizableScene";
export enum Textures { export enum Textures {
@ -86,7 +87,7 @@ interface DeleteGroupEventInterface {
groupId: number groupId: number
} }
export class GameScene extends Phaser.Scene implements CenterListener { export class GameScene extends ResizableScene implements CenterListener {
GameManager : GameManager; GameManager : GameManager;
Terrains : Array<Phaser.Tilemaps.Tileset>; Terrains : Array<Phaser.Tilemaps.Tileset>;
CurrentPlayer!: CurrentGamerInterface; CurrentPlayer!: CurrentGamerInterface;
@ -131,7 +132,6 @@ export class GameScene extends Phaser.Scene implements CenterListener {
private startLayerName: string|undefined; private startLayerName: string|undefined;
private presentationModeSprite!: Sprite; private presentationModeSprite!: Sprite;
private chatModeSprite!: Sprite; private chatModeSprite!: Sprite;
private onResizeCallback!: (this: Window, ev: UIEvent) => void;
private gameMap!: GameMap; private gameMap!: GameMap;
private actionableItems: Map<number, ActionableItem> = new Map<number, ActionableItem>(); private actionableItems: Map<number, ActionableItem> = new Map<number, ActionableItem>();
// The item that can be selected by pressing the space key. // The item that can be selected by pressing the space key.
@ -464,8 +464,6 @@ export class GameScene extends Phaser.Scene implements CenterListener {
this.switchLayoutMode(); this.switchLayoutMode();
}); });
this.onResizeCallback = this.onResize.bind(this);
window.addEventListener('resize', this.onResizeCallback);
this.reposition(); this.reposition();
// From now, this game scene will be notified of reposition events // From now, this game scene will be notified of reposition events
@ -951,13 +949,12 @@ export class GameScene extends Phaser.Scene implements CenterListener {
}); });
const nextSceneKey = this.checkToExit(); const nextSceneKey = this.checkToExit();
if(nextSceneKey){ if (nextSceneKey) {
// We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map.
this.connection.closeConnection(); this.connection.closeConnection();
this.simplePeer.unregister(); this.simplePeer.unregister();
this.scene.stop(); this.scene.stop();
this.scene.remove(this.scene.key); this.scene.remove(this.scene.key);
window.removeEventListener('resize', this.onResizeCallback);
this.scene.start(nextSceneKey.key, { this.scene.start(nextSceneKey.key, {
startLayerName: nextSceneKey.hash startLayerName: nextSceneKey.hash
}); });
@ -1150,7 +1147,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
this.connection.emitActionableEvent(itemId, eventName, state, parameters); this.connection.emitActionableEvent(itemId, eventName, state, parameters);
} }
private onResize(): void { public onResize(): void {
this.reposition(); this.reposition();
// Send new viewport to server // Send new viewport to server

View File

@ -6,6 +6,7 @@ import {LAYERS, loadAllLayers} from "../Entity/body_character";
import Sprite = Phaser.GameObjects.Sprite; import Sprite = Phaser.GameObjects.Sprite;
import Container = Phaser.GameObjects.Container; import Container = Phaser.GameObjects.Container;
import {gameManager} from "../Game/GameManager"; import {gameManager} from "../Game/GameManager";
import {ResizableScene} from "./ResizableScene";
export const CustomizeSceneName = "CustomizeScene"; export const CustomizeSceneName = "CustomizeScene";
@ -16,7 +17,7 @@ enum CustomizeTextures{
arrowUp = "arrow_up", arrowUp = "arrow_up",
} }
export class CustomizeScene extends Phaser.Scene { export class CustomizeScene extends ResizableScene {
private textField!: TextField; private textField!: TextField;
private enterField!: TextField; private enterField!: TextField;
@ -35,8 +36,6 @@ export class CustomizeScene extends Phaser.Scene {
private containersRow: Array<Array<Container>> = new Array<Array<Container>>(); private containersRow: Array<Array<Container>> = new Array<Array<Container>>();
private activeRow = 0; private activeRow = 0;
private repositionCallback!: (this: Window, ev: UIEvent) => void;
constructor() { constructor() {
super({ super({
key: CustomizeSceneName key: CustomizeSceneName
@ -144,10 +143,6 @@ export class CustomizeScene extends Phaser.Scene {
this.moveLayers(); this.moveLayers();
} }
}); });
this.repositionCallback = this.reposition.bind(this);
window.addEventListener('resize', this.repositionCallback);
} }
update(time: number, delta: number): void { update(time: number, delta: number): void {
super.update(time, delta); super.update(time, delta);
@ -249,7 +244,7 @@ export class CustomizeScene extends Phaser.Scene {
} }
} }
private reposition() { public onResize(): void {
this.moveLayers(); this.moveLayers();
this.Rectangle.x = this.cameras.main.worldView.x + this.cameras.main.width / 2; this.Rectangle.x = this.cameras.main.worldView.x + this.cameras.main.width / 2;

View File

@ -7,6 +7,7 @@ import Rectangle = Phaser.GameObjects.Rectangle;
import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character"; import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character";
import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {cypressAsserter} from "../../Cypress/CypressAsserter";
import {SelectCharacterSceneName} from "./SelectCharacterScene"; import {SelectCharacterSceneName} from "./SelectCharacterScene";
import {ResizableScene} from "./ResizableScene";
//todo: put this constants in a dedicated file //todo: put this constants in a dedicated file
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
@ -15,12 +16,12 @@ enum LoginTextures {
mainFont = "main_font" mainFont = "main_font"
} }
export class LoginScene extends Phaser.Scene { export class LoginScene extends ResizableScene {
private nameInput: TextInput|null = null; private nameInput!: TextInput;
private textField: TextField|null = null; private textField!: TextField;
private infoTextField: TextField|null = null; private infoTextField!: TextField;
private pressReturnField: TextField|null = null; private pressReturnField!: TextField;
private logo: Image|null = null; private logo!: Image;
private name: string = ''; private name: string = '';
constructor() { constructor() {
@ -93,4 +94,14 @@ export class LoginScene extends Phaser.Scene {
this.scene.start(SelectCharacterSceneName); this.scene.start(SelectCharacterSceneName);
} }
public onResize(ev: UIEvent): void {
this.textField.x = this.game.renderer.width / 2;
this.nameInput.setX(this.game.renderer.width / 2 - 64);
this.pressReturnField.x = this.game.renderer.width / 2;
this.logo.x = this.game.renderer.width - 30;
this.logo.y = this.game.renderer.height - 20;
this.infoTextField.y = this.game.renderer.height - 35;
}
} }

View File

@ -0,0 +1,5 @@
import {Scene} from "phaser";
export abstract class ResizableScene extends Scene {
public abstract onResize(ev: UIEvent): void;
}

View File

@ -5,6 +5,7 @@ import Rectangle = Phaser.GameObjects.Rectangle;
import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character"; import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character";
import {EnableCameraSceneName} from "./EnableCameraScene"; import {EnableCameraSceneName} from "./EnableCameraScene";
import {CustomizeSceneName} from "./CustomizeScene"; import {CustomizeSceneName} from "./CustomizeScene";
import {ResizableScene} from "./ResizableScene";
//todo: put this constants in a dedicated file //todo: put this constants in a dedicated file
@ -17,7 +18,7 @@ enum LoginTextures {
customizeButtonSelected = "customize_button_selected" customizeButtonSelected = "customize_button_selected"
} }
export class SelectCharacterScene extends Phaser.Scene { export class SelectCharacterScene extends ResizableScene {
private readonly nbCharactersPerRow = 4; private readonly nbCharactersPerRow = 4;
private textField!: TextField; private textField!: TextField;
private pressReturnField!: TextField; private pressReturnField!: TextField;
@ -242,4 +243,26 @@ export class SelectCharacterScene extends Phaser.Scene {
window.localStorage.setItem('selectedPlayer', String(playerNumber)); window.localStorage.setItem('selectedPlayer', String(playerNumber));
} }
} }
public onResize(ev: UIEvent): void {
this.textField.x = this.game.renderer.width / 2;
this.pressReturnField.x = this.game.renderer.width / 2;
this.logo.x = this.game.renderer.width - 30;
this.logo.y = this.game.renderer.height - 20;
this.customizeButton.x = this.game.renderer.width / 2;
this.customizeButtonSelected.x = this.game.renderer.width / 2;
for (let i = 0; i <PLAYER_RESOURCES.length; i++) {
const player = this.players[i];
const col = i % this.nbCharactersPerRow;
const row = Math.floor(i / this.nbCharactersPerRow);
const [x, y] = this.getCharacterPosition(col, row);
player.x = x;
player.y = y;
}
this.updateSelectedPlayer();
}
} }

View File

@ -12,6 +12,7 @@ import {OutlinePipeline} from "./Phaser/Shaders/OutlinePipeline";
import {CustomizeScene} from "./Phaser/Login/CustomizeScene"; import {CustomizeScene} from "./Phaser/Login/CustomizeScene";
import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager"; import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager";
import {connectionManager} from "./Connexion/ConnectionManager"; import {connectionManager} from "./Connexion/ConnectionManager";
import {ResizableScene} from "./Phaser/Login/ResizableScene";
//CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com'); //CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com');
connectionManager.init(); connectionManager.init();
@ -55,6 +56,13 @@ window.addEventListener('resize', function (event) {
const {width, height} = CoWebsiteManager.getGameSize(); const {width, height} = CoWebsiteManager.getGameSize();
game.scale.resize(width / RESOLUTION, height / RESOLUTION); game.scale.resize(width / RESOLUTION, height / RESOLUTION);
// 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);
}
}
}); });
CoWebsiteManager.onStateChange(() => { CoWebsiteManager.onStateChange(() => {
const {width, height} = CoWebsiteManager.getGameSize(); const {width, height} = CoWebsiteManager.getGameSize();

View File

@ -3871,7 +3871,7 @@ quill-delta@^3.6.2:
extend "^3.0.2" extend "^3.0.2"
fast-diff "1.1.2" fast-diff "1.1.2"
quill@^1.3.7: quill@1.3.7:
version "1.3.7" version "1.3.7"
resolved "https://registry.yarnpkg.com/quill/-/quill-1.3.7.tgz#da5b2f3a2c470e932340cdbf3668c9f21f9286e8" resolved "https://registry.yarnpkg.com/quill/-/quill-1.3.7.tgz#da5b2f3a2c470e932340cdbf3668c9f21f9286e8"
integrity sha512-hG/DVzh/TiknWtE6QmWAF/pxoZKYxfe3J/d/+ShUWkDvvkZQVTPeVmUJVu1uE6DDooC4fWTiCLh84ul89oNz5g== integrity sha512-hG/DVzh/TiknWtE6QmWAF/pxoZKYxfe3J/d/+ShUWkDvvkZQVTPeVmUJVu1uE6DDooC4fWTiCLh84ul89oNz5g==

View File

@ -2287,9 +2287,9 @@
"dev": true "dev": true
}, },
"elliptic": { "elliptic": {
"version": "6.4.1", "version": "6.5.3",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
"integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==", "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
"dev": true, "dev": true,
"requires": { "requires": {
"bn.js": "^4.4.0", "bn.js": "^4.4.0",
@ -3487,13 +3487,6 @@
"glob": "~7.1.1", "glob": "~7.1.1",
"lodash": "~4.17.12", "lodash": "~4.17.12",
"minimatch": "~3.0.2" "minimatch": "~3.0.2"
},
"dependencies": {
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
}
} }
}, },
"graceful-fs": { "graceful-fs": {
@ -4234,9 +4227,9 @@
} }
}, },
"lodash": { "lodash": {
"version": "4.17.15", "version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
}, },
"lodash.get": { "lodash.get": {
"version": "4.4.2", "version": "4.4.2",
@ -4721,11 +4714,6 @@
"which": "^1.2.9" "which": "^1.2.9"
} }
}, },
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
},
"lru-cache": { "lru-cache": {
"version": "4.1.5", "version": "4.1.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",