From 94ef3749f5bb2602d52814c289d140d58cc74e7e Mon Sep 17 00:00:00 2001 From: wancat Date: Thu, 27 Jun 2024 12:04:35 +0800 Subject: [PATCH] fix: socket & terminal states across quests --- app/src/store/session.ts | 3 +++ app/src/views/GamePage.vue | 1 + 2 files changed, 4 insertions(+) diff --git a/app/src/store/session.ts b/app/src/store/session.ts index 301b6c8..9db6e0f 100644 --- a/app/src/store/session.ts +++ b/app/src/store/session.ts @@ -8,6 +8,7 @@ import { Session, StageResponse } from '../types' const socket = new Socket() const term = new SocketTerminal(40, 80) +let hasSetup = false interface Store { session: Session | null @@ -65,6 +66,7 @@ const useSession = defineStore('session', { this.$reset() }, setup() { + if (hasSetup) return socket.on('terminal', (data: string) => { term.write(data) }) @@ -77,6 +79,7 @@ const useSession = defineStore('session', { socket.on('response', (response: StageResponse) => { this.newResponse(response) }) + hasSetup = true }, setStatus(status: string) { if (!this.session) return diff --git a/app/src/views/GamePage.vue b/app/src/views/GamePage.vue index ce233a8..9fcd367 100644 --- a/app/src/views/GamePage.vue +++ b/app/src/views/GamePage.vue @@ -29,6 +29,7 @@ const props = defineProps({ }) onMounted(async () => { + sessionStore.reset() sessionStore.setup() await sessionStore.setQuest(props.questId) await sessionStore.getActiveSession()