From 8f9c02ff75044063eba271dc8ea8942887bd94bf Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 22 May 2021 15:45:24 +0200 Subject: [PATCH] Fix game reset and highscore updates --- src/screens/Game/components/FullGamePodium.tsx | 4 ++-- src/screens/Game/screens/GameMainScreen.tsx | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/screens/Game/components/FullGamePodium.tsx b/src/screens/Game/components/FullGamePodium.tsx index c4e6a58..b14b053 100644 --- a/src/screens/Game/components/FullGamePodium.tsx +++ b/src/screens/Game/components/FullGamePodium.tsx @@ -30,12 +30,12 @@ export default function FullGamePodium(props: Props) { diff --git a/src/screens/Game/screens/GameMainScreen.tsx b/src/screens/Game/screens/GameMainScreen.tsx index 690ab14..f21c31d 100644 --- a/src/screens/Game/screens/GameMainScreen.tsx +++ b/src/screens/Game/screens/GameMainScreen.tsx @@ -17,7 +17,7 @@ * along with Campus INSAT. If not, see . */ -import React, { useLayoutEffect, useRef, useState } from 'react'; +import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'; import { StyleSheet, View } from 'react-native'; import { useTheme } from 'react-native-paper'; import i18n from 'i18n-js'; @@ -41,7 +41,7 @@ import { getPreferenceObject, PreferenceKeys, } from '../../../utils/asyncStorage'; -import { useNavigation } from '@react-navigation/core'; +import { useFocusEffect, useNavigation } from '@react-navigation/core'; const styles = StyleSheet.create({ container: { @@ -110,6 +110,13 @@ export default function GameMainScreen() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [navigation]); + useFocusEffect( + useCallback(() => { + const l = logic.current; + return () => l.endGame(true); + }, []) + ); + const getRightButton = () => ( @@ -146,8 +153,9 @@ export default function GameMainScreen() { if (newScores.length > 3) { newScores.splice(3, 1); } - console.log(newScores); - updatePreferences(PreferenceKeys.gameScores, newScores); + if (newScores.some((item, i) => item !== savedScores[i])) { + updatePreferences(PreferenceKeys.gameScores, newScores); + } if (!isRestart) { navigation.replace(MainRoutes.GameStart, { score: score,