From 67627637aaeb0492c8234669c36ec1d94fdfd9a9 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Tue, 25 Jan 2022 13:42:41 +0100 Subject: [PATCH] added store with actions for actionsMenu --- .../Components/ActionsMenu/ActionsMenu.svelte | 26 +++++++------- front/src/Phaser/Entity/RemotePlayer.ts | 26 +++++++++++++- front/src/Stores/ActionsMenuStore.ts | 36 +++++++++++++++++++ front/src/Stores/GameStore.ts | 2 +- 4 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 front/src/Stores/ActionsMenuStore.ts diff --git a/front/src/Components/ActionsMenu/ActionsMenu.svelte b/front/src/Components/ActionsMenu/ActionsMenu.svelte index 3f60e4d8..06eee23d 100644 --- a/front/src/Components/ActionsMenu/ActionsMenu.svelte +++ b/front/src/Components/ActionsMenu/ActionsMenu.svelte @@ -1,8 +1,12 @@ @@ -26,13 +26,15 @@

Actions

diff --git a/front/src/Phaser/Entity/RemotePlayer.ts b/front/src/Phaser/Entity/RemotePlayer.ts index 428bd8aa..8e162632 100644 --- a/front/src/Phaser/Entity/RemotePlayer.ts +++ b/front/src/Phaser/Entity/RemotePlayer.ts @@ -3,6 +3,7 @@ import type { PointInterface } from "../../Connexion/ConnexionModels"; import { Character } from "../Entity/Character"; import type { PlayerAnimationDirections } from "../Player/Animation"; import { requestVisitCardsStore, requestActionsMenuStore } from "../../Stores/GameStore"; +import { actionsMenuStore } from '../../Stores/ActionsMenuStore'; /** * Class representing the sprite of a remote player (a player that plays on another computer) @@ -44,7 +45,30 @@ export class RemotePlayer extends Character { this.on("pointerdown", (event: Phaser.Input.Pointer) => { if (event.downElement.nodeName === "CANVAS") { - // requestVisitCardsStore.set(this.visitCardUrl); + actionsMenuStore.addPossibleAction( + "visit-card", + "Visiting Card", () => { + requestVisitCardsStore.set(this.visitCardUrl); + actionsMenuStore.clearActions(); + requestActionsMenuStore.set(false); + }); + actionsMenuStore.addPossibleAction( + "log-hello", + "Log Hello", () => { + console.log('HELLO'); + // requestActionsMenuStore.set(false); + }); + actionsMenuStore.addPossibleAction( + "log-goodbye", + "Log Goodbye", () => { + console.log('GOODBYE'); + // requestActionsMenuStore.set(false); + }); + actionsMenuStore.addPossibleAction( + "clear", + "Clear Actions", () => { + actionsMenuStore.clearActions(); + }); requestActionsMenuStore.set(true); } }); diff --git a/front/src/Stores/ActionsMenuStore.ts b/front/src/Stores/ActionsMenuStore.ts new file mode 100644 index 00000000..c3c2b56b --- /dev/null +++ b/front/src/Stores/ActionsMenuStore.ts @@ -0,0 +1,36 @@ +import { writable } from "svelte/store"; + +export interface ActionsMenuInterface { + displayName: string; + callback: Function; +} + +function createActionsMenuStore() { + + const actions = new Map(); + const { subscribe, update, set } = writable>(actions); + + return { + subscribe, + addPossibleAction: (key: string, displayName: string, callback: Function) => { + update((actions) => { + actions.set(key, { displayName, callback }); + return actions; + }); + }, + removePossibleAction: (key: string) => { + update((actions) => { + actions.delete(key); + return actions; + }); + }, + /** + * Hides menu + */ + clearActions: () => { + set(new Map()); + } + }; +} + +export const actionsMenuStore = createActionsMenuStore(); \ No newline at end of file diff --git a/front/src/Stores/GameStore.ts b/front/src/Stores/GameStore.ts index a8000bab..4260f548 100644 --- a/front/src/Stores/GameStore.ts +++ b/front/src/Stores/GameStore.ts @@ -4,7 +4,7 @@ export const userMovingStore = writable(false); export const requestVisitCardsStore = writable(null); -export const requestActionsMenuStore = writable(true); +export const requestActionsMenuStore = writable(false); export const userIsAdminStore = writable(false);