Fix game reset and highscore updates

This commit is contained in:
Arnaud Vergnet 2021-05-22 15:45:24 +02:00
parent 9ae585bdf8
commit 8f9c02ff75
2 changed files with 14 additions and 6 deletions

View file

@ -30,12 +30,12 @@ export default function FullGamePodium(props: Props) {
<View style={styles.topScoreSubcontainer}>
<GamePodium
place={3}
score={silver.toString()}
score={bronze.toString()}
isHighScore={isHighScore}
/>
<GamePodium
place={2}
score={bronze.toString()}
score={silver.toString()}
isHighScore={isHighScore}
/>
</View>

View file

@ -17,7 +17,7 @@
* along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
*/
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 = () => (
<MaterialHeaderButtons>
<Item title={'pause'} iconName={'pause'} onPress={togglePause} />
@ -146,8 +153,9 @@ export default function GameMainScreen() {
if (newScores.length > 3) {
newScores.splice(3, 1);
}
console.log(newScores);
if (newScores.some((item, i) => item !== savedScores[i])) {
updatePreferences(PreferenceKeys.gameScores, newScores);
}
if (!isRestart) {
navigation.replace(MainRoutes.GameStart, {
score: score,