GameManager has an attribute scenePlugin
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import Image = Phaser.GameObjects.Image;
|
||||
import Rectangle = Phaser.GameObjects.Rectangle;
|
||||
import { addLoader } from "../Components/Loader";
|
||||
import { gameManager} from "../Game/GameManager";
|
||||
import { gameManager } from "../Game/GameManager";
|
||||
import { ResizableScene } from "./ResizableScene";
|
||||
import { EnableCameraSceneName } from "./EnableCameraScene";
|
||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||
import type { CompanionResourceDescriptionInterface } from "../Companion/CompanionTextures";
|
||||
import { getAllCompanionResources } from "../Companion/CompanionTexturesLoadingManager";
|
||||
import {touchScreenManager} from "../../Touch/TouchScreenManager";
|
||||
import {PinchManager} from "../UserInput/PinchManager";
|
||||
import { touchScreenManager } from "../../Touch/TouchScreenManager";
|
||||
import { PinchManager } from "../UserInput/PinchManager";
|
||||
import { MenuScene } from "../Menu/MenuScene";
|
||||
import {selectCompanionSceneVisibleStore} from "../../Stores/SelectCompanionStore";
|
||||
import {waScaleManager} from "../Services/WaScaleManager";
|
||||
import {isMobile} from "../../Enum/EnvironmentVariable";
|
||||
import { selectCompanionSceneVisibleStore } from "../../Stores/SelectCompanionStore";
|
||||
import { waScaleManager } from "../Services/WaScaleManager";
|
||||
import { isMobile } from "../../Enum/EnvironmentVariable";
|
||||
|
||||
export const SelectCompanionSceneName = "SelectCompanionScene";
|
||||
|
||||
@@ -28,12 +28,12 @@ export class SelectCompanionScene extends ResizableScene {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
key: SelectCompanionSceneName
|
||||
key: SelectCompanionSceneName,
|
||||
});
|
||||
}
|
||||
|
||||
preload() {
|
||||
getAllCompanionResources(this.load).forEach(model => {
|
||||
getAllCompanionResources(this.load).forEach((model) => {
|
||||
this.companionModels.push(model);
|
||||
});
|
||||
|
||||
@@ -42,7 +42,6 @@ export class SelectCompanionScene extends ResizableScene {
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
selectCompanionSceneVisibleStore.set(true);
|
||||
|
||||
waScaleManager.saveZoom();
|
||||
@@ -53,14 +52,16 @@ export class SelectCompanionScene extends ResizableScene {
|
||||
}
|
||||
|
||||
// input events
|
||||
this.input.keyboard.on('keyup-ENTER', this.selectCompanion.bind(this));
|
||||
this.input.keyboard.on("keyup-ENTER", this.selectCompanion.bind(this));
|
||||
|
||||
this.input.keyboard.on('keydown-RIGHT', this.moveToRight.bind(this));
|
||||
this.input.keyboard.on('keydown-LEFT', this.moveToLeft.bind(this));
|
||||
this.input.keyboard.on("keydown-RIGHT", this.moveToRight.bind(this));
|
||||
this.input.keyboard.on("keydown-LEFT", this.moveToLeft.bind(this));
|
||||
|
||||
if(localUserStore.getCompanion()){
|
||||
const companionIndex = this.companionModels.findIndex((companion) => companion.name === localUserStore.getCompanion());
|
||||
if(companionIndex > -1 || companionIndex < this.companions.length){
|
||||
if (localUserStore.getCompanion()) {
|
||||
const companionIndex = this.companionModels.findIndex(
|
||||
(companion) => companion.name === localUserStore.getCompanion()
|
||||
);
|
||||
if (companionIndex > -1 || companionIndex < this.companions.length) {
|
||||
this.currentCompanion = companionIndex;
|
||||
this.selectedCompanion = this.companions[companionIndex];
|
||||
}
|
||||
@@ -89,26 +90,26 @@ export class SelectCompanionScene extends ResizableScene {
|
||||
this.closeScene();
|
||||
}
|
||||
|
||||
public closeScene(){
|
||||
public closeScene() {
|
||||
// next scene
|
||||
this.scene.stop(SelectCompanionSceneName);
|
||||
waScaleManager.restoreZoom();
|
||||
gameManager.tryResumingGame(this, EnableCameraSceneName);
|
||||
gameManager.tryResumingGame(EnableCameraSceneName);
|
||||
this.scene.remove(SelectCompanionSceneName);
|
||||
selectCompanionSceneVisibleStore.set(false);
|
||||
}
|
||||
|
||||
private createCurrentCompanion(): void {
|
||||
for (let i = 0; i < this.companionModels.length; i++) {
|
||||
const companionResource = this.companionModels[i]
|
||||
const companionResource = this.companionModels[i];
|
||||
const [middleX, middleY] = this.getCompanionPosition();
|
||||
const companion = this.physics.add.sprite(middleX, middleY, companionResource.name, 0);
|
||||
this.setUpCompanion(companion, i);
|
||||
this.anims.create({
|
||||
key: companionResource.name,
|
||||
frames: this.anims.generateFrameNumbers(companionResource.name, {start: 0, end: 2,}),
|
||||
frames: this.anims.generateFrameNumbers(companionResource.name, { start: 0, end: 2 }),
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
repeat: -1,
|
||||
});
|
||||
|
||||
companion.setInteractive().on("pointerdown", () => {
|
||||
@@ -140,87 +141,84 @@ export class SelectCompanionScene extends ResizableScene {
|
||||
this.selectedCompanion = companion;
|
||||
}
|
||||
|
||||
private moveCompanion(){
|
||||
for(let i = 0; i < this.companions.length; i++){
|
||||
private moveCompanion() {
|
||||
for (let i = 0; i < this.companions.length; i++) {
|
||||
const companion = this.companions[i];
|
||||
this.setUpCompanion(companion, i);
|
||||
}
|
||||
this.updateSelectedCompanion();
|
||||
}
|
||||
|
||||
public moveToRight(){
|
||||
if(this.currentCompanion === (this.companions.length - 1)){
|
||||
public moveToRight() {
|
||||
if (this.currentCompanion === this.companions.length - 1) {
|
||||
return;
|
||||
}
|
||||
this.currentCompanion += 1;
|
||||
this.moveCompanion();
|
||||
}
|
||||
|
||||
public moveToLeft(){
|
||||
if(this.currentCompanion === 0){
|
||||
public moveToLeft() {
|
||||
if (this.currentCompanion === 0) {
|
||||
return;
|
||||
}
|
||||
this.currentCompanion -= 1;
|
||||
this.moveCompanion();
|
||||
}
|
||||
|
||||
private defineSetupCompanion(num: number){
|
||||
private defineSetupCompanion(num: number) {
|
||||
const deltaX = 30;
|
||||
const deltaY = 2;
|
||||
let [companionX, companionY] = this.getCompanionPosition();
|
||||
let companionVisible = true;
|
||||
let companionScale = 1.5;
|
||||
let companionOpactity = 1;
|
||||
if( this.currentCompanion !== num ){
|
||||
if (this.currentCompanion !== num) {
|
||||
companionVisible = false;
|
||||
}
|
||||
if( num === (this.currentCompanion + 1) ){
|
||||
if (num === this.currentCompanion + 1) {
|
||||
companionY -= deltaY;
|
||||
companionX += deltaX;
|
||||
companionScale = 0.8;
|
||||
companionOpactity = 0.6;
|
||||
companionVisible = true;
|
||||
}
|
||||
if( num === (this.currentCompanion + 2) ){
|
||||
if (num === this.currentCompanion + 2) {
|
||||
companionY -= deltaY;
|
||||
companionX += (deltaX * 2);
|
||||
companionX += deltaX * 2;
|
||||
companionScale = 0.8;
|
||||
companionOpactity = 0.6;
|
||||
companionVisible = true;
|
||||
}
|
||||
if( num === (this.currentCompanion - 1) ){
|
||||
if (num === this.currentCompanion - 1) {
|
||||
companionY -= deltaY;
|
||||
companionX -= deltaX;
|
||||
companionScale = 0.8;
|
||||
companionOpactity = 0.6;
|
||||
companionVisible = true;
|
||||
}
|
||||
if( num === (this.currentCompanion - 2) ){
|
||||
if (num === this.currentCompanion - 2) {
|
||||
companionY -= deltaY;
|
||||
companionX -= (deltaX * 2);
|
||||
companionX -= deltaX * 2;
|
||||
companionScale = 0.8;
|
||||
companionOpactity = 0.6;
|
||||
companionVisible = true;
|
||||
}
|
||||
return {companionX, companionY, companionScale, companionOpactity, companionVisible}
|
||||
return { companionX, companionY, companionScale, companionOpactity, companionVisible };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pixel position by on column and row number
|
||||
*/
|
||||
private getCompanionPosition(): [number, number] {
|
||||
return [
|
||||
this.game.renderer.width / 2,
|
||||
this.game.renderer.height / 3
|
||||
];
|
||||
return [this.game.renderer.width / 2, this.game.renderer.height / 3];
|
||||
}
|
||||
|
||||
private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number){
|
||||
|
||||
const {companionX, companionY, companionScale, companionOpactity, companionVisible} = this.defineSetupCompanion(numero);
|
||||
private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number) {
|
||||
const { companionX, companionY, companionScale, companionOpactity, companionVisible } =
|
||||
this.defineSetupCompanion(numero);
|
||||
companion.setBounce(0.2);
|
||||
companion.setCollideWorldBounds(true);
|
||||
companion.setVisible( companionVisible );
|
||||
companion.setVisible(companionVisible);
|
||||
companion.setScale(companionScale, companionScale);
|
||||
companion.setAlpha(companionOpactity);
|
||||
companion.setX(companionX);
|
||||
|
||||
Reference in New Issue
Block a user