changing the way Outline is handled
This commit is contained in:
parent
f42c7564b9
commit
dbd06bda4e
6 changed files with 78 additions and 7 deletions
5
front/src/Utils/CustomTypeGuards.ts
Normal file
5
front/src/Utils/CustomTypeGuards.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type { OutlineableInterface } from '../Phaser/Game/OutlineableInterface';
|
||||
|
||||
export function isOutlineable(object: unknown): object is OutlineableInterface {
|
||||
return (object as unknown as OutlineableInterface)?.getObjectToOutline() !== undefined;
|
||||
}
|
34
front/src/Utils/OutlineManager.ts
Normal file
34
front/src/Utils/OutlineManager.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import type OutlinePipelinePlugin from 'phaser3-rex-plugins/plugins/outlinepipeline-plugin.js';
|
||||
import { isOutlineable } from './CustomTypeGuards';
|
||||
|
||||
export interface OutlineConfig {
|
||||
thickness: number;
|
||||
outlineColor: number;
|
||||
}
|
||||
|
||||
export class OutlineManager {
|
||||
|
||||
private scene: Phaser.Scene;
|
||||
|
||||
private outlinePlugin?: OutlinePipelinePlugin
|
||||
|
||||
constructor(scene: Phaser.Scene) {
|
||||
this.scene = scene;
|
||||
this.outlinePlugin =
|
||||
this.scene.plugins.get("rexOutlinePipeline") as unknown as OutlinePipelinePlugin | undefined;
|
||||
}
|
||||
|
||||
public tryAddOutline(object: unknown): void {
|
||||
if (!isOutlineable(object)) {
|
||||
return;
|
||||
}
|
||||
this.outlinePlugin?.add(object.getObjectToOutline(), object.getOutlineConfig());
|
||||
}
|
||||
|
||||
public tryRemoveOutline(object: unknown): void {
|
||||
if (!isOutlineable(object)) {
|
||||
return;
|
||||
}
|
||||
this.outlinePlugin?.remove(object.getObjectToOutline());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue