ran pretty on the front
This commit is contained in:
@@ -3,17 +3,23 @@
|
||||
* It has coordinates and an "activation radius"
|
||||
*/
|
||||
import Sprite = Phaser.GameObjects.Sprite;
|
||||
import type {GameScene} from "../Game/GameScene";
|
||||
import type { GameScene } from "../Game/GameScene";
|
||||
import type OutlinePipelinePlugin from "phaser3-rex-plugins/plugins/outlinepipeline-plugin.js";
|
||||
|
||||
type EventCallback = (state: unknown, parameters: unknown) => void;
|
||||
|
||||
export class ActionableItem {
|
||||
private readonly activationRadiusSquared : number;
|
||||
private readonly activationRadiusSquared: number;
|
||||
private isSelectable: boolean = false;
|
||||
private callbacks: Map<string, Array<EventCallback>> = new Map<string, Array<EventCallback>>();
|
||||
|
||||
public constructor(private id: number, private sprite: Sprite, private eventHandler: GameScene, private activationRadius: number, private onActivateCallback: (item: ActionableItem) => void) {
|
||||
public constructor(
|
||||
private id: number,
|
||||
private sprite: Sprite,
|
||||
private eventHandler: GameScene,
|
||||
private activationRadius: number,
|
||||
private onActivateCallback: (item: ActionableItem) => void
|
||||
) {
|
||||
this.activationRadiusSquared = activationRadius * activationRadius;
|
||||
}
|
||||
|
||||
@@ -25,8 +31,8 @@ export class ActionableItem {
|
||||
* Returns the square of the distance to the object center IF we are in item action range
|
||||
* OR null if we are out of range.
|
||||
*/
|
||||
public actionableDistance(x: number, y: number): number|null {
|
||||
const distanceSquared = (x - this.sprite.x)*(x - this.sprite.x) + (y - this.sprite.y)*(y - this.sprite.y);
|
||||
public actionableDistance(x: number, y: number): number | null {
|
||||
const distanceSquared = (x - this.sprite.x) * (x - this.sprite.x) + (y - this.sprite.y) * (y - this.sprite.y);
|
||||
if (distanceSquared < this.activationRadiusSquared) {
|
||||
return distanceSquared;
|
||||
} else {
|
||||
@@ -45,7 +51,7 @@ export class ActionableItem {
|
||||
|
||||
this.getOutlinePlugin()?.add(this.sprite, {
|
||||
thickness: 2,
|
||||
outlineColor: 0xffff00
|
||||
outlineColor: 0xffff00,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,8 +66,8 @@ export class ActionableItem {
|
||||
this.getOutlinePlugin()?.remove(this.sprite);
|
||||
}
|
||||
|
||||
private getOutlinePlugin(): OutlinePipelinePlugin|undefined {
|
||||
return this.sprite.scene.plugins.get('rexOutlinePipeline') as unknown as OutlinePipelinePlugin|undefined;
|
||||
private getOutlinePlugin(): OutlinePipelinePlugin | undefined {
|
||||
return this.sprite.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +84,7 @@ export class ActionableItem {
|
||||
}
|
||||
|
||||
public on(eventName: string, callback: EventCallback): void {
|
||||
let callbacksArray: Array<EventCallback>|undefined = this.callbacks.get(eventName);
|
||||
let callbacksArray: Array<EventCallback> | undefined = this.callbacks.get(eventName);
|
||||
if (callbacksArray === undefined) {
|
||||
callbacksArray = new Array<EventCallback>();
|
||||
this.callbacks.set(eventName, callbacksArray);
|
||||
|
||||
Reference in New Issue
Block a user