From 5ae039b9877b087e4af3df9b75ee011d8de3f43c Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 26 Jan 2022 10:54:51 +0100 Subject: [PATCH] little cleanup --- .../Components/FollowMenu/FollowMenu.svelte | 2 +- front/src/Phaser/Entity/Character.ts | 20 +++---- front/src/Phaser/Entity/RemotePlayer.ts | 52 ++++++++++++------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/front/src/Components/FollowMenu/FollowMenu.svelte b/front/src/Components/FollowMenu/FollowMenu.svelte index 2f50f4ea..b063ca16 100644 --- a/front/src/Components/FollowMenu/FollowMenu.svelte +++ b/front/src/Components/FollowMenu/FollowMenu.svelte @@ -11,7 +11,7 @@ vim: ft=typescript function name(userId: number): string { const user = gameScene.MapPlayersByKey.get(userId); - return user ? user.PlayerValue : ""; + return user ? user.playerName : ""; } function sendFollowRequest() { diff --git a/front/src/Phaser/Entity/Character.ts b/front/src/Phaser/Entity/Character.ts index e1fd3a5a..b9b23207 100644 --- a/front/src/Phaser/Entity/Character.ts +++ b/front/src/Phaser/Entity/Character.ts @@ -30,8 +30,8 @@ const interactiveRadius = 35; export abstract class Character extends Container { private bubble: SpeechBubble | null = null; - private readonly playerName: Text; - public PlayerValue: string; + private readonly playerNameText: Text; + public playerName: string; public sprites: Map; protected lastDirection: PlayerAnimationDirections = PlayerAnimationDirections.Down; //private teleportation: Sprite; @@ -59,7 +59,7 @@ export abstract class Character extends Container { ) { super(scene, x, y /*, texture, frame*/); this.scene = scene; - this.PlayerValue = name; + this.playerName = name; this.invisible = true; this.sprites = new Map(); @@ -83,7 +83,7 @@ export abstract class Character extends Container { }); }); - this.playerName = new Text(scene, 0, playerNameY, name, { + this.playerNameText = new Text(scene, 0, playerNameY, name, { fontFamily: '"Press Start 2P"', fontSize: "8px", strokeThickness: 2, @@ -94,8 +94,8 @@ export abstract class Character extends Container { fontSize: 35, }, }); - this.playerName.setOrigin(0.5).setDepth(DEPTH_INGAME_TEXT_INDEX); - this.add(this.playerName); + this.playerNameText.setOrigin(0.5).setDepth(DEPTH_INGAME_TEXT_INDEX); + this.add(this.playerNameText); if (isClickable) { this.setInteractive({ @@ -114,10 +114,10 @@ export abstract class Character extends Container { this.outlineColorStoreUnsubscribe = this.outlineColorStore.subscribe((color) => { if (color === undefined) { - this.getOutlinePlugin()?.remove(this.playerName); + this.getOutlinePlugin()?.remove(this.playerNameText); } else { - this.getOutlinePlugin()?.remove(this.playerName); - this.getOutlinePlugin()?.add(this.playerName, { + this.getOutlinePlugin()?.remove(this.playerNameText); + this.getOutlinePlugin()?.add(this.playerNameText, { thickness: 2, outlineColor: color, }); @@ -408,7 +408,7 @@ export abstract class Character extends Container { private destroyEmote() { this.emote?.destroy(); this.emote = null; - this.playerName.setVisible(true); + this.playerNameText.setVisible(true); } public get pictureStore(): PictureStore { diff --git a/front/src/Phaser/Entity/RemotePlayer.ts b/front/src/Phaser/Entity/RemotePlayer.ts index 7012ea3b..e04fcf7e 100644 --- a/front/src/Phaser/Entity/RemotePlayer.ts +++ b/front/src/Phaser/Entity/RemotePlayer.ts @@ -57,24 +57,10 @@ export class RemotePlayer extends Character { actionsMenuStore.clear(); return; } - actionsMenuStore.initialize(this.PlayerValue); - actionsMenuStore.addAction( - "Visiting Card", () => { - requestVisitCardsStore.set(this.visitCardUrl); - actionsMenuStore.clear(); - }); - actionsMenuStore.addAction( - "Log Hello", () => { - console.log('HELLO'); - }); - actionsMenuStore.addAction( - "Log Goodbye", () => { - console.log('GOODBYE'); - }); - actionsMenuStore.addAction( - "Clear Goodbye Action", () => { - actionsMenuStore.removeAction("Log Goodbye"); - }); + actionsMenuStore.initialize(this.playerName); + for (const action of this.getActionsMenuActions()) { + actionsMenuStore.addAction(action.actionName, action.callback); + } } }); } @@ -96,4 +82,34 @@ export class RemotePlayer extends Character { actionsMenuStore.clear(); super.destroy(); } + + private getActionsMenuActions(): { actionName: string, callback: Function }[] { + return [ + { + actionName: "Visiting Card", + callback: () => { + requestVisitCardsStore.set(this.visitCardUrl); + actionsMenuStore.clear(); + } + }, + { + actionName: "Log Hello", + callback: () => { + console.log('HELLO'); + } + }, + { + actionName: "Log Goodbye", + callback: () => { + console.log('GOODBYE'); + } + }, + { + actionName: "Clear Goodbye Action", + callback: () => { + actionsMenuStore.removeAction("Log Goodbye"); + } + }, + ]; + } }