2021-09-05 18:36:22 +02:00
|
|
|
import { PlayerAnimationDirections, PlayerAnimationTypes } from "../Player/Animation";
|
|
|
|
import { SpeechBubble } from "./SpeechBubble";
|
2021-05-26 17:07:07 +02:00
|
|
|
import Text = Phaser.GameObjects.Text;
|
2020-07-28 17:43:33 +02:00
|
|
|
import Container = Phaser.GameObjects.Container;
|
|
|
|
import Sprite = Phaser.GameObjects.Sprite;
|
2021-11-09 18:10:55 +01:00
|
|
|
import DOMElement = Phaser.GameObjects.DOMElement;
|
2021-09-05 18:36:22 +02:00
|
|
|
import { TextureError } from "../../Exception/TextureError";
|
|
|
|
import { Companion } from "../Companion/Companion";
|
|
|
|
import type { GameScene } from "../Game/GameScene";
|
|
|
|
import { DEPTH_INGAME_TEXT_INDEX } from "../Game/DepthIndexes";
|
2021-06-22 17:15:18 +02:00
|
|
|
import type OutlinePipelinePlugin from "phaser3-rex-plugins/plugins/outlinepipeline-plugin.js";
|
2021-09-05 18:36:22 +02:00
|
|
|
import { isSilentStore } from "../../Stores/MediaStore";
|
2022-03-11 17:02:58 +01:00
|
|
|
import { lazyLoadPlayerCharacterTextures } from "./PlayerTexturesLoadingManager";
|
2021-12-10 12:02:14 +01:00
|
|
|
import { TexturesHelper } from "../Helpers/TexturesHelper";
|
2021-12-14 14:46:24 +01:00
|
|
|
import type { PictureStore } from "../../Stores/PictureStore";
|
2021-12-21 17:02:18 +01:00
|
|
|
import { Unsubscriber, Writable, writable } from "svelte/store";
|
|
|
|
import { createColorStore } from "../../Stores/OutlineColorStore";
|
2022-02-02 13:30:49 +01:00
|
|
|
import type { OutlineableInterface } from "../Game/OutlineableInterface";
|
2022-02-01 11:44:39 +01:00
|
|
|
import type CancelablePromise from "cancelable-promise";
|
2022-02-07 15:09:18 +01:00
|
|
|
import { TalkIcon } from "../Components/TalkIcon";
|
2022-03-15 11:21:48 +01:00
|
|
|
import { Deferred } from "ts-deferred";
|
2021-03-31 11:21:06 +02:00
|
|
|
|
2021-09-05 18:36:22 +02:00
|
|
|
const playerNameY = -25;
|
2020-04-12 16:12:08 +02:00
|
|
|
|
2020-06-04 18:54:34 +02:00
|
|
|
interface AnimationData {
|
|
|
|
key: string;
|
|
|
|
frameRate: number;
|
|
|
|
repeat: number;
|
|
|
|
frameModel: string; //todo use an enum
|
2021-09-05 18:36:22 +02:00
|
|
|
frames: number[];
|
2020-06-04 18:54:34 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 18:08:53 +02:00
|
|
|
const interactiveRadius = 35;
|
2021-05-10 17:10:41 +02:00
|
|
|
|
2022-01-26 14:59:23 +01:00
|
|
|
export abstract class Character extends Container implements OutlineableInterface {
|
2021-09-05 18:36:22 +02:00
|
|
|
private bubble: SpeechBubble | null = null;
|
2022-01-26 10:54:51 +01:00
|
|
|
private readonly playerNameText: Text;
|
2022-02-03 16:00:29 +01:00
|
|
|
private readonly talkIcon: TalkIcon;
|
2022-01-26 10:54:51 +01:00
|
|
|
public playerName: string;
|
2020-07-28 17:43:33 +02:00
|
|
|
public sprites: Map<string, Sprite>;
|
2021-12-14 18:47:51 +01:00
|
|
|
protected lastDirection: PlayerAnimationDirections = PlayerAnimationDirections.Down;
|
2020-10-12 11:22:41 +02:00
|
|
|
//private teleportation: Sprite;
|
2021-01-07 17:11:22 +01:00
|
|
|
private invisible: boolean;
|
2022-01-31 13:00:14 +01:00
|
|
|
private clickable: boolean;
|
2021-04-01 18:51:51 +02:00
|
|
|
public companion?: Companion;
|
2021-11-09 18:10:55 +01:00
|
|
|
private emote: Phaser.GameObjects.DOMElement | null = null;
|
2021-09-05 18:36:22 +02:00
|
|
|
private emoteTween: Phaser.Tweens.Tween | null = null;
|
2021-06-22 17:15:18 +02:00
|
|
|
scene: GameScene;
|
2021-12-14 14:46:24 +01:00
|
|
|
private readonly _pictureStore: Writable<string | undefined>;
|
2021-12-21 17:02:18 +01:00
|
|
|
private readonly outlineColorStore = createColorStore();
|
|
|
|
private readonly outlineColorStoreUnsubscribe: Unsubscriber;
|
2022-02-01 11:44:39 +01:00
|
|
|
private texturePromise: CancelablePromise<string[] | void> | undefined;
|
2020-04-12 16:12:08 +02:00
|
|
|
|
2022-03-15 11:21:48 +01:00
|
|
|
/**
|
|
|
|
* A deferred promise that resolves when the texture of the character is actually displayed.
|
|
|
|
*/
|
|
|
|
private textureLoadedDeferred = new Deferred<void>();
|
|
|
|
|
2021-09-05 18:36:22 +02:00
|
|
|
constructor(
|
|
|
|
scene: GameScene,
|
|
|
|
x: number,
|
|
|
|
y: number,
|
2022-02-01 11:44:39 +01:00
|
|
|
texturesPromise: CancelablePromise<string[]>,
|
2021-09-05 18:36:22 +02:00
|
|
|
name: string,
|
|
|
|
direction: PlayerAnimationDirections,
|
|
|
|
moving: boolean,
|
|
|
|
frame: string | number,
|
|
|
|
isClickable: boolean,
|
|
|
|
companion: string | null,
|
2022-02-02 11:10:52 +01:00
|
|
|
companionTexturePromise?: CancelablePromise<string>
|
2020-06-04 18:54:34 +02:00
|
|
|
) {
|
2021-09-05 18:36:22 +02:00
|
|
|
super(scene, x, y /*, texture, frame*/);
|
2021-06-22 17:15:18 +02:00
|
|
|
this.scene = scene;
|
2022-01-26 10:54:51 +01:00
|
|
|
this.playerName = name;
|
2021-09-05 18:36:22 +02:00
|
|
|
this.invisible = true;
|
2022-01-31 13:00:14 +01:00
|
|
|
this.clickable = false;
|
2020-07-28 17:43:33 +02:00
|
|
|
|
|
|
|
this.sprites = new Map<string, Sprite>();
|
2021-12-14 14:46:24 +01:00
|
|
|
this._pictureStore = writable(undefined);
|
2020-07-28 17:43:33 +02:00
|
|
|
|
2021-01-07 17:11:22 +01:00
|
|
|
//textures are inside a Promise in case they need to be lazyloaded before use.
|
2022-02-01 11:44:39 +01:00
|
|
|
this.texturePromise = texturesPromise
|
2021-09-21 14:24:15 +02:00
|
|
|
.then((textures) => {
|
|
|
|
this.addTextures(textures, frame);
|
|
|
|
this.invisible = false;
|
2021-10-15 16:14:48 +02:00
|
|
|
this.playAnimation(direction, moving);
|
2022-03-15 11:21:48 +01:00
|
|
|
this.textureLoadedDeferred.resolve();
|
2021-12-14 14:46:24 +01:00
|
|
|
return this.getSnapshot().then((htmlImageElementSrc) => {
|
|
|
|
this._pictureStore.set(htmlImageElementSrc);
|
|
|
|
});
|
2021-09-21 14:24:15 +02:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2022-03-18 10:56:20 +01:00
|
|
|
return lazyLoadPlayerCharacterTextures(scene.superLoad, [
|
2022-03-11 17:02:58 +01:00
|
|
|
{
|
|
|
|
id: "color_22",
|
|
|
|
img: "resources/customisation/character_color/character_color21.png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "eyes_23",
|
|
|
|
img: "resources/customisation/character_eyes/character_eyes23.png",
|
|
|
|
},
|
2022-03-15 11:21:48 +01:00
|
|
|
])
|
|
|
|
.then((textures) => {
|
|
|
|
this.addTextures(textures, frame);
|
|
|
|
this.invisible = false;
|
|
|
|
this.playAnimation(direction, moving);
|
|
|
|
this.textureLoadedDeferred.resolve();
|
|
|
|
return this.getSnapshot().then((htmlImageElementSrc) => {
|
|
|
|
this._pictureStore.set(htmlImageElementSrc);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
this.textureLoadedDeferred.reject(e);
|
|
|
|
throw e;
|
|
|
|
});
|
2022-02-01 11:44:39 +01:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.texturePromise = undefined;
|
2021-09-21 14:24:15 +02:00
|
|
|
});
|
2021-06-14 16:40:33 +02:00
|
|
|
|
2022-01-26 10:54:51 +01:00
|
|
|
this.playerNameText = new Text(scene, 0, playerNameY, name, {
|
2021-09-05 18:36:22 +02:00
|
|
|
fontFamily: '"Press Start 2P"',
|
|
|
|
fontSize: "8px",
|
|
|
|
strokeThickness: 2,
|
2022-02-21 01:09:53 +01:00
|
|
|
stroke: "#14304C",
|
2022-01-24 16:55:58 +01:00
|
|
|
metrics: {
|
|
|
|
ascent: 20,
|
|
|
|
descent: 10,
|
|
|
|
fontSize: 35,
|
|
|
|
},
|
2021-09-05 18:36:22 +02:00
|
|
|
});
|
2020-05-01 23:38:09 +02:00
|
|
|
|
2022-02-03 16:00:29 +01:00
|
|
|
this.talkIcon = new TalkIcon(scene, 0, -45);
|
|
|
|
this.add(this.talkIcon);
|
2022-02-01 12:25:14 +01:00
|
|
|
|
2021-06-08 16:30:58 +02:00
|
|
|
if (isClickable) {
|
2021-05-10 17:10:41 +02:00
|
|
|
this.setInteractive({
|
|
|
|
hitArea: new Phaser.Geom.Circle(0, 0, interactiveRadius),
|
|
|
|
hitAreaCallback: Phaser.Geom.Circle.Contains, //eslint-disable-line @typescript-eslint/unbound-method
|
|
|
|
useHandCursor: true,
|
|
|
|
});
|
|
|
|
}
|
2022-01-26 10:54:51 +01:00
|
|
|
this.playerNameText.setOrigin(0.5).setDepth(DEPTH_INGAME_TEXT_INDEX);
|
|
|
|
this.add(this.playerNameText);
|
2020-05-01 23:38:09 +02:00
|
|
|
|
2022-01-31 13:00:14 +01:00
|
|
|
this.setClickable(isClickable);
|
2021-05-10 17:10:41 +02:00
|
|
|
|
2021-12-21 17:02:18 +01:00
|
|
|
this.outlineColorStoreUnsubscribe = this.outlineColorStore.subscribe((color) => {
|
|
|
|
if (color === undefined) {
|
2022-01-26 10:54:51 +01:00
|
|
|
this.getOutlinePlugin()?.remove(this.playerNameText);
|
2021-12-21 17:02:18 +01:00
|
|
|
} else {
|
2022-01-26 10:54:51 +01:00
|
|
|
this.getOutlinePlugin()?.remove(this.playerNameText);
|
|
|
|
this.getOutlinePlugin()?.add(this.playerNameText, {
|
2021-12-21 17:02:18 +01:00
|
|
|
thickness: 2,
|
|
|
|
outlineColor: color,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.scene.markDirty();
|
|
|
|
});
|
|
|
|
|
2020-07-28 17:43:33 +02:00
|
|
|
scene.add.existing(this);
|
|
|
|
|
2020-04-13 13:42:21 +02:00
|
|
|
this.scene.physics.world.enableBody(this);
|
2020-07-28 17:43:33 +02:00
|
|
|
this.getBody().setImmovable(true);
|
|
|
|
this.getBody().setCollideWorldBounds(true);
|
|
|
|
this.setSize(16, 16);
|
|
|
|
this.getBody().setSize(16, 16); //edit the hitbox to better match the character model
|
|
|
|
this.getBody().setOffset(0, 8);
|
2021-10-14 17:32:27 +02:00
|
|
|
this.setDepth(0);
|
2020-05-12 11:49:55 +02:00
|
|
|
|
2021-09-05 18:36:22 +02:00
|
|
|
if (typeof companion === "string") {
|
2021-05-10 17:10:41 +02:00
|
|
|
this.addCompanion(companion, companionTexturePromise);
|
|
|
|
}
|
2021-04-01 18:51:51 +02:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:26:37 +01:00
|
|
|
public setClickable(clickable: boolean = true): void {
|
2022-01-31 13:00:14 +01:00
|
|
|
if (this.clickable === clickable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.clickable = clickable;
|
2022-01-31 12:26:37 +01:00
|
|
|
if (clickable) {
|
|
|
|
this.setInteractive({
|
2022-02-03 10:13:17 +01:00
|
|
|
hitArea: new Phaser.Geom.Circle(8, 8, interactiveRadius),
|
2022-01-31 12:26:37 +01:00
|
|
|
hitAreaCallback: Phaser.Geom.Circle.Contains, //eslint-disable-line @typescript-eslint/unbound-method
|
|
|
|
useHandCursor: true,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.disableInteractive();
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:00:14 +01:00
|
|
|
public isClickable() {
|
|
|
|
return this.clickable;
|
|
|
|
}
|
|
|
|
|
2022-02-02 13:30:49 +01:00
|
|
|
public getPosition(): { x: number; y: number } {
|
2022-01-26 12:57:10 +01:00
|
|
|
return { x: this.x, y: this.y };
|
|
|
|
}
|
|
|
|
|
2022-02-07 11:08:52 +01:00
|
|
|
/**
|
|
|
|
* Returns position based on where player is currently facing
|
|
|
|
* @param shift How far from player should the point of interest be.
|
|
|
|
*/
|
2022-02-07 14:23:34 +01:00
|
|
|
public getDirectionalActivationPosition(shift: number): { x: number; y: number } {
|
2022-02-07 11:08:52 +01:00
|
|
|
switch (this.lastDirection) {
|
2022-02-07 14:23:34 +01:00
|
|
|
case PlayerAnimationDirections.Down: {
|
|
|
|
return { x: this.x, y: this.y + shift };
|
|
|
|
}
|
|
|
|
case PlayerAnimationDirections.Left: {
|
|
|
|
return { x: this.x - shift, y: this.y };
|
|
|
|
}
|
|
|
|
case PlayerAnimationDirections.Right: {
|
|
|
|
return { x: this.x + shift, y: this.y };
|
|
|
|
}
|
|
|
|
case PlayerAnimationDirections.Up: {
|
|
|
|
return { x: this.x, y: this.y - shift };
|
|
|
|
}
|
2022-02-07 11:08:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 14:59:23 +01:00
|
|
|
public getObjectToOutline(): Phaser.GameObjects.GameObject {
|
|
|
|
return this.playerNameText;
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:46:24 +01:00
|
|
|
private async getSnapshot(): Promise<string> {
|
2021-12-10 12:02:14 +01:00
|
|
|
const sprites = Array.from(this.sprites.values()).map((sprite) => {
|
|
|
|
return { sprite, frame: 1 };
|
|
|
|
});
|
|
|
|
return TexturesHelper.getSnapshot(this.scene, ...sprites).catch((reason) => {
|
|
|
|
console.warn(reason);
|
2021-12-04 16:29:28 +01:00
|
|
|
for (const sprite of this.sprites.values()) {
|
|
|
|
// we can be sure that either predefined woka or body texture is at this point loaded
|
|
|
|
if (sprite.texture.key.includes("color") || sprite.texture.key.includes("male")) {
|
|
|
|
return this.scene.textures.getBase64(sprite.texture.key);
|
|
|
|
}
|
|
|
|
}
|
2021-12-10 12:02:14 +01:00
|
|
|
return "male1";
|
2021-11-29 20:39:09 +01:00
|
|
|
});
|
2021-06-22 17:15:18 +02:00
|
|
|
}
|
|
|
|
|
2022-02-16 15:55:07 +01:00
|
|
|
public showTalkIcon(show: boolean = true, forceClose: boolean = false): void {
|
|
|
|
this.talkIcon.show(show, forceClose);
|
2022-02-01 12:25:14 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 11:10:52 +01:00
|
|
|
public addCompanion(name: string, texturePromise?: CancelablePromise<string>): void {
|
2021-09-05 18:36:22 +02:00
|
|
|
if (typeof texturePromise !== "undefined") {
|
2021-04-06 19:10:18 +02:00
|
|
|
this.companion = new Companion(this.scene, this.x, this.y, name, texturePromise);
|
|
|
|
}
|
2020-06-04 18:54:34 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 16:39:23 +02:00
|
|
|
public addTextures(textures: string[], frame?: string | number): void {
|
2021-11-24 15:43:01 +01:00
|
|
|
if (textures.length < 1) {
|
|
|
|
throw new TextureError("no texture given");
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:39:23 +02:00
|
|
|
for (const texture of textures) {
|
2021-09-05 18:36:22 +02:00
|
|
|
if (this.scene && !this.scene.textures.exists(texture)) {
|
|
|
|
throw new TextureError("texture not found");
|
2020-12-18 14:30:46 +01:00
|
|
|
}
|
2020-10-20 16:39:23 +02:00
|
|
|
const sprite = new Sprite(this.scene, 0, 0, texture, frame);
|
|
|
|
this.add(sprite);
|
2021-09-05 18:36:22 +02:00
|
|
|
this.getPlayerAnimations(texture).forEach((d) => {
|
2020-10-20 16:39:23 +02:00
|
|
|
this.scene.anims.create({
|
|
|
|
key: d.key,
|
2021-09-05 18:36:22 +02:00
|
|
|
frames: this.scene.anims.generateFrameNumbers(d.frameModel, { frames: d.frames }),
|
2020-10-20 16:39:23 +02:00
|
|
|
frameRate: d.frameRate,
|
2021-09-05 18:36:22 +02:00
|
|
|
repeat: d.repeat,
|
2020-10-20 16:39:23 +02:00
|
|
|
});
|
2021-09-05 18:36:22 +02:00
|
|
|
});
|
2020-10-20 16:39:23 +02:00
|
|
|
// Needed, otherwise, animations are not handled correctly.
|
2021-09-05 18:36:22 +02:00
|
|
|
if (this.scene) {
|
2020-12-18 13:56:25 +01:00
|
|
|
this.scene.sys.updateList.add(sprite);
|
|
|
|
}
|
2020-10-20 16:39:23 +02:00
|
|
|
this.sprites.set(texture, sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-26 17:25:32 +01:00
|
|
|
private getOutlinePlugin(): OutlinePipelinePlugin | undefined {
|
|
|
|
return this.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:54:34 +02:00
|
|
|
private getPlayerAnimations(name: string): AnimationData[] {
|
2021-09-05 18:36:22 +02:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Down}-${PlayerAnimationTypes.Walk}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [0, 1, 2, 1],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Left}-${PlayerAnimationTypes.Walk}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [3, 4, 5, 4],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Right}-${PlayerAnimationTypes.Walk}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [6, 7, 8, 7],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Up}-${PlayerAnimationTypes.Walk}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [9, 10, 11, 10],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Down}-${PlayerAnimationTypes.Idle}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [1],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Left}-${PlayerAnimationTypes.Idle}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [4],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Right}-${PlayerAnimationTypes.Idle}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [7],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: `${name}-${PlayerAnimationDirections.Up}-${PlayerAnimationTypes.Idle}`,
|
|
|
|
frameModel: name,
|
|
|
|
frames: [10],
|
|
|
|
frameRate: 10,
|
|
|
|
repeat: 1,
|
|
|
|
},
|
|
|
|
];
|
2020-06-04 18:54:34 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 18:36:22 +02:00
|
|
|
protected playAnimation(direction: PlayerAnimationDirections, moving: boolean): void {
|
2021-01-07 17:11:22 +01:00
|
|
|
if (this.invisible) return;
|
2020-07-28 17:43:33 +02:00
|
|
|
for (const [texture, sprite] of this.sprites.entries()) {
|
|
|
|
if (!sprite.anims) {
|
2021-09-05 18:36:22 +02:00
|
|
|
console.error("ANIMS IS NOT DEFINED!!!");
|
2020-07-28 17:43:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (moving && (!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== direction)) {
|
2021-09-05 18:36:22 +02:00
|
|
|
sprite.play(texture + "-" + direction + "-" + PlayerAnimationTypes.Walk, true);
|
2020-07-28 17:43:33 +02:00
|
|
|
} else if (!moving) {
|
2021-09-05 18:36:22 +02:00
|
|
|
sprite.anims.play(texture + "-" + direction + "-" + PlayerAnimationTypes.Idle, true);
|
2020-07-28 17:43:33 +02:00
|
|
|
}
|
2020-06-10 15:43:22 +02:00
|
|
|
}
|
2020-07-28 17:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected getBody(): Phaser.Physics.Arcade.Body {
|
|
|
|
const body = this.body;
|
|
|
|
if (!(body instanceof Phaser.Physics.Arcade.Body)) {
|
2021-09-05 18:36:22 +02:00
|
|
|
throw new Error("Container does not have arcade body");
|
2020-06-04 18:54:34 +02:00
|
|
|
}
|
2020-07-28 17:43:33 +02:00
|
|
|
return body;
|
2020-04-12 16:12:08 +02:00
|
|
|
}
|
2020-04-12 19:06:31 +02:00
|
|
|
|
2020-05-06 01:50:01 +02:00
|
|
|
move(x: number, y: number) {
|
2020-07-28 17:43:33 +02:00
|
|
|
const body = this.getBody();
|
2020-04-12 19:06:31 +02:00
|
|
|
|
2020-07-28 17:43:33 +02:00
|
|
|
body.setVelocity(x, y);
|
2020-04-12 19:06:31 +02:00
|
|
|
|
2021-12-14 18:47:51 +01:00
|
|
|
if (Math.abs(body.velocity.x) > Math.abs(body.velocity.y)) {
|
|
|
|
if (body.velocity.x < 0) {
|
|
|
|
this.lastDirection = PlayerAnimationDirections.Left;
|
|
|
|
} else if (body.velocity.x > 0) {
|
|
|
|
this.lastDirection = PlayerAnimationDirections.Right;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (body.velocity.y < 0) {
|
|
|
|
this.lastDirection = PlayerAnimationDirections.Up;
|
|
|
|
} else if (body.velocity.y > 0) {
|
|
|
|
this.lastDirection = PlayerAnimationDirections.Down;
|
|
|
|
}
|
2020-04-13 15:15:20 +02:00
|
|
|
}
|
2021-12-14 18:47:51 +01:00
|
|
|
this.playAnimation(this.lastDirection, true);
|
2020-05-08 17:35:40 +02:00
|
|
|
|
|
|
|
this.setDepth(this.y);
|
2021-04-01 18:51:51 +02:00
|
|
|
|
|
|
|
if (this.companion) {
|
|
|
|
this.companion.setTarget(this.x, this.y, this.lastDirection);
|
|
|
|
}
|
2020-05-03 22:24:14 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 18:36:22 +02:00
|
|
|
stop() {
|
2020-07-28 17:43:33 +02:00
|
|
|
this.getBody().setVelocity(0, 0);
|
|
|
|
this.playAnimation(this.lastDirection, false);
|
2020-04-13 15:41:11 +02:00
|
|
|
}
|
2020-04-27 18:12:36 +02:00
|
|
|
|
2020-04-12 19:35:51 +02:00
|
|
|
say(text: string) {
|
|
|
|
if (this.bubble) return;
|
2021-09-05 18:36:22 +02:00
|
|
|
this.bubble = new SpeechBubble(this.scene, this, text);
|
2020-04-12 19:35:51 +02:00
|
|
|
setTimeout(() => {
|
2020-06-04 18:11:07 +02:00
|
|
|
if (this.bubble !== null) {
|
|
|
|
this.bubble.destroy();
|
|
|
|
this.bubble = null;
|
|
|
|
}
|
2021-09-05 18:36:22 +02:00
|
|
|
}, 3000);
|
2020-04-12 19:35:51 +02:00
|
|
|
}
|
2020-05-03 22:24:14 +02:00
|
|
|
|
2021-01-06 15:00:54 +01:00
|
|
|
destroy(): void {
|
2020-07-29 11:40:05 +02:00
|
|
|
for (const sprite of this.sprites.values()) {
|
2021-09-05 18:36:22 +02:00
|
|
|
if (this.scene) {
|
2020-12-18 13:56:25 +01:00
|
|
|
this.scene.sys.updateList.remove(sprite);
|
|
|
|
}
|
2020-07-29 11:40:05 +02:00
|
|
|
}
|
2022-02-01 11:44:39 +01:00
|
|
|
this.texturePromise?.cancel();
|
2021-09-05 18:36:22 +02:00
|
|
|
this.list.forEach((objectContaining) => objectContaining.destroy());
|
2021-12-21 17:02:18 +01:00
|
|
|
this.outlineColorStoreUnsubscribe();
|
2021-01-06 15:00:54 +01:00
|
|
|
super.destroy();
|
2021-03-31 11:21:06 +02:00
|
|
|
}
|
2021-06-14 16:40:33 +02:00
|
|
|
|
2021-09-10 16:57:21 +02:00
|
|
|
isSilent() {
|
|
|
|
isSilentStore.set(true);
|
|
|
|
}
|
|
|
|
noSilent() {
|
|
|
|
isSilentStore.set(false);
|
|
|
|
}
|
|
|
|
|
2021-06-29 08:37:01 +02:00
|
|
|
playEmote(emote: string) {
|
2021-05-10 17:10:41 +02:00
|
|
|
this.cancelPreviousEmote();
|
2021-09-10 16:57:21 +02:00
|
|
|
const emoteY = -45;
|
2021-11-09 18:10:55 +01:00
|
|
|
const image = new Image(16, 16);
|
|
|
|
image.src = emote;
|
|
|
|
this.emote = new DOMElement(this.scene, -1, 0, image, "z-index:10;");
|
2021-05-21 16:25:12 +02:00
|
|
|
this.emote.setAlpha(0);
|
2021-03-31 11:21:06 +02:00
|
|
|
this.add(this.emote);
|
2021-09-10 16:57:21 +02:00
|
|
|
this.createStartTransition(emoteY);
|
2021-05-21 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 16:57:21 +02:00
|
|
|
private createStartTransition(emoteY: number) {
|
2021-06-07 15:11:54 +02:00
|
|
|
this.emoteTween = this.scene?.tweens.add({
|
2021-05-21 16:25:12 +02:00
|
|
|
targets: this.emote,
|
|
|
|
props: {
|
|
|
|
alpha: 1,
|
|
|
|
y: emoteY,
|
|
|
|
},
|
2021-09-05 18:36:22 +02:00
|
|
|
ease: "Power2",
|
2021-05-21 16:25:12 +02:00
|
|
|
duration: 500,
|
|
|
|
onComplete: () => {
|
2021-09-10 16:57:21 +02:00
|
|
|
this.startPulseTransition(emoteY);
|
2021-09-05 18:36:22 +02:00
|
|
|
},
|
2021-05-21 16:25:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-10 16:57:21 +02:00
|
|
|
private startPulseTransition(emoteY: number) {
|
|
|
|
if (this.emote) {
|
|
|
|
this.emoteTween = this.scene?.tweens.add({
|
|
|
|
targets: this.emote,
|
|
|
|
props: {
|
|
|
|
y: emoteY * 1.3,
|
|
|
|
scale: this.emote.scale * 1.1,
|
|
|
|
},
|
|
|
|
duration: 250,
|
|
|
|
yoyo: true,
|
|
|
|
repeat: 1,
|
|
|
|
completeDelay: 200,
|
|
|
|
onComplete: () => {
|
|
|
|
this.startExitTransition(emoteY);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-05-21 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private startExitTransition(emoteY: number) {
|
2021-06-07 15:11:54 +02:00
|
|
|
this.emoteTween = this.scene?.tweens.add({
|
2021-05-21 16:25:12 +02:00
|
|
|
targets: this.emote,
|
|
|
|
props: {
|
|
|
|
alpha: 0,
|
|
|
|
y: 2 * emoteY,
|
|
|
|
},
|
2021-09-05 18:36:22 +02:00
|
|
|
ease: "Power2",
|
2021-05-21 16:25:12 +02:00
|
|
|
duration: 500,
|
|
|
|
onComplete: () => {
|
|
|
|
this.destroyEmote();
|
2021-09-05 18:36:22 +02:00
|
|
|
},
|
2021-03-31 11:21:06 +02:00
|
|
|
});
|
2020-05-03 22:24:14 +02:00
|
|
|
}
|
2021-05-10 17:10:41 +02:00
|
|
|
|
|
|
|
cancelPreviousEmote() {
|
|
|
|
if (!this.emote) return;
|
|
|
|
|
2021-05-21 16:25:12 +02:00
|
|
|
this.emoteTween?.remove();
|
2021-09-05 18:36:22 +02:00
|
|
|
this.destroyEmote();
|
2021-05-21 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private destroyEmote() {
|
2021-05-10 17:10:41 +02:00
|
|
|
this.emote?.destroy();
|
|
|
|
this.emote = null;
|
2022-01-26 10:54:51 +01:00
|
|
|
this.playerNameText.setVisible(true);
|
2021-05-10 17:10:41 +02:00
|
|
|
}
|
2021-12-14 14:46:24 +01:00
|
|
|
|
|
|
|
public get pictureStore(): PictureStore {
|
|
|
|
return this._pictureStore;
|
|
|
|
}
|
2021-12-21 17:02:18 +01:00
|
|
|
|
2022-01-27 14:05:30 +01:00
|
|
|
public setFollowOutlineColor(color: number): void {
|
|
|
|
this.outlineColorStore.setFollowColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeFollowOutlineColor(): void {
|
|
|
|
this.outlineColorStore.removeFollowColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public setApiOutlineColor(color: number): void {
|
|
|
|
this.outlineColorStore.setApiColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeApiOutlineColor(): void {
|
|
|
|
this.outlineColorStore.removeApiColor();
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:39:03 +01:00
|
|
|
public pointerOverOutline(color: number): void {
|
|
|
|
this.outlineColorStore.pointerOver(color);
|
2022-01-27 14:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public pointerOutOutline(): void {
|
|
|
|
this.outlineColorStore.pointerOut();
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:39:03 +01:00
|
|
|
public characterCloseByOutline(color: number): void {
|
|
|
|
this.outlineColorStore.characterCloseBy(color);
|
2021-12-21 17:02:18 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 14:05:30 +01:00
|
|
|
public characterFarAwayOutline(): void {
|
|
|
|
this.outlineColorStore.characterFarAway();
|
2021-12-21 17:02:18 +01:00
|
|
|
}
|
2022-03-15 11:21:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a promise that resolves as soon as a texture is displayed for the user.
|
|
|
|
* The promise will return when the required texture is loaded OR when the fallback texture is loaded (in case
|
|
|
|
* the required texture could not be loaded).
|
|
|
|
*/
|
|
|
|
public getTextureLoadedPromise(): PromiseLike<void> {
|
|
|
|
return this.textureLoadedDeferred.promise;
|
|
|
|
}
|
2020-04-27 18:12:36 +02:00
|
|
|
}
|