Refactoring & fix feedback WorkAdventure

This commit is contained in:
Gregoire Parant 2021-04-23 03:59:14 +02:00
parent 8e52b8597c
commit f11e936143
21 changed files with 275 additions and 116 deletions

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#customizeScene { #customizeScene {
background: #0000; background: #0000;
/*border: 1px solid #ebeeee;*/ /*border: 1px solid #ebeeee;*/
@ -8,7 +11,7 @@
overflow: scroll; overflow: scroll;
width: 42vw; width: 42vw;
height: 38vh; height: 38vh;
max-width: 300px; /*max-width: 300px;*/
max-height: 40vh; max-height: 40vh;
} }
#customizeScene h1 { #customizeScene h1 {
@ -48,7 +51,7 @@
width: 100%; width: 100%;
} }
#customizeScene section.action.action-move { #customizeScene section.action.action-move {
top: 96%; top: 55%;
} }
#customizeScene button { #customizeScene button {
margin: 2px 10px; margin: 2px 10px;
@ -140,11 +143,11 @@
<section class="action action-move"> <section class="action action-move">
<button class="customizeSceneButton" id="customizeSceneButtonLeft"> < </button> <button class="customizeSceneButton" id="customizeSceneButtonLeft"> < </button>
<button class="customizeSceneButton" id="customizeSceneButtonRight"> > </button> <button class="customizeSceneButton" id="customizeSceneButtonRight"> > </button>
<button class="customizeSceneButton" id="customizeSceneButtonUp"> < </button> <!--<button class="customizeSceneButton" id="customizeSceneButtonUp"> < </button>
<button class="customizeSceneButton" id="customizeSceneButtonDown"> > </button> <button class="customizeSceneButton" id="customizeSceneButtonDown"> > </button>-->
</section> </section>
<section class="action"> <section class="action">
<a type="submit" id="customizeSceneFormBack">Back</a> <a type="submit" id="customizeSceneFormBack">Back</a>
<button type="submit" id="customizeSceneFormSubmit">Finish</button> <button type="submit" id="customizeSceneFormSubmit">Next</button>
</section> </section>
</form> </form>

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#enableCameraScene { #enableCameraScene {
background: #000000; background: #000000;
/*border: 1px solid #ebeeee;*/ /*border: 1px solid #ebeeee;*/
@ -54,7 +57,6 @@
color: #ebeeee; color: #ebeeee;
border-radius: 7px; border-radius: 7px;
padding-bottom: 4px; padding-bottom: 4px;
width: 100px;
} }
#enableCameraScene button#enableCameraSceneFormCancel { #enableCameraScene button#enableCameraSceneFormCancel {
background-color: #c7c7c700; background-color: #c7c7c700;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#selectCharacterScene { #selectCharacterScene {
background: #0000; background: #0000;
/*border: 1px solid #ebeeee;*/ /*border: 1px solid #ebeeee;*/
@ -9,6 +12,7 @@
overflow: scroll; overflow: scroll;
max-width: 300px; max-width: 300px;
width: 40vw; width: 40vw;
overflow: unset;
} }
#selectCharacterScene h1 { #selectCharacterScene h1 {
background-image: linear-gradient(top, #f1f3f3, #d4dae0); background-image: linear-gradient(top, #f1f3f3, #d4dae0);
@ -42,7 +46,7 @@
#selectCharacterScene section.action { #selectCharacterScene section.action {
text-align: center; text-align: center;
margin: 0; margin: 0;
margin-top: 20vh; margin-top: 28vh;
} }
#selectCharacterScene button { #selectCharacterScene button {
margin: 10px 0px; margin: 10px 0px;
@ -98,9 +102,11 @@
width: 25px; width: 25px;
} }
#selectCharacterScene section button.selectCharacterButton#selectCharacterButtonLeft{ #selectCharacterScene section button.selectCharacterButton#selectCharacterButtonLeft{
display: none;
left: 1vw; left: 1vw;
} }
#selectCharacterScene section button.selectCharacterButton#selectCharacterButtonRight{ #selectCharacterScene section button.selectCharacterButton#selectCharacterButtonRight{
display: none;
right: 1vw; right: 1vw;
} }
#selectCharacterScene section button#selectCharacterSceneFormCustomYourOwnSubmit{ #selectCharacterScene section button#selectCharacterSceneFormCustomYourOwnSubmit{
@ -110,6 +116,15 @@
background-color: #ffd700; background-color: #ffd700;
color: black; color: black;
} }
@media only screen and (max-width: 800px),
only screen and (max-height: 600px) {
#selectCharacterScene section button.selectCharacterButton#selectCharacterButtonRight{
display: block;
}
#selectCharacterScene section button.selectCharacterButton#selectCharacterButtonLeft{
display: block;
}
}
</style> </style>
<form id="selectCharacterScene" hidden> <form id="selectCharacterScene" hidden>

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#selectCompanionScene { #selectCompanionScene {
background: #0000; background: #0000;
/*border: 1px solid #ebeeee;*/ /*border: 1px solid #ebeeee;*/

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#gameMenu main{ #gameMenu main{
margin-top: 15px; margin-top: 15px;
} }

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#menuIcon button { #menuIcon button {
background-color: black; background-color: black;
color: white; color: white;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#gameQuality { #gameQuality {
background: #eceeee; background: #eceeee;
border: 1px solid #42464b; border: 1px solid #42464b;
@ -47,7 +50,6 @@
color: white; color: white;
border-radius: 7px; border-radius: 7px;
padding-bottom: 4px; padding-bottom: 4px;
width: 60px;
} }
#gameQuality button#gameQualityFormCancel { #gameQuality button#gameQualityFormCancel {
background-color: #c7c7c700; background-color: #c7c7c700;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#gameReport { #gameReport {
background: #eceeee; background: #eceeee;
border: 1px solid #42464b; border: 1px solid #42464b;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#gameShare { #gameShare {
background: #eceeee; background: #eceeee;
border: 1px solid #42464b; border: 1px solid #42464b;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#helpCameraSettings { #helpCameraSettings {
background: #eceeee; background: #eceeee;
border: 1px solid #42464b; border: 1px solid #42464b;

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#loginScene { #loginScene {
background: #000000; background: #000000;
/*border: 1px solid #ebeeee;*/ /*border: 1px solid #ebeeee;*/

View File

@ -1,4 +1,7 @@
<style> <style>
*{
font-family: PixelFont-7,monospace!important;
}
#warningMain { #warningMain {
border-radius: 5px; border-radius: 5px;
height: 100px; height: 100px;

View File

@ -17,6 +17,8 @@ const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new
export const MAX_USERNAME_LENGTH = parseInt(process.env.MAX_USERNAME_LENGTH || '') || 8; export const MAX_USERNAME_LENGTH = parseInt(process.env.MAX_USERNAME_LENGTH || '') || 8;
export const MAX_PER_GROUP = parseInt(process.env.MAX_PER_GROUP || '4'); export const MAX_PER_GROUP = parseInt(process.env.MAX_PER_GROUP || '4');
export const isMobile = ():boolean => ( ( window.innerWidth <= 800 ) || ( window.innerHeight <= 600 ) );
export { export {
DEBUG_MODE, DEBUG_MODE,
START_ROOM_URL, START_ROOM_URL,

View File

@ -1,12 +1,9 @@
import {EnableCameraSceneName} from "./EnableCameraScene"; import {EnableCameraSceneName} from "./EnableCameraScene";
import {TextField} from "../Components/TextField";
import Image = Phaser.GameObjects.Image;
import Rectangle = Phaser.GameObjects.Rectangle; import Rectangle = Phaser.GameObjects.Rectangle;
import {loadAllLayers, loadCustomTexture} from "../Entity/PlayerTexturesLoadingManager"; import {loadAllLayers} from "../Entity/PlayerTexturesLoadingManager";
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";
import {localUserStore} from "../../Connexion/LocalUserStore"; import {localUserStore} from "../../Connexion/LocalUserStore";
import {addLoader} from "../Components/Loader"; import {addLoader} from "../Components/Loader";
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures"; import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
@ -17,34 +14,12 @@ import { SelectCharacterSceneName } from "./SelectCharacterScene";
export const CustomizeSceneName = "CustomizeScene"; export const CustomizeSceneName = "CustomizeScene";
enum CustomizeTextures{
icon = "icon",
arrowRight = "arrow_right",
mainFont = "main_font",
arrowUp = "arrow_up",
}
export const CustomizeSceneKey = "CustomizeScene"; export const CustomizeSceneKey = "CustomizeScene";
const customizeSceneKey = 'customizeScene'; const customizeSceneKey = 'customizeScene';
export class CustomizeScene extends AbstractCharacterScene { export class CustomizeScene extends AbstractCharacterScene {
private arrowRight!: Image;
private arrowLeft!: Image;
private arrowDown!: Image;
private arrowUp!: Image;
private Rectangle!: Rectangle; private Rectangle!: Rectangle;
private mobileTapUP!: Rectangle;
private mobileTapDOWN!: Rectangle;
private mobileTapLEFT!: Rectangle;
private mobileTapRIGHT!: Rectangle;
private mobileTapENTER!: Rectangle;
private logo!: Image;
private selectedLayers: number[] = [0]; private selectedLayers: number[] = [0];
private containersRow: Container[][] = []; private containersRow: Container[][] = [];
private activeRow:number = 0; private activeRow:number = 0;
@ -91,9 +66,17 @@ export class CustomizeScene extends AbstractCharacterScene {
}else if((event?.target as HTMLInputElement).id === 'customizeSceneButtonUp') { }else if((event?.target as HTMLInputElement).id === 'customizeSceneButtonUp') {
this.moveCursorVertically(-1); this.moveCursorVertically(-1);
}else if((event?.target as HTMLInputElement).id === 'customizeSceneFormBack') { }else if((event?.target as HTMLInputElement).id === 'customizeSceneFormBack') {
this.backToPreviousScene(); if(this.activeRow > 0){
}else if((event?.target as HTMLInputElement).id === 'customizeSceneFormSubmit') { this.moveCursorVertically(-1);
this.nextSceneToCamera(); }else{
this.backToPreviousScene();
}
}else if((event?.target as HTMLButtonElement).id === 'customizeSceneFormSubmit') {
if(this.activeRow < 5){
this.moveCursorVertically(1);
}else{
this.nextSceneToCamera();
}
} }
}); });
@ -143,6 +126,17 @@ export class CustomizeScene extends AbstractCharacterScene {
} }
private moveCursorVertically(index:number): void { private moveCursorVertically(index:number): void {
if(index === -1 && this.activeRow === 5){
const button = this.customizeSceneElement.getChildByID('customizeSceneFormSubmit') as HTMLButtonElement;
button.innerText = 'Next';
}
if(index === 1 && this.activeRow === 4){
const button = this.customizeSceneElement.getChildByID('customizeSceneFormSubmit') as HTMLButtonElement;
button.innerText = 'Finish';
}
this.activeRow += index; this.activeRow += index;
if (this.activeRow < 0) { if (this.activeRow < 0) {
this.activeRow = 0 this.activeRow = 0
@ -278,7 +272,7 @@ export class CustomizeScene extends AbstractCharacterScene {
}); });
} }
private getMiddleX() : number{ protected getMiddleX() : number{
return (this.game.renderer.width / 2) - return (this.game.renderer.width / 2) -
( (
this.customizeSceneElement this.customizeSceneElement
@ -312,4 +306,37 @@ export class CustomizeScene extends AbstractCharacterScene {
this.scene.sleep(CustomizeSceneName); this.scene.sleep(CustomizeSceneName);
this.scene.run(SelectCharacterSceneName); this.scene.run(SelectCharacterSceneName);
} }
/**
* TODO fix me and mutualize code
*/
defineSetupPosition() : {playerX: number, playerY: number, playerScale: number, playserOpactity: number, playerVisible: boolean}{
throw new Error('defineSetupPosition cannot be used');
return {playerX: 0, playerY: 0, playerScale: 0, playserOpactity: 0, playerVisible: false};
}
/**
* TODO fix me and mutualize code
*/
nextSceneToCameraScene(): void {
throw new Error('nextSceneToCameraScene cannot be used in this scene');
}
/**
* TODO fix me and mutualize code
*/
nextSceneToCustomizeScene(): void {
throw new Error('nextSceneToCustomizeScene cannot be used in this scene');
}
/**
* TODO fix me and mutualize code
* Returns pixel position by on column and row number
*/
getCharacterPosition(): [number, number] {
return [
this.game.renderer.width / 2,
this.game.renderer.height / 2
];
}
} }

View File

@ -63,7 +63,6 @@ export class EnableCameraScene extends Phaser.Scene {
create() { create() {
const middleX = this.getMiddleX(); const middleX = this.getMiddleX();
console.log('create => middleX', middleX);
this.enableCameraSceneElement = this.add.dom(middleX, 0).createFromCache(enableCameraSceneKey); this.enableCameraSceneElement = this.add.dom(middleX, 0).createFromCache(enableCameraSceneKey);
MenuScene.revealMenusAfterInit(this.enableCameraSceneElement, enableCameraSceneKey); MenuScene.revealMenusAfterInit(this.enableCameraSceneElement, enableCameraSceneKey);

View File

@ -3,6 +3,7 @@ import {SelectCharacterSceneName} from "./SelectCharacterScene";
import {ResizableScene} from "./ResizableScene"; import {ResizableScene} from "./ResizableScene";
import { localUserStore } from "../../Connexion/LocalUserStore"; import { localUserStore } from "../../Connexion/LocalUserStore";
import {MenuScene} from "../Menu/MenuScene"; import {MenuScene} from "../Menu/MenuScene";
import { isUserNameValid } from "../../Connexion/LocalUser";
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
@ -12,7 +13,6 @@ export class LoginScene extends ResizableScene {
private loginSceneElement!: Phaser.GameObjects.DOMElement; private loginSceneElement!: Phaser.GameObjects.DOMElement;
private name: string = ''; private name: string = '';
private mobileTapZone!: Phaser.GameObjects.Zone;
constructor() { constructor() {
super({ super({
@ -35,11 +35,14 @@ export class LoginScene extends ResizableScene {
inputElement.value = localUserStore.getName() ?? ''; inputElement.value = localUserStore.getName() ?? '';
inputElement.focus(); inputElement.focus();
inputElement.addEventListener('keypress', (event: KeyboardEvent) => { inputElement.addEventListener('keypress', (event: KeyboardEvent) => {
if(inputElement.value.length > 8){ if(inputElement.value.length > 7){
event.preventDefault(); event.preventDefault();
return; return;
} }
pErrorElement.innerHTML = ''; pErrorElement.innerHTML = '';
if(inputElement.value && !isUserNameValid(inputElement.value)){
pErrorElement.innerHTML = 'Invalid user name: only letters and numbers are allowed. No spaces.';
}
if (event.key === 'Enter') { if (event.key === 'Enter') {
event.preventDefault(); event.preventDefault();
this.login(inputElement); this.login(inputElement);
@ -61,6 +64,10 @@ export class LoginScene extends ResizableScene {
pErrorElement.innerHTML = 'The name is empty'; pErrorElement.innerHTML = 'The name is empty';
return return
} }
if(!isUserNameValid(this.name)){
pErrorElement.innerHTML = 'Invalid user name: only letters and numbers are allowed. No spaces.';
return
}
if (this.name === '') return if (this.name === '') return
gameManager.setPlayerName(this.name); gameManager.setPlayerName(this.name);

View File

@ -0,0 +1,77 @@
import {gameManager} from "../Game/GameManager";
import {TextField} from "../Components/TextField";
import Image = Phaser.GameObjects.Image;
import Rectangle = Phaser.GameObjects.Rectangle;
import {EnableCameraSceneName} from "./EnableCameraScene";
import {CustomizeSceneName} from "./CustomizeScene";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {loadAllDefaultModels} from "../Entity/PlayerTexturesLoadingManager";
import {addLoader} from "../Components/Loader";
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
import {AbstractCharacterScene} from "./AbstractCharacterScene";
import {areCharacterLayersValid} from "../../Connexion/LocalUser";
import {touchScreenManager} from "../../Touch/TouchScreenManager";
import {PinchManager} from "../UserInput/PinchManager";
import {MenuScene} from "../Menu/MenuScene";
import { SelectCharacterScene, SelectCharacterSceneName } from "./SelectCharacterScene";
export class SelectCharacterMobileScene extends SelectCharacterScene {
create(){
super.create();
this.selectedRectangle.destroy();
}
protected defineSetupPlayer(numero: number){
const deltaX = 30;
const deltaY = 2;
let [playerX, playerY] = this.getCharacterPosition();
let playerVisible = true;
let playerScale = 1.5;
let playserOpactity = 1;
if( this.currentSelectUser !== numero ){
playerVisible = false;
}
if( numero === (this.currentSelectUser + 1) ){
playerY -= deltaY;
playerX += deltaX;
playerScale = 0.8;
playserOpactity = 0.6;
playerVisible = true;
}
if( numero === (this.currentSelectUser + 2) ){
playerY -= deltaY;
playerX += (deltaX * 2);
playerScale = 0.8;
playserOpactity = 0.6;
playerVisible = true;
}
if( numero === (this.currentSelectUser - 1) ){
playerY -= deltaY;
playerX -= deltaX;
playerScale = 0.8;
playserOpactity = 0.6;
playerVisible = true;
}
if( numero === (this.currentSelectUser - 2) ){
playerY -= deltaY;
playerX -= (deltaX * 2);
playerScale = 0.8;
playserOpactity = 0.6;
playerVisible = true;
}
return {playerX, playerY, playerScale, playserOpactity, playerVisible}
}
/**
* Returns pixel position by on column and row number
*/
protected getCharacterPosition(): [number, number] {
return [
this.game.renderer.width / 2,
this.game.renderer.height / 3
];
}
}

View File

@ -1,5 +1,4 @@
import {gameManager} from "../Game/GameManager"; import {gameManager} from "../Game/GameManager";
import {TextField} from "../Components/TextField";
import Image = Phaser.GameObjects.Image; import Image = Phaser.GameObjects.Image;
import Rectangle = Phaser.GameObjects.Rectangle; import Rectangle = Phaser.GameObjects.Rectangle;
import {EnableCameraSceneName} from "./EnableCameraScene"; import {EnableCameraSceneName} from "./EnableCameraScene";
@ -13,29 +12,23 @@ import {areCharacterLayersValid} from "../../Connexion/LocalUser";
import {touchScreenManager} from "../../Touch/TouchScreenManager"; import {touchScreenManager} from "../../Touch/TouchScreenManager";
import {PinchManager} from "../UserInput/PinchManager"; import {PinchManager} from "../UserInput/PinchManager";
import {MenuScene} from "../Menu/MenuScene"; import {MenuScene} from "../Menu/MenuScene";
import Zone = Phaser.GameObjects.Zone; import { SelectCharacterMobileScene } from "./SelectCharacterMobileScene";
//todo: put this constants in a dedicated file //todo: put this constants in a dedicated file
export const SelectCharacterSceneName = "SelectCharacterScene"; export const SelectCharacterSceneName = "SelectCharacterScene";
enum LoginTextures {
playButton = "play_button",
icon = "icon",
mainFont = "main_font",
customizeButton = "customize_button",
customizeButtonSelected = "customize_button_selected"
}
const selectCharacterKey = 'selectCharacterScene'; const selectCharacterKey = 'selectCharacterScene';
export class SelectCharacterScene extends AbstractCharacterScene { export class SelectCharacterScene extends AbstractCharacterScene {
private readonly nbCharactersPerRow = 6; protected readonly nbCharactersPerRow = 6;
private selectedPlayer!: Phaser.Physics.Arcade.Sprite|null; // null if we are selecting the "customize" option protected selectedPlayer!: Phaser.Physics.Arcade.Sprite|null; // null if we are selecting the "customize" option
private players: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>(); protected players: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>();
private playerModels!: BodyResourceDescriptionInterface[]; protected playerModels!: BodyResourceDescriptionInterface[];
private selectCharacterSceneElement!: Phaser.GameObjects.DOMElement; protected selectedRectangle!: Rectangle;
private currentSelectUser = 0;
protected selectCharacterSceneElement!: Phaser.GameObjects.DOMElement;
protected currentSelectUser = 0;
constructor() { constructor() {
super({ super({
@ -58,6 +51,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
} }
create() { create() {
const middleX = this.getMiddleX(); const middleX = this.getMiddleX();
this.selectCharacterSceneElement = this.add.dom(middleX, 0).createFromCache(selectCharacterKey); this.selectCharacterSceneElement = this.add.dom(middleX, 0).createFromCache(selectCharacterKey);
MenuScene.revealMenusAfterInit(this.selectCharacterSceneElement, selectCharacterKey); MenuScene.revealMenusAfterInit(this.selectCharacterSceneElement, selectCharacterKey);
@ -80,6 +74,10 @@ export class SelectCharacterScene extends AbstractCharacterScene {
new PinchManager(this); new PinchManager(this);
} }
const rectangleXStart = this.game.renderer.width / 2 - (this.nbCharactersPerRow / 2) * 32 + 16;
this.selectedRectangle = this.add.rectangle(rectangleXStart, 90, 32, 32).setStrokeStyle(2, 0xFFFFFF);
this.selectedRectangle.setDepth(2);
/*create user*/ /*create user*/
this.createCurrentPlayer(); this.createCurrentPlayer();
const playerNumber = localUserStore.getPlayerCharacterIndex(); const playerNumber = localUserStore.getPlayerCharacterIndex();
@ -94,9 +92,15 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.input.keyboard.on('keydown-LEFT', () => { this.input.keyboard.on('keydown-LEFT', () => {
this.moveToLeft(); this.moveToLeft();
}); });
this.input.keyboard.on('keydown-UP', () => {
this.moveToUp();
});
this.input.keyboard.on('keydown-DOWN', () => {
this.moveToDown();
});
} }
private nextSceneToCameraScene(): void { protected nextSceneToCameraScene(): void {
if (this.selectedPlayer !== null && !areCharacterLayersValid([this.selectedPlayer.texture.key])) { if (this.selectedPlayer !== null && !areCharacterLayersValid([this.selectedPlayer.texture.key])) {
return; return;
} }
@ -109,7 +113,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.scene.remove(SelectCharacterSceneName); this.scene.remove(SelectCharacterSceneName);
} }
private nextSceneToCustomizeScene(): void { protected nextSceneToCustomizeScene(): void {
if (this.selectedPlayer !== null && !areCharacterLayersValid([this.selectedPlayer.texture.key])) { if (this.selectedPlayer !== null && !areCharacterLayersValid([this.selectedPlayer.texture.key])) {
return; return;
} }
@ -126,8 +130,8 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.setUpPlayer(player, i); this.setUpPlayer(player, i);
this.anims.create({ this.anims.create({
key: playerResource.name, key: playerResource.name,
frames: this.anims.generateFrameNumbers(playerResource.name, {start: 0, end: 2,}), frames: this.anims.generateFrameNumbers(playerResource.name, {start: 0, end: 11}),
frameRate: 10, frameRate: 8,
repeat: -1 repeat: -1
}); });
player.setInteractive().on("pointerdown", () => { player.setInteractive().on("pointerdown", () => {
@ -144,7 +148,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.selectedPlayer.play(this.playerModels[this.currentSelectUser].name); this.selectedPlayer.play(this.playerModels[this.currentSelectUser].name);
} }
private moveUser(){ protected moveUser(){
for(let i = 0; i < this.players.length; i++){ for(let i = 0; i < this.players.length; i++){
const player = this.players[i]; const player = this.players[i];
this.setUpPlayer(player, i); this.setUpPlayer(player, i);
@ -152,7 +156,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.updateSelectedPlayer(); this.updateSelectedPlayer();
} }
private moveToLeft(){ protected moveToLeft(){
if(this.currentSelectUser === 0){ if(this.currentSelectUser === 0){
return; return;
} }
@ -160,7 +164,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.moveUser(); this.moveUser();
} }
private moveToRight(){ protected moveToRight(){
if(this.currentSelectUser === (this.players.length - 1)){ if(this.currentSelectUser === (this.players.length - 1)){
return; return;
} }
@ -168,48 +172,44 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.moveUser(); this.moveUser();
} }
private defineSetupPlayer(numero: number){ protected moveToUp(){
const deltaX = 30; if(this.currentSelectUser < this.nbCharactersPerRow){
const deltaY = 2; return;
let [playerX, playerY] = this.getCharacterPosition();
let playerVisible = true;
let playerScale = 1.5;
let playserOpactity = 1;
if( this.currentSelectUser !== numero ){
playerVisible = false;
} }
if( numero === (this.currentSelectUser + 1) ){ this.currentSelectUser -= this.nbCharactersPerRow;
playerY -= deltaY; this.moveUser();
playerX += deltaX; }
playerScale = 0.8;
playserOpactity = 0.6; protected moveToDown(){
playerVisible = true; if((this.currentSelectUser + this.nbCharactersPerRow) > (this.players.length - 1)){
return;
} }
if( numero === (this.currentSelectUser + 2) ){ this.currentSelectUser += this.nbCharactersPerRow;
playerY -= deltaY; this.moveUser();
playerX += (deltaX * 2); }
playerScale = 0.8;
playserOpactity = 0.6; protected defineSetupPlayer(numero: number){
playerVisible = true; const deltaX = 32;
} const deltaY = 32;
if( numero === (this.currentSelectUser - 1) ){ let [playerX, playerY] = this.getCharacterPosition(); // player X and player y are middle of the
playerY -= deltaY;
playerX -= deltaX; playerX = ( (playerX - (deltaX * 2.5)) + ((deltaX) * (numero % this.nbCharactersPerRow)) ); // calcul position on line users
playerScale = 0.8; playerY = ( (playerY - (deltaY * 2)) + ((deltaY) * ( Math.floor(numero / this.nbCharactersPerRow) )) ); // calcul position on column users
playserOpactity = 0.6;
playerVisible = true; const playerVisible = true;
} const playerScale = 1;
if( numero === (this.currentSelectUser - 2) ){ const playserOpactity = 1;
playerY -= deltaY;
playerX -= (deltaX * 2); // if selected
playerScale = 0.8; if( numero === this.currentSelectUser ){
playserOpactity = 0.6; this.selectedRectangle.setX(playerX);
playerVisible = true; this.selectedRectangle.setY(playerY);
} }
return {playerX, playerY, playerScale, playserOpactity, playerVisible} return {playerX, playerY, playerScale, playserOpactity, playerVisible}
} }
private setUpPlayer(player: Phaser.Physics.Arcade.Sprite, numero: number){ protected setUpPlayer(player: Phaser.Physics.Arcade.Sprite, numero: number){
const {playerX, playerY, playerScale, playserOpactity, playerVisible} = this.defineSetupPlayer(numero); const {playerX, playerY, playerScale, playserOpactity, playerVisible} = this.defineSetupPlayer(numero);
player.setBounce(0.2); player.setBounce(0.2);
@ -224,15 +224,15 @@ export class SelectCharacterScene extends AbstractCharacterScene {
/** /**
* Returns pixel position by on column and row number * Returns pixel position by on column and row number
*/ */
private getCharacterPosition(): [number, number] { protected getCharacterPosition(): [number, number] {
return [ return [
this.game.renderer.width / 2, this.game.renderer.width / 2,
this.game.renderer.height / 3 this.game.renderer.height / 2.5
]; ];
} }
private updateSelectedPlayer(): void { protected updateSelectedPlayer(): void {
this.selectedPlayer?.anims.pause(); this.selectedPlayer?.anims.pause(this.selectedPlayer?.anims.currentAnim.frames[0]);
const player = this.players[this.currentSelectUser]; const player = this.players[this.currentSelectUser];
player.play(this.playerModels[this.currentSelectUser].name); player.play(this.playerModels[this.currentSelectUser].name);
this.selectedPlayer = player; this.selectedPlayer = player;
@ -262,7 +262,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
}); });
} }
private getMiddleX() : number{ protected getMiddleX() : number{
return (this.game.renderer.width / 2) - return (this.game.renderer.width / 2) -
( (
this.selectCharacterSceneElement this.selectCharacterSceneElement

View File

@ -10,16 +10,9 @@ import { getAllCompanionResources } from "../Companion/CompanionTexturesLoadingM
import {touchScreenManager} from "../../Touch/TouchScreenManager"; import {touchScreenManager} from "../../Touch/TouchScreenManager";
import {PinchManager} from "../UserInput/PinchManager"; import {PinchManager} from "../UserInput/PinchManager";
import { MenuScene } from "../Menu/MenuScene"; import { MenuScene } from "../Menu/MenuScene";
import Zone = Phaser.GameObjects.Zone;
export const SelectCompanionSceneName = "SelectCompanionScene"; export const SelectCompanionSceneName = "SelectCompanionScene";
enum LoginTextures {
playButton = "play_button",
icon = "icon",
mainFont = "main_font"
}
const selectCompanionSceneKey = 'selectCompanionScene'; const selectCompanionSceneKey = 'selectCompanionScene';
export class SelectCompanionScene extends ResizableScene { export class SelectCompanionScene extends ResizableScene {

View File

@ -123,7 +123,6 @@ export class HelpCameraSettingsScene extends Phaser.Scene {
} }
private getMiddleY() : number{ private getMiddleY() : number{
console.log('this.helpCameraSettingsElement.node.getBoundingClientRect()', this.helpCameraSettingsElement.node.getBoundingClientRect());
const middleY = ((window.innerHeight) - ( const middleY = ((window.innerHeight) - (
(this.helpCameraSettingsElement (this.helpCameraSettingsElement
&& this.helpCameraSettingsElement.node && this.helpCameraSettingsElement.node

View File

@ -2,7 +2,7 @@ import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig; import GameConfig = Phaser.Types.Core.GameConfig;
import "../dist/resources/style/index.scss"; import "../dist/resources/style/index.scss";
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable"; import {DEBUG_MODE, isMobile, RESOLUTION} from "./Enum/EnvironmentVariable";
import {LoginScene} from "./Phaser/Login/LoginScene"; import {LoginScene} from "./Phaser/Login/LoginScene";
import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene"; import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
import {SelectCharacterScene} from "./Phaser/Login/SelectCharacterScene"; import {SelectCharacterScene} from "./Phaser/Login/SelectCharacterScene";
@ -17,6 +17,7 @@ import {HelpCameraSettingsScene} from "./Phaser/Menu/HelpCameraSettingsScene";
import {localUserStore} from "./Connexion/LocalUserStore"; import {localUserStore} from "./Connexion/LocalUserStore";
import {ErrorScene} from "./Phaser/Reconnecting/ErrorScene"; import {ErrorScene} from "./Phaser/Reconnecting/ErrorScene";
import {iframeListener} from "./Api/IframeListener"; import {iframeListener} from "./Api/IframeListener";
import { SelectCharacterMobileScene } from './Phaser/Login/SelectCharacterMobileScene';
const {width, height} = coWebsiteManager.getGameSize(); const {width, height} = coWebsiteManager.getGameSize();
@ -67,14 +68,22 @@ switch (phaserMode) {
throw new Error('phaserMode parameter must be one of "auto", "canvas" or "webgl"'); throw new Error('phaserMode parameter must be one of "auto", "canvas" or "webgl"');
} }
const config: GameConfig = { const config: GameConfig = {
type: mode, type: mode,
title: "WorkAdventure", title: "WorkAdventure",
width: width / RESOLUTION, width: width / RESOLUTION,
height: height / RESOLUTION, height: height / RESOLUTION,
parent: "game", parent: "game",
scene: [EntryScene, LoginScene, SelectCharacterScene, SelectCompanionScene, EnableCameraScene, ReconnectingScene, ErrorScene, CustomizeScene, MenuScene, HelpCameraSettingsScene], scene: [EntryScene,
LoginScene,
isMobile() ? SelectCharacterMobileScene : SelectCharacterScene,
SelectCompanionScene,
EnableCameraScene,
ReconnectingScene,
ErrorScene,
CustomizeScene,
MenuScene,
HelpCameraSettingsScene],
zoom: RESOLUTION, zoom: RESOLUTION,
fps: fps, fps: fps,
dom: { dom: {