load texture inside game scene instead inside of inside companion class
This commit is contained in:
parent
e5a196a42b
commit
187e21eed9
@ -23,7 +23,7 @@ export class Companion extends Container {
|
|||||||
private direction: PlayerAnimationDirections;
|
private direction: PlayerAnimationDirections;
|
||||||
private animationType: PlayerAnimationTypes;
|
private animationType: PlayerAnimationTypes;
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, x: number, y: number, name: string) {
|
constructor(scene: Phaser.Scene, x: number, y: number, name: string, texturePromise: Promise<string>) {
|
||||||
super(scene, x + 14, y + 4);
|
super(scene, x + 14, y + 4);
|
||||||
|
|
||||||
this.sprites = new Map<string, Sprite>();
|
this.sprites = new Map<string, Sprite>();
|
||||||
@ -37,12 +37,10 @@ export class Companion extends Container {
|
|||||||
|
|
||||||
this.companionName = name;
|
this.companionName = name;
|
||||||
|
|
||||||
lazyLoadCompanionResource(this.scene.load, this.companionName)
|
texturePromise.then(resource => {
|
||||||
.then(resource => {
|
|
||||||
this.addResource(resource);
|
this.addResource(resource);
|
||||||
this.invisible = false;
|
this.invisible = false;
|
||||||
})
|
})
|
||||||
.catch(error => console.error(error));
|
|
||||||
|
|
||||||
this.scene.physics.world.enableBody(this);
|
this.scene.physics.world.enableBody(this);
|
||||||
|
|
||||||
|
@ -71,8 +71,10 @@ export abstract class Character extends Container {
|
|||||||
this.playAnimation(direction, moving);
|
this.playAnimation(direction, moving);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addCompanion(name: string): void {
|
public addCompanion(name: string, texturePromise?: Promise<string>): void {
|
||||||
this.companion = new Companion(this.scene, this.x, this.y, name);
|
if (typeof texturePromise !== 'undefined') {
|
||||||
|
this.companion = new Companion(this.scene, this.x, this.y, name, texturePromise);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTextures(textures: string[], frame?: string | number): void {
|
public addTextures(textures: string[], frame?: string | number): void {
|
||||||
|
@ -18,7 +18,8 @@ export class RemotePlayer extends Character {
|
|||||||
texturesPromise: Promise<string[]>,
|
texturesPromise: Promise<string[]>,
|
||||||
direction: PlayerAnimationDirections,
|
direction: PlayerAnimationDirections,
|
||||||
moving: boolean,
|
moving: boolean,
|
||||||
companion: string|null
|
companion: string|null,
|
||||||
|
companionTexturePromise?: Promise<string>
|
||||||
) {
|
) {
|
||||||
super(Scene, x, y, texturesPromise, name, direction, moving, 1);
|
super(Scene, x, y, texturesPromise, name, direction, moving, 1);
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ export class RemotePlayer extends Character {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
|
||||||
if (typeof companion === 'string') {
|
if (typeof companion === 'string') {
|
||||||
this.addCompanion(companion);
|
this.addCompanion(companion, companionTexturePromise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ import FILE_LOAD_ERROR = Phaser.Loader.Events.FILE_LOAD_ERROR;
|
|||||||
import DOMElement = Phaser.GameObjects.DOMElement;
|
import DOMElement = Phaser.GameObjects.DOMElement;
|
||||||
import {Subscription} from "rxjs";
|
import {Subscription} from "rxjs";
|
||||||
import {worldFullMessageStream} from "../../Connexion/WorldFullMessageStream";
|
import {worldFullMessageStream} from "../../Connexion/WorldFullMessageStream";
|
||||||
|
import { lazyLoadCompanionResource } from "../Companion/CompanionTexturesLoadingManager";
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface|null,
|
initPosition: PointInterface|null,
|
||||||
@ -1024,7 +1025,8 @@ ${escapedMessage}
|
|||||||
PlayerAnimationDirections.Down,
|
PlayerAnimationDirections.Down,
|
||||||
false,
|
false,
|
||||||
this.userInputManager,
|
this.userInputManager,
|
||||||
this.companion
|
this.companion,
|
||||||
|
this.companion !== null ? lazyLoadCompanionResource(this.load, this.companion) : undefined
|
||||||
);
|
);
|
||||||
}catch (err){
|
}catch (err){
|
||||||
if(err instanceof TextureError) {
|
if(err instanceof TextureError) {
|
||||||
@ -1217,7 +1219,8 @@ ${escapedMessage}
|
|||||||
texturesPromise,
|
texturesPromise,
|
||||||
addPlayerData.position.direction as PlayerAnimationDirections,
|
addPlayerData.position.direction as PlayerAnimationDirections,
|
||||||
addPlayerData.position.moving,
|
addPlayerData.position.moving,
|
||||||
addPlayerData.companion
|
addPlayerData.companion,
|
||||||
|
addPlayerData.companion !== null ? lazyLoadCompanionResource(this.load, addPlayerData.companion) : undefined
|
||||||
);
|
);
|
||||||
this.MapPlayers.add(player);
|
this.MapPlayers.add(player);
|
||||||
this.MapPlayersByKey.set(player.userId, player);
|
this.MapPlayersByKey.set(player.userId, player);
|
||||||
|
@ -22,7 +22,8 @@ export class Player extends Character implements CurrentGamerInterface {
|
|||||||
direction: PlayerAnimationDirections,
|
direction: PlayerAnimationDirections,
|
||||||
moving: boolean,
|
moving: boolean,
|
||||||
private userInputManager: UserInputManager,
|
private userInputManager: UserInputManager,
|
||||||
companion: string|null
|
companion: string|null,
|
||||||
|
companionTexturePromise?: Promise<string>
|
||||||
) {
|
) {
|
||||||
super(Scene, x, y, texturesPromise, name, direction, moving, 1);
|
super(Scene, x, y, texturesPromise, name, direction, moving, 1);
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ export class Player extends Character implements CurrentGamerInterface {
|
|||||||
this.getBody().setImmovable(false);
|
this.getBody().setImmovable(false);
|
||||||
|
|
||||||
if (typeof companion === 'string') {
|
if (typeof companion === 'string') {
|
||||||
this.addCompanion(companion);
|
this.addCompanion(companion, companionTexturePromise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user