Create exception error
This commit is contained in:
parent
f5dd5efc0e
commit
323fa6abba
1
front/src/Exception/TextureError.ts
Normal file
1
front/src/Exception/TextureError.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export class TextureError extends Error{}
|
@ -3,6 +3,7 @@ import {SpeechBubble} from "./SpeechBubble";
|
|||||||
import BitmapText = Phaser.GameObjects.BitmapText;
|
import BitmapText = Phaser.GameObjects.BitmapText;
|
||||||
import Container = Phaser.GameObjects.Container;
|
import Container = Phaser.GameObjects.Container;
|
||||||
import Sprite = Phaser.GameObjects.Sprite;
|
import Sprite = Phaser.GameObjects.Sprite;
|
||||||
|
import {TextureError} from "../../Exception/TextureError";
|
||||||
|
|
||||||
export interface PlayerResourceDescriptionInterface {
|
export interface PlayerResourceDescriptionInterface {
|
||||||
name: string,
|
name: string,
|
||||||
@ -94,6 +95,9 @@ export abstract class Character extends Container {
|
|||||||
|
|
||||||
public addTextures(textures: string[], frame?: string | number): void {
|
public addTextures(textures: string[], frame?: string | number): void {
|
||||||
for (const texture of textures) {
|
for (const texture of textures) {
|
||||||
|
if(!this.scene.textures.exists(texture)){
|
||||||
|
throw new TextureError('texture not found');
|
||||||
|
}
|
||||||
const sprite = new Sprite(this.scene, 0, 0, texture, frame);
|
const sprite = new Sprite(this.scene, 0, 0, texture, frame);
|
||||||
sprite.setInteractive({useHandCursor: true});
|
sprite.setInteractive({useHandCursor: true});
|
||||||
this.add(sprite);
|
this.add(sprite);
|
||||||
@ -154,10 +158,7 @@ export abstract class Character extends Container {
|
|||||||
if (moving && (!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== direction)) {
|
if (moving && (!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== direction)) {
|
||||||
sprite.play(texture+'-'+direction, true);
|
sprite.play(texture+'-'+direction, true);
|
||||||
} else if (!moving) {
|
} else if (!moving) {
|
||||||
/*if (this.anims.currentAnim) {
|
sprite.anims.play(texture + '-' + direction, true);
|
||||||
this.anims.stop();
|
|
||||||
}*/
|
|
||||||
sprite.play(texture+'-'+direction, true);
|
|
||||||
sprite.anims.stop();
|
sprite.anims.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ import {PresentationModeIcon} from "../Components/PresentationModeIcon";
|
|||||||
import {ChatModeIcon} from "../Components/ChatModeIcon";
|
import {ChatModeIcon} from "../Components/ChatModeIcon";
|
||||||
import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon";
|
import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon";
|
||||||
import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene";
|
import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene";
|
||||||
|
import {TextureError} from "../../Exception/TextureError";
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface|null,
|
initPosition: PointInterface|null,
|
||||||
@ -376,13 +377,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
mediaManager.setUserInputManager(this.userInputManager);
|
mediaManager.setUserInputManager(this.userInputManager);
|
||||||
|
|
||||||
//notify game manager can to create currentUser in map
|
//notify game manager can to create currentUser in map
|
||||||
try {
|
this.createCurrentPlayer();
|
||||||
this.createCurrentPlayer();
|
|
||||||
}catch (err){
|
|
||||||
//permit to return on character custom if any there any changes frame in the new version
|
|
||||||
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene());
|
|
||||||
throw 'characterLayers are not invalid';
|
|
||||||
}
|
|
||||||
|
|
||||||
//initialise camera
|
//initialise camera
|
||||||
this.initCamera();
|
this.initCamera();
|
||||||
@ -829,16 +824,23 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
createCurrentPlayer(){
|
createCurrentPlayer(){
|
||||||
//initialise player
|
//initialise player
|
||||||
//TODO create animation moving between exit and start
|
//TODO create animation moving between exit and start
|
||||||
this.CurrentPlayer = new Player(
|
try {
|
||||||
this,
|
this.CurrentPlayer = new Player(
|
||||||
this.startX,
|
this,
|
||||||
this.startY,
|
this.startX,
|
||||||
this.playerName,
|
this.startY,
|
||||||
this.characterLayers,
|
this.playerName,
|
||||||
PlayerAnimationNames.WalkDown,
|
this.characterLayers,
|
||||||
false,
|
PlayerAnimationNames.WalkDown,
|
||||||
this.userInputManager
|
false,
|
||||||
);
|
this.userInputManager
|
||||||
|
);
|
||||||
|
}catch (err){
|
||||||
|
if(err instanceof TextureError) {
|
||||||
|
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene());
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//create collision
|
//create collision
|
||||||
this.createCollisionWithPlayer();
|
this.createCollisionWithPlayer();
|
||||||
|
Loading…
Reference in New Issue
Block a user