Skip to content

Commit 5670cae

Browse files
committed
ready to publish testflight
1 parent 3fb2923 commit 5670cae

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

.expo/packager-info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"devToolsPort": 19002,
3-
"expoServerPort": 19000,
3+
"expoServerPort": null,
44
"packagerPort": 19000,
55
"packagerPid": null,
66
"expoServerNgrokUrl": null,

App.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
1-
import React from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import GameContext from './GameContext';
33
import { StatusBar } from 'expo-status-bar';
44
import Game from './Screens/Game'
55
import { Flex } from './CoreElements/containerStyles';
66
import { colors } from './CoreElements/theme';
7+
import AsyncStorage from "@react-native-async-storage/async-storage"
78

89
export default function App() {
9-
return (
10-
// Eventually will be a react-navigotor between Rules and Game, possibly a game win final screen
11-
<GameContext>
10+
const [appPreferences, setAppPreferences] = useState({})
11+
12+
const getStoredPreferences = async () => {
13+
try {
14+
const jsonValue = await AsyncStorage.getItem('preferences')
15+
return jsonValue != null ? JSON.parse(jsonValue) : null;
16+
} catch (e) {
17+
console.error("getStoredPreferences error: ", e)
18+
}
19+
}
20+
21+
const storePreferences = async (preferenceObject) => {
22+
try {
23+
const jsonValue = JSON.stringify(preferenceObject)
24+
await AsyncStorage.setItem('settings', jsonValue)
25+
} catch (e) {
26+
console.error("storePreferences error: ", e)
27+
}
28+
}
29+
30+
const handlePreferenceLoad = async () => {
31+
const storedPreferences = await getStoredPreferences()
32+
if (!storedPreferences) {
33+
console.log("no stored prefs")
34+
const newPreferencesObj = {
35+
deckTheme: "Default",
36+
sounds: false
37+
}
38+
storePreferences(newPreferencesObj)
39+
setAppPreferences(newPreferencesObj)
40+
} else setAppPreferences(storedPrefences)
41+
}
42+
43+
useEffect(() => {
44+
handlePreferenceLoad()
45+
}, [])
46+
47+
useEffect(() => {
48+
console.log("app preferences changed - saving now")
49+
if (appPreferences !== {}) {
50+
storePreferences(appPreferences)
51+
}
52+
}, [appPreferences])
53+
54+
if (appPreferences === {}) return null
55+
else return (
56+
<GameContext appPreferences={appPreferences} setAppPreferences={setAppPreferences}>
1257
<Flex color={colors.background}>
1358
<StatusBar style="light" hidden={true} />
1459
<Game />
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { Image, Pressable, StyleSheet, View } from 'react-native'
33
import { Body, DefaultText, Subtitle } from '../CoreElements/fontStyles'
44
import { DataContext } from "../GameContext"
55
import { iconSVGs, colors, themeSamples } from '../CoreElements/theme'
6-
import { cardImages } from '../Data/data'
76
import Svg, { Path } from 'react-native-svg'
87

9-
export default function DeckTheme({ deck }) {
10-
const { deckTheme, setDeckTheme } = useContext(DataContext)
8+
export default function DeckThemeChoice({ deck }) {
9+
const { appPreferences, setAppPreferences } = useContext(DataContext)
1110

1211
const handleThemeChange = () => {
13-
setDeckTheme(deck)
12+
setAppPreferences({ ...appPreferences, deckTheme: deck })
1413
}
1514

1615

@@ -28,12 +27,12 @@ export default function DeckTheme({ deck }) {
2827
})
2928

3029
return (
31-
<Pressable onPress={deckTheme !== deck ? handleThemeChange : null}>
30+
<Pressable onPress={appPreferences.deckTheme !== deck ? handleThemeChange : null}>
3231
<View style={styles.container}>
3332
<Subtitle align="left" override={{ fontSize: 18 }}>{deck}</Subtitle>
3433
<Image source={themeSamples[deck]} />
3534
<View style={{ position: "absolute", top: 10, left: 10 }}>
36-
{deckTheme === deck ?
35+
{appPreferences.deckTheme === deck ?
3736
<Svg width="33" height="33" viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg">
3837
<Path d="M16.5 32.6562C25.2188 32.6562 32.4375 25.4219 32.4375 16.7188C32.4375 8 25.2031 0.78125 16.4844 0.78125C7.78125 0.78125 0.5625 8 0.5625 16.7188C0.5625 25.4219 7.79688 32.6562 16.5 32.6562ZM16.5 30C9.125 30 3.23438 24.0938 3.23438 16.7188C3.23438 9.34375 9.10938 3.4375 16.4844 3.4375C23.8594 3.4375 29.7656 9.34375 29.7812 16.7188C29.7969 24.0938 23.875 30 16.5 30ZM14.7812 24.1406C15.2969 24.1406 15.7344 23.8906 16.0469 23.4062L23.1875 12.1719C23.3594 11.8594 23.5625 11.5156 23.5625 11.1719C23.5625 10.4688 22.9375 10.0156 22.2812 10.0156C21.8906 10.0156 21.5 10.2656 21.2031 10.7188L14.7188 21.125L11.6406 17.1406C11.2656 16.6406 10.9219 16.5156 10.4844 16.5156C9.8125 16.5156 9.28125 17.0625 9.28125 17.75C9.28125 18.0938 9.42188 18.4219 9.64062 18.7188L13.4531 23.4062C13.8438 23.9219 14.2656 24.1406 14.7812 24.1406Z" fill={colors.green} />
3938
</Svg>

GameContext.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import { decidePace, debugMode, logMode } from "./Data/data"
1313

1414
export const DataContext = createContext()
1515

16-
export default function GameContext({ children }) {
16+
export default function GameContext({ appPreferences, setAppPreferences, children }) {
1717
////////////////
1818
// GAME STATE //
1919
////////////////
20-
21-
// Theme State
22-
const [deckTheme, setDeckTheme] = useState("Default")
20+
console.log("App Preferences: ", appPreferences)
2321

2422
// Card State
2523
const [playerHand, setPlayerHand] = useState([])
@@ -812,7 +810,7 @@ export default function GameContext({ children }) {
812810
return (
813811
<DataContext.Provider
814812
value={{
815-
deckTheme, setDeckTheme,
813+
appPreferences, setAppPreferences,
816814
showPromptModal, setShowPromptModal,
817815
showRulesModal, setShowRulesModal,
818816
showSettingsModal, setShowSettingsModal,

Modals/SettingsModal.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React, { useContext } from 'react'
2-
import { View, Modal, StyleSheet, Pressable, Image, ScrollView } from 'react-native'
2+
import { View, Modal, StyleSheet, Pressable, ScrollView } from 'react-native'
33
import { DataContext } from '../GameContext'
4-
import { Flex } from '../CoreElements/containerStyles'
5-
import { Subtitle, Italic, Body, DefaultText, Heading, Title } from '../CoreElements/fontStyles'
4+
import { Italic, DefaultText, Heading, Title } from '../CoreElements/fontStyles'
65
import { colors, iconSVGs, styles } from '../CoreElements/theme'
76
import Svg, { Path } from 'react-native-svg'
8-
import DeckTheme from '../Components/DeckTheme'
7+
import DeckThemeChoice from '../Components/DeckThemeChoice'
98

109
export default function SettingsModal() {
11-
const { setShowStartModal, setShowSettingsModal, showSettingsModal, setDeckTheme, deckTheme } = useContext(DataContext)
10+
const { setShowStartModal, setShowSettingsModal, showSettingsModal } = useContext(DataContext)
1211

1312
const handleClose = () => {
1413
setShowStartModal(true)
@@ -38,8 +37,8 @@ export default function SettingsModal() {
3837
</View>
3938
<View style={{ justifyContent: "center", alignItems: "center", marginVertical: 20 }}>
4039
<Title override={{ fontSize: 24 }}>Deck Theme</Title>
41-
<DeckTheme deck="Default" />
42-
<DeckTheme deck="QueenG" />
40+
<DeckThemeChoice deck="Default" />
41+
<DeckThemeChoice deck="QueenG" />
4342
</View>
4443
<Pressable
4544
accessibilityLabel={"Press to begin the game"}

0 commit comments

Comments
 (0)