Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
87 lines (68 loc) · 2.62 KB
/
Copy pathApp.js
File metadata and controls
87 lines (68 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { React, useEffect, useRef, useState } from 'react';
import Homescreen from './app/screens/Homescreen';
import Game from './app/screens/Game'
import EnemyRound from './app/screens/EnemyRound';
import Ranking from './app/screens/Ranking';
import { MusicContext } from './app/assets/modules/MusicContext';
import {loadMusic} from './app/assets/modules/SoundFunctions'
import { Audio } from 'expo-av';
import * as SQLite from 'expo-sqlite';
import { createTable } from './app/assets/modules/sqlFunctions';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {useFonts} from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
const Stack = createNativeStackNavigator();
export default function App() {
const music = useRef(new Audio.Sound());
const [contextObj, setContextObj] = useState({ref: music.current, isMusic: true, click: null,
win: null, loose: null, db: SQLite.openDatabase('database12.db'), oppPicture: undefined, oppPictureType: ""});
//unload sounds
useEffect(() => {
return () => {
if(contextObj.click){
contextObj.click.unloadAsync();
}
if(contextObj.win){
contextObj.win.unloadAsync();
}
if(contextObj.loose){
contextObj.loose.unloadAsync();
}
}
}, [contextObj.click, contextObj.win, contextObj.loose]);
useEffect(() => {
createTable(contextObj.db, "rankingEasy");
createTable(contextObj.db, "rankingHard");
loadMusic(contextObj.ref);
async function prepare() {
await SplashScreen.preventAutoHideAsync();
}
prepare();
}, []);
//set fonts
const[fontIsLoaded] = useFonts({
"Game": require("./app/assets/fonts/Silkscreen-Regular.ttf"),
"Buttons": require("./app/assets/fonts/SignikaNegative-Bold.ttf")
});
//check fonts
if(!fontIsLoaded){
return undefined;
}
else
{
SplashScreen.hideAsync();
}
return (
<NavigationContainer>
<MusicContext.Provider value={{contextObj, setContextObj}}>
<Stack.Navigator>
<Stack.Screen name="Homescreen" component={Homescreen} options={{headerShown: false}}/>
<Stack.Screen name="Ranking" component={Ranking} options={{headerShown: false,animation: 'slide_from_left'}}/>
<Stack.Screen name="Game" component={Game} options={{headerShown: false}}/>
<Stack.Screen name="EnemyRound" component={EnemyRound} options={{headerShown: false, animation: 'slide_from_bottom'} } />
</Stack.Navigator>
</MusicContext.Provider>
</NavigationContainer>
);
}