From d1295bcc2f057a569cf776c6e6090bd62cea4391 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Wed, 10 Jul 2024 22:45:54 -0400 Subject: [PATCH] - fix bug where the wordballoon doesn't show if you send a message while the TTS for another message is still playing - agents now spawn in random positions on the viewport --- msagent.js/src/agent.ts | 7 +++++++ webapp/src/ts/client.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/msagent.js/src/agent.ts b/msagent.js/src/agent.ts index 635a81d..1b5d415 100644 --- a/msagent.js/src/agent.ts +++ b/msagent.js/src/agent.ts @@ -15,6 +15,10 @@ function dwAlign(off: number): number { return ul; } +function randint(min: number, max: number) { + return Math.floor(Math.random() * (max - min) + min); +} + // animation state (used during animation playback) class AgentAnimationState { char: Agent; @@ -308,6 +312,9 @@ export class Agent { } show() { + this.x = randint(0, document.documentElement.clientWidth - this.data.characterInfo.charWidth); + this.y = randint(0, document.documentElement.clientHeight - this.data.characterInfo.charHeight); + this.setLoc(); this.cnv.style.display = 'block'; this.playAnimationByName('Show', () => {}); } diff --git a/webapp/src/ts/client.ts b/webapp/src/ts/client.ts index f56f134..8774389 100644 --- a/webapp/src/ts/client.ts +++ b/webapp/src/ts/client.ts @@ -188,11 +188,11 @@ export class MSAgentClient { this.playingAudio.set(user!.username, audio); audio.addEventListener('ended', () => { - this.playingAudio.delete(user!.username); - // give a bit of time before the wordballoon disappears setTimeout(() => { - user!.agent.stopSpeaking(); + if (this.playingAudio.get(user!.username) === audio) + user!.agent.stopSpeaking(); + this.playingAudio.delete(user!.username); }, 1000); });