fix practice mode no sound and score system during practice
This commit is contained in:
committed by
Clément Le Bihan
parent
9fd70d3110
commit
a24a960184
@@ -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,
|
||||
|
||||
@@ -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' &&
|
||||
<IconButton
|
||||
size="sm"
|
||||
variant="solid"
|
||||
@@ -117,7 +120,7 @@ const PlayViewControlBar = ({
|
||||
name: paused ? 'play' : 'pause',
|
||||
}}
|
||||
onPress={paused ? onResume : onPause}
|
||||
/>
|
||||
/>}
|
||||
<IconButton
|
||||
size="sm"
|
||||
colorScheme="coolGray"
|
||||
@@ -162,7 +165,8 @@ const PlayViewControlBar = ({
|
||||
minWidth: 120,
|
||||
}}
|
||||
>
|
||||
<MetronomeControls paused={paused} bpm={bpm.current} />
|
||||
{ playType != 'practice' &&
|
||||
<MetronomeControls paused={paused} bpm={bpm.current} />}
|
||||
</View>
|
||||
</Row>
|
||||
);
|
||||
|
||||
@@ -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) => {
|
||||
/>
|
||||
</View>
|
||||
<PlayViewControlBar
|
||||
playType={playType}
|
||||
score={score}
|
||||
time={time}
|
||||
paused={paused}
|
||||
|
||||
Reference in New Issue
Block a user