Browse Source

Fix game reset and highscore updates

Arnaud Vergnet 2 years ago
parent
commit
8f9c02ff75

+ 2
- 2
src/screens/Game/components/FullGamePodium.tsx View File

@@ -30,12 +30,12 @@ export default function FullGamePodium(props: Props) {
30 30
       <View style={styles.topScoreSubcontainer}>
31 31
         <GamePodium
32 32
           place={3}
33
-          score={silver.toString()}
33
+          score={bronze.toString()}
34 34
           isHighScore={isHighScore}
35 35
         />
36 36
         <GamePodium
37 37
           place={2}
38
-          score={bronze.toString()}
38
+          score={silver.toString()}
39 39
           isHighScore={isHighScore}
40 40
         />
41 41
       </View>

+ 12
- 4
src/screens/Game/screens/GameMainScreen.tsx View File

@@ -17,7 +17,7 @@
17 17
  * along with Campus INSAT.  If not, see <https://www.gnu.org/licenses/>.
18 18
  */
19 19
 
20
-import React, { useLayoutEffect, useRef, useState } from 'react';
20
+import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
21 21
 import { StyleSheet, View } from 'react-native';
22 22
 import { useTheme } from 'react-native-paper';
23 23
 import i18n from 'i18n-js';
@@ -41,7 +41,7 @@ import {
41 41
   getPreferenceObject,
42 42
   PreferenceKeys,
43 43
 } from '../../../utils/asyncStorage';
44
-import { useNavigation } from '@react-navigation/core';
44
+import { useFocusEffect, useNavigation } from '@react-navigation/core';
45 45
 
46 46
 const styles = StyleSheet.create({
47 47
   container: {
@@ -110,6 +110,13 @@ export default function GameMainScreen() {
110 110
     // eslint-disable-next-line react-hooks/exhaustive-deps
111 111
   }, [navigation]);
112 112
 
113
+  useFocusEffect(
114
+    useCallback(() => {
115
+      const l = logic.current;
116
+      return () => l.endGame(true);
117
+    }, [])
118
+  );
119
+
113 120
   const getRightButton = () => (
114 121
     <MaterialHeaderButtons>
115 122
       <Item title={'pause'} iconName={'pause'} onPress={togglePause} />
@@ -146,8 +153,9 @@ export default function GameMainScreen() {
146 153
     if (newScores.length > 3) {
147 154
       newScores.splice(3, 1);
148 155
     }
149
-    console.log(newScores);
150
-    updatePreferences(PreferenceKeys.gameScores, newScores);
156
+    if (newScores.some((item, i) => item !== savedScores[i])) {
157
+      updatePreferences(PreferenceKeys.gameScores, newScores);
158
+    }
151 159
     if (!isRestart) {
152 160
       navigation.replace(MainRoutes.GameStart, {
153 161
         score: score,

Loading…
Cancel
Save