added isActivatable() method to implement through interface
This commit is contained in:
parent
2322f5f76d
commit
989897cb01
8 changed files with 32 additions and 247 deletions
|
@ -37,6 +37,7 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||
protected lastDirection: PlayerAnimationDirections = PlayerAnimationDirections.Down;
|
||||
//private teleportation: Sprite;
|
||||
private invisible: boolean;
|
||||
private clickable: boolean;
|
||||
public companion?: Companion;
|
||||
private emote: Phaser.GameObjects.DOMElement | null = null;
|
||||
private emoteTween: Phaser.Tweens.Tween | null = null;
|
||||
|
@ -62,6 +63,7 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||
this.scene = scene;
|
||||
this.playerName = name;
|
||||
this.invisible = true;
|
||||
this.clickable = false;
|
||||
|
||||
this.sprites = new Map<string, Sprite>();
|
||||
this._pictureStore = writable(undefined);
|
||||
|
@ -98,13 +100,7 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||
this.playerNameText.setOrigin(0.5).setDepth(DEPTH_INGAME_TEXT_INDEX);
|
||||
this.add(this.playerNameText);
|
||||
|
||||
if (isClickable) {
|
||||
this.setInteractive({
|
||||
hitArea: new Phaser.Geom.Circle(0, 0, interactiveRadius),
|
||||
hitAreaCallback: Phaser.Geom.Circle.Contains, //eslint-disable-line @typescript-eslint/unbound-method
|
||||
useHandCursor: true,
|
||||
});
|
||||
}
|
||||
this.setClickable(isClickable);
|
||||
|
||||
this.outlineColorStoreUnsubscribe = this.outlineColorStore.subscribe((color) => {
|
||||
if (color === undefined) {
|
||||
|
@ -135,6 +131,10 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||
}
|
||||
|
||||
public setClickable(clickable: boolean = true): void {
|
||||
if (this.clickable === clickable) {
|
||||
return;
|
||||
}
|
||||
this.clickable = clickable;
|
||||
if (clickable) {
|
||||
this.setInteractive({
|
||||
hitArea: new Phaser.Geom.Circle(0, 0, interactiveRadius),
|
||||
|
@ -146,6 +146,10 @@ export abstract class Character extends Container implements OutlineableInterfac
|
|||
this.disableInteractive();
|
||||
}
|
||||
|
||||
public isClickable() {
|
||||
return this.clickable;
|
||||
}
|
||||
|
||||
public getPosition(): { x: number, y: number } {
|
||||
return { x: this.x, y: this.y };
|
||||
}
|
||||
|
|
|
@ -61,6 +61,13 @@ export class RemotePlayer extends Character implements ActivatableInterface {
|
|||
});
|
||||
|
||||
this.bindEventHandlers();
|
||||
|
||||
this.registerActionsMenuAction({
|
||||
actionName: "ddd",
|
||||
callback: () => {
|
||||
console.log('ddd');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public updatePosition(position: PointInterface): void {
|
||||
|
@ -98,6 +105,10 @@ export class RemotePlayer extends Character implements ActivatableInterface {
|
|||
super.destroy();
|
||||
}
|
||||
|
||||
public isActivatable(): boolean {
|
||||
return this.isClickable();
|
||||
}
|
||||
|
||||
private updateIsClickable(): void {
|
||||
this.setClickable(this.registeredActions.length > 0);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
export interface ActivatableInterface {
|
||||
readonly activationRadius: number;
|
||||
isActivatable: () => boolean;
|
||||
activate: () => void;
|
||||
getPosition: () => { x: number, y: number };
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ export class ActivatablesManager {
|
|||
let closestObject: ActivatableInterface | undefined = undefined;
|
||||
|
||||
for (const [object, distance] of this.activatableObjectsDistances.entries()) {
|
||||
if (object.activationRadius > distance && shortestDistance > distance) {
|
||||
if (object.isActivatable() && object.activationRadius > distance && shortestDistance > distance) {
|
||||
shortestDistance = distance;
|
||||
closestObject = object;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,10 @@ export class ActionableItem implements ActivatableInterface{
|
|||
return this.sprite.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
||||
}
|
||||
|
||||
public isActivatable(): boolean {
|
||||
return this.isSelectable;
|
||||
}
|
||||
|
||||
public activate(): void {
|
||||
this.onActivateCallback(this);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,10 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
|
|||
public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {}
|
||||
|
||||
public handleSpaceKeyUpEvent(event: Event): Event {
|
||||
this.gameScene.getActivatablesManager().getSelectedActivatableObject()?.activate();
|
||||
const activatable = this.gameScene.getActivatablesManager().getSelectedActivatableObject();
|
||||
if (activatable && activatable.isActivatable()) {
|
||||
activatable.activate();
|
||||
}
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue