From a24a960184913cd24a22f682bf966a12e2cd0b8b Mon Sep 17 00:00:00 2001 From: GitBluub Date: Wed, 17 Jan 2024 02:14:56 +0100 Subject: [PATCH] fix practice mode no sound and score system during practice --- front/components/Play/PartitionMagic.tsx | 2 ++ front/components/Play/PlayViewControlBar.tsx | 8 ++++-- front/views/PlayView.tsx | 27 +++++++++++++++----- scorometer/chroma_case/Message.py | 9 ++++++- scorometer/main.py | 9 ++++++- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/front/components/Play/PartitionMagic.tsx b/front/components/Play/PartitionMagic.tsx index f1add24..114560d 100644 --- a/front/components/Play/PartitionMagic.tsx +++ b/front/components/Play/PartitionMagic.tsx @@ -202,6 +202,8 @@ const PartitionMagic = ({ easing: Easing.inOut(Easing.ease), } ); + if (playType == 'practice') + return; cursor.notes.forEach((note) => { piano.current?.start({ note: note.note, diff --git a/front/components/Play/PlayViewControlBar.tsx b/front/components/Play/PlayViewControlBar.tsx index 1d1ff75..38621b0 100644 --- a/front/components/Play/PlayViewControlBar.tsx +++ b/front/components/Play/PlayViewControlBar.tsx @@ -8,6 +8,7 @@ import Song from '../../models/Song'; import { useTheme } from 'native-base'; type PlayViewControlBarProps = { + playType: 'practice' | 'normal' | null; song: Song; time: number; paused: boolean; @@ -19,6 +20,7 @@ type PlayViewControlBarProps = { }; const PlayViewControlBar = ({ + playType, song, time, paused, @@ -107,6 +109,7 @@ const PlayViewControlBar = ({ gap: isPhone ? 10 : 25, }} > + { playType != 'practice' && + />} - + { playType != 'practice' && + } ); diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index b713a24..87a0f7d 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -32,6 +32,7 @@ type PlayViewProps = { // this a hot fix this should be reverted soon let scoroBaseApiUrl = process.env.EXPO_PUBLIC_SCORO_URL!; +let interval: NodeJS.Timeout; if (process.env.NODE_ENV != 'development' && Platform.OS === 'web') { Linking.getInitialURL().then((initUrl) => { @@ -146,8 +147,16 @@ const PlayView = ({ songId }: PlayViewProps) => { bearer: accessToken, }) ); + interval = setInterval(() => { + webSocket.current!.send( + JSON.stringify({ + type: 'ping', + }) + ); + }, 15000); }; webSocket.current.onclose = () => { + clearInterval(interval); console.log('Websocket closed', endMsgReceived); if (!endMsgReceived) { toast.show({ description: 'Connection lost with Scorometer' }); @@ -165,25 +174,28 @@ const PlayView = ({ songId }: PlayViewProps) => { toast.show({ description: 'Scoro: ' + data.error }); return; } + if (data.type == 'pong') + return; if (data.type == 'end') { + const maxPoints = data.score.max_score || 1; + const points = data.overallScore; + endMsgReceived = true; webSocket.current?.close(); + setScore(Math.floor((Math.max(points, 0) * 100) / maxPoints)); setEndResult({ songId: song.data!.id, ...data }); return; } - if (data.type == 'step') { - console.log(data.timestamp) - setTime(data.timestamp) - //set idx += 1 - return - } - console.log(data); const points = data.info.score; const maxPoints = data.info.max_score || 1; setScore(Math.floor((Math.max(points, 0) * 100) / maxPoints)); + if (data.type == 'step') { + setTime(data.timestamp) + return + } let formattedMessage = ''; let messageColor: ColorSchemeType | undefined; @@ -416,6 +428,7 @@ const PlayView = ({ songId }: PlayViewProps) => { /> ( | NoteOnMessage | NoteOffMessage | PauseMessage - | InvalidMessage, + | InvalidMessage + | PingMessage, str, ] ): diff --git a/scorometer/main.py b/scorometer/main.py index d85c8f1..0cfcafa 100755 --- a/scorometer/main.py +++ b/scorometer/main.py @@ -17,6 +17,7 @@ from chroma_case.Message import ( NoteOffMessage, NoteOnMessage, PauseMessage, + PingMessage, StartMessage, getMessage, ) @@ -215,6 +216,9 @@ class Scorometer: def practiceCheck(self): if self.to_play == self.keys_down_practice: + + self.info["perfect"] += len(self.to_play) + self.info["score"] += 100 * len(self.to_play) if len(self.practice_partition) == 0: self.endGamePractice() self.send({"type": "step", "timestamp": self.practice_partition[0][0].start + 1}) @@ -250,13 +254,16 @@ class Scorometer: | NoteOnMessage | NoteOffMessage | PauseMessage - | InvalidMessage, + | InvalidMessage + | PingMessage, line: str, ): match message: case InvalidMessage(error): logging.warning(f"Invalid message {line} with error: {error}") self.send({"error": f"Invalid message {line} with error: {error}"}) + case PingMessage(): + self.send({"type": "pong"}) case NoteOnMessage(): if self.mode == NORMAL: self.handleNoteOn(message)