From 5460bd49be1f53a9b26d1d72abe3390d6da04447 Mon Sep 17 00:00:00 2001 From: PizZaKatZe Date: Mon, 27 Dec 2021 15:55:00 +0100 Subject: [PATCH] Fix follow requests via keyboard --- .../Components/FollowMenu/FollowMenu.svelte | 31 ++++++------------- front/src/Phaser/Player/Player.ts | 18 +++++++---- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/front/src/Components/FollowMenu/FollowMenu.svelte b/front/src/Components/FollowMenu/FollowMenu.svelte index 264b27ed..aaa23b3e 100644 --- a/front/src/Components/FollowMenu/FollowMenu.svelte +++ b/front/src/Components/FollowMenu/FollowMenu.svelte @@ -14,14 +14,11 @@ vim: ft=typescript } function sendFollowRequest() { - gameScene.connection?.emitFollowRequest(); - followRoleStore.set("leader"); - followStateStore.set("active"); + gameScene.CurrentPlayer.sendFollowRequest(); } function acceptFollowRequest() { - gameScene.CurrentPlayer.enableFollowing(); - gameScene.connection?.emitFollowConfirmation(); + gameScene.CurrentPlayer.startFollowing(); } function abortEnding() { @@ -42,23 +39,15 @@ vim: ft=typescript -{#if $followStateStore === "requesting"} +{#if $followStateStore === "requesting" && $followRoleStore === "follower"}
- {#if $followRoleStore === "follower"} -
-

Do you want to follow {name($followUsersStore[0])}?

-
-
- - -
- {:else if $followRoleStore === "leader"} -
-

Should never be displayed

-
- {/if} +
+

Do you want to follow {name($followUsersStore[0])}?

+
+
+ + +
{/if} diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index 946bb6c4..e41b3237 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -100,10 +100,6 @@ export class Player extends Character { return [xMovement, yMovement]; } - public enableFollowing() { - followStateStore.set("active"); - } - public moveUser(delta: number): void { const activeEvents = this.userInputManager.getEventListForGameTick(); const state = get(followStateStore); @@ -111,8 +107,7 @@ export class Player extends Character { if (activeEvents.get(UserInputEvent.Follow)) { if (state === "off" && this.scene.groups.size > 0) { - followStateStore.set("requesting"); - followRoleStore.set("leader"); + this.sendFollowRequest(); } else if (state === "active") { followStateStore.set("ending"); } @@ -125,4 +120,15 @@ export class Player extends Character { } this.inputStep(activeEvents, x, y); } + + public sendFollowRequest() { + this.scene.connection?.emitFollowRequest(); + followRoleStore.set("leader"); + followStateStore.set("active"); + } + + public startFollowing() { + followStateStore.set("active"); + this.scene.connection?.emitFollowConfirmation(); + } }