Merge branch 'Persistance' of https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY into Persistance
continuous-integration/drone/push Build is failing Details

Persistance
Alban GUILHOT 2 years ago
commit 1f55c75bcd

@ -6,9 +6,9 @@ import { useFonts } from 'expo-font';
export default function App() {
const [fontsLoaded] = useFonts({
'Helvetica': require('./assets/fonts/Helvetica.ttf'),
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 KiB

@ -1,11 +0,0 @@
import React from 'react'
import App from './App'
// export for others scripts to use
export default function Index(){
return(
<App/>
)
}

@ -24,11 +24,14 @@
"babel-preset-env": "^1.7.0",
"babel-preset-typescript": "^7.0.0-alpha.19",
"babel-test": "^0.2.4",
"cors": "^2.8.5",
"expo": "^46.0.17",
"expo-status-bar": "~1.4.0",
"express": "^4.18.2",
"jest": "^29.3.1",
"jquery": "^3.6.1",
"node": "^18.10.0",
"nodemon": "^2.0.20",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-native": "^0.69.6",
@ -40,6 +43,8 @@
"react-native-safe-area-context": "4.3.1",
"react-native-web": "~0.18.7",
"react-redux": "^8.0.4",
"socket.io": "^4.5.4",
"socket.io-client": "^4.5.4",
"ts-node": "^10.9.1",
"zustand": "^4.1.4"
},

@ -0,0 +1,28 @@
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
const connectUsers = [];
io.on('connection', (socket) => {
console.log(socket.id)
socket.on('inConv', (conv) => {
socket.join("C" + conv.id);
});
socket.on("messageSent", (conv) =>{
socket.to("C"+conv.id).emit("messageReceived");
console.log("Message envoyé");
});
});
server.listen(3000, () => {
console.log('listening on *:3000');
});

@ -0,0 +1,4 @@
const { io } = require("socket.io-client");
export const socket = io("http://localhost:3000");

@ -8,6 +8,7 @@ import {
Image,
TouchableHighlight,
Alert,
ImageBackground,
} from 'react-native'
import { MANAGER_MATCH, MANAGER_USER } from '../../../appManagers';
import { useMatchStore } from '../../context/matchContext';
@ -114,23 +115,24 @@ function CookieClicker(props: { navigation: any}){
return (
<View style={styles.container}>
<View >
<Text>
<ImageBackground source={{ uri: "https://i0.wp.com/lesfoliesdejenny.fr/wp-content/uploads/2021/12/5.png?w=1080&ssl=1" }} resizeMode="cover" style={styles.image}>
<View style={styles.containerTop}>
<Text style={styles.cout}>
Timer: {timer}
</Text>
<TouchableHighlight onPress={onPressCookie} >
<Image style={styles.photo} source={{uri: 'https://cdn-icons-png.flaticon.com/512/614/614131.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasCookie.png' }} />
</TouchableHighlight>
<Text>
<Text style={styles.cout}>
Argent {money}
</Text>
<Text>
<Text style={styles.cout}>
Points {count}
</Text>
</View>
<View style={styles.containerRight}>
<TouchableHighlight onPress={onPressGrandma}>
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/12/Grandma-Happy-PNG-Photo.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasGrandma.png' }} />
</TouchableHighlight>
<View>
<Text style={styles.cout}>
@ -139,7 +141,7 @@ function CookieClicker(props: { navigation: any}){
</View>
<TouchableHighlight onPress={onPressFarm} style={styles.photo}>
<Image style={styles.photo} source={{uri: 'https://www.pngall.com/wp-content/uploads/8/Farming-PNG-Picture.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasFarm.png' }} />
</TouchableHighlight>
<View>
<Text style={styles.cout}>
@ -148,7 +150,7 @@ function CookieClicker(props: { navigation: any}){
</View>
<TouchableHighlight onPress={onPressFactory}>
<Image style={styles.photo} source={{uri: 'https://cdn.pixabay.com/photo/2018/04/16/09/12/factory-3323977_960_720.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasFactory.png' }} />
</TouchableHighlight>
<View>
<Text style={styles.cout}>
@ -157,7 +159,7 @@ function CookieClicker(props: { navigation: any}){
</View>
<TouchableHighlight onPress={onPressWizard}>
<Image style={styles.photo} source={{uri: 'https://www.clasher.us/images/coc/units/Wizard_Tower7.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasTower.png' }} />
</TouchableHighlight>
<View>
<Text style={styles.cout}>
@ -166,22 +168,29 @@ function CookieClicker(props: { navigation: any}){
</View>
<TouchableHighlight onPress={onPressPortal}>
<Image style={styles.photo} source={{uri: 'https://i.pinimg.com/originals/98/29/21/9829215db6f9210c0ae4e318e854cb1f.png'}}/>
<Image style={styles.photo} source={{ uri: 'https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/Persistance/bob_party/assets/ImagesJeux/CookieClicker/ChristmasPortal.png' }} />
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {portalCost}
</Text>
</View>
</View>
</View>
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
container: {
top: 75,
height: window.innerHeight,
width: window.innerWidth,
flex: 1,
},
containerTop:{
top: "5%",
margin: 10,
flex: 1,
justifyContent: 'center',
@ -190,7 +199,6 @@ const styles = StyleSheet.create({
containerRight: {
flex: 1,
flexWrap: "wrap",
top: 100,
marginBottom: 20,
left: 100,
},
@ -208,12 +216,18 @@ const styles = StyleSheet.create({
marginBottom: 10
},
photo: {
width: 50,
height: 50
width: 75,
height: 75
},
cout: {
marginBottom: 20
}
marginBottom: 20,
color: "white",
fontSize: 15
},
image: {
flex: 1,
justifyContent: "center"
},
})

@ -0,0 +1,212 @@
import {Alert, ImageBackground, Pressable, StyleSheet, Text, View } from "react-native";
import React, {useState} from "react";
import { useMatchStore } from "../../context/matchContext";
export default function tic_tac_toe(props: { navigation: any}){
const [map,setMap]=useState([
['','',''],
['','',''],
['','',''],
]);
const {navigation}=props;
const [currentTurn,setCurrentTurn] = useState("x");
//const resetMatch = useMatchStore((state) => state.resetMatch);
const onPressCell = (rowIndex:number,columnIndex:number) => {
if(map[rowIndex][columnIndex]==""){
setMap((existingMap) =>{
const updateMap = [...existingMap]
updateMap[rowIndex][columnIndex]=currentTurn;
return updateMap;
});
}else{
Alert.alert("Case déjà prise");
}
setCurrentTurn(currentTurn === "x"? "o" : "x");
checkWinning();
checkComplete();
};
const checkWinning = () =>{
// Checks rows
for (let i=0; i<3; i++){
const isRowXWinning = map[i].every((cell)=> cell==="x");
const isRowOWinning = map[i] .every((cell)=>cell==="o");
if(isRowXWinning==true){
Alert.alert("X won !");
navigation.goBack();
}
else if(isRowOWinning==true){
Alert.alert("X won !");
navigation.goBack();
}
}
// Checks columns
for (let col=0;col<3;col++){
let isColumnXWinning=true;
let isColumnOWinning=true;
for(let row=0;row<3;row++){
if(map[row][col] !== "x"){
isColumnXWinning=false;
}
if(map[row][col] !== "o"){
isColumnOWinning=false;
}
}
if (isColumnXWinning == true){
Alert.alert("X won !");
navigation.goBack();
}
if(isColumnOWinning==true){
Alert.alert("O won !");
navigation.goBack();
}
}
// Checks diag
let isDiag1XWinning=true;
let isDiag1OWinning=true;
let isDiag2XWinning=true;
let isDiag2OWinning=true;
for (let i=0;i<3;i++){
if(map[i][i]!=="x"){
isDiag1XWinning=false;
}
if(map[i][i]!=="o"){
isDiag1OWinning=false;
}
if(map[i][2-i]!=="x"){
isDiag2XWinning=false;
}
if(map[i][2-i]!=="o"){
isDiag2OWinning=false;
}
}
if(isDiag1OWinning==true || isDiag2OWinning==true){
Alert.alert("O won !");
navigation.goBack();
}
if(isDiag1XWinning==true || isDiag2XWinning==true){
Alert.alert("X won !");
navigation.goBack();
}
};
const checkComplete = () =>{
/*let isFull;
for (let row=0; row<3; row++){
for(let col=0;col<3;col++){
if(map[row][col]==="o" || map[row][col]==="x"){
isFull=false;
}
}
}
if (isFull!=false){
Alert.alert("Draw !");
navigation.goBack();
}*/
const isRow0Full = map[0].every((cell)=> cell!=="");
const isRow1Full = map[1] .every((cell)=>cell!=="");
const isRow2Full = map[2] .every((cell)=>cell!=="");
if(isRow0Full==true && isRow1Full==true && isRow2Full==true){
Alert.alert("Draw !");
navigation.goBack();
}
};
return(
<View style={styles.container}>
<Text style={styles.text}>TIC TAC TOE</Text>
<ImageBackground style={styles.grid} source={{uri:"https://upload.wikimedia.org/wikipedia/commons/6/64/Tic-tac-toe.png"}} >
<View style={styles.map}>
{map.map((row, rowIndex)=>(
<View key={`row-${rowIndex}`} style={styles.row}>
{row.map((cell, columnIndex)=> (
<Pressable
onPress={() => onPressCell(rowIndex,columnIndex)}
style={styles.cell}
key={`row-${rowIndex}-col-${columnIndex}`}
>
{cell === "o" && <View style={styles.circle}/>}
{cell === "x" &&(
<View style={styles.cross}>
<View style={styles.crossLine}/>
<View style={[styles.crossLine, styles.crossLineReversed]}/>
</View>
)}
</Pressable>
))}
</View>
))}
</View>
</ImageBackground>
</View>
);
}
const styles= StyleSheet.create({
container:{
height:"100%",
width:"100%",
flex:1,
backgroundColor:"#45444E",
alignItems:"center",
justifyContent:"center",
},
grid:{
width:375,
height:375,
alignItems:"center",
justifyContent:"center",
},
row:{
flex:1,
flexDirection:"row",
},
cell:{
width:100,
flex:1,
},
circle:{
left:15,
top:15,
width:90,
height:90,
backgroundColor:"#0085FF",
borderRadius:50
},
cross:{
width:"100%",
height:"100%",
},
crossLine:{
left:52,
top:15,
position:"absolute",
width:15,
height:100,
borderRadius:50,
backgroundColor:"#EE9433",
transform:[{rotate:"45deg"},],
},
crossLineReversed:{
transform:[{rotate:"-45deg"},],
},
map:{
aspectRatio:1,
padding:5
},
text:{
fontSize: 26,
lineHeight: 21,
fontWeight: 'bold',
letterSpacing: 0.25,
color: 'white',
marginBottom:25
}
})

@ -10,6 +10,7 @@ import { useStoreStore } from "../context/storeContext";
import tabSkinApp from "../constSkin";
import { useConversationStore } from "../context/conversationContext";
import { MANAGER_CONVERSATION, MANAGER_USER } from "../../appManagers";
import { socket } from "../../socketConfig";
/*
Images that are required to create a bottom bar
@ -30,23 +31,26 @@ const smessage = require('../../assets/Icons/Selected/SChat.png');
const sstore = require('../../assets/Icons/Selected/SStore.png');
export const BotBar:
/* Parameters :
* nav : tool needed to allow the navigation between the screens
* state : optional parameter that indicates from which screen the component has been called
(the string must be the name of the screen)
*/
FC<{ nav: any, state?: String }> =
({ nav, state }) => {
const setTabSkin = useStoreStore((state) => state.setTabSkin);
const setTabConv = useConversationStore((state) => state.setTabConv);
const handleStoreChange = useCallback(async () => {
let tabSkinStore = [...tabSkinApp];
// const tmp=MANAGER_USER.getCurrentUser()?.getTabSkin();
// if (tmp!==undefined){
MANAGER_USER.getCurrentUser()?.getTabSkin()?.forEach(skin => {
for (let i = 0; i < tabSkinStore.length; i++) {
if (skin.isEqual(tabSkinStore[i])) {
@ -55,19 +59,11 @@ export const BotBar:
}
});
setTabSkin(tabSkinStore);
// }
}, []);
const handleConversationChange = useCallback(async () => {
const tmp = MANAGER_USER.getCurrentUser();
if (tmp !== null) {
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {
MANAGER_CONVERSATION.setCurrentTabConv(res);
setTabConv(res);
});
}
}, []);
/*
By default, all the images are the white ones
@ -100,7 +96,7 @@ export const BotBar:
*/
return (
<View style={styles.footer}>
<Pressable onPress={() => { handleConversationChange(); nav.navigate('ChatTab') }}>
<Pressable onPress={() => { nav.navigate('ChatTab') }}>
<Image
style={styles.icon}
source={imgLeft}

@ -0,0 +1,39 @@
import { FC, ReactNode, useCallback } from "react"
import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native"
import React from "react"
import { trace } from "console"
import { Game } from "../core/game"
/*
Importing the correct stylesheet
*/
import styles from './style/Game.style';
import LobbySolo from "../screens/LobbySolo"
import ManagerMatch from "../services/matchServices/managerMatch"
import MatchCreator from "../core/Match/matchCreator"
import { useMatchStore } from "../context/matchContext"
import { MANAGER_MATCH, MANAGER_USER } from "../../appManagers"
import { Match } from "../core/Match/match"
import { User } from "../core/User/user"
export const PlayerBox :
/*
* match : match that must be displayed
* nav : tool needed to allow the navigation between the screens
*/
FC<{user: User}> =
({user}) =>
{
return (
<View>
<Image
style={styles.image}
source={{uri: user.getCurrentSkin().getSkinSource()}}
/>
<Text style={styles.name}>{user.getUsername()}</Text>
</View>
)
}

@ -11,6 +11,7 @@ import { User } from "../core/User/user"
import styles from './style/TopBar.style';
import { useMatchStore } from "../context/matchContext"
import { MANAGER_USER } from "../../appManagers"
import { useUserStore } from "../context/userContext"
/*
Images required
@ -68,7 +69,7 @@ FC<{nav: any, state?: string}> =
return (
<View style={styles.header}>
<Pressable onPress={() => nav.navigate('ProfileTab', {screen: 'Profile'})}>
<SkinComponent skin={MANAGER_USER.getCurrentUser().getCurrentSkin()} state='icon' nav={nav} />
<SkinComponent skin={useUserStore().user?.getCurrentSkin()} state='icon' nav={nav} />
</Pressable>
<Text style={styles.titre}>BOB PARTY</Text>
<Pressable onPress={() => nav.navigate('Settings')}>

@ -5,15 +5,15 @@ import { Conversation } from "../core/conversation";
// Define store types
interface ConversationState {
tabConv: Conversation[] | undefined;
tabConv: Conversation[] | null;
setTabConv: (tabConv: Conversation[]) => void;
resetTabConv: () => void;
}
// Define store data and methods
export const useConversationStore = create<ConversationState>()((set, get) => ({
tabConv: undefined,
tabConv: null,
setTabConv: (tabConv) => set((state) => ({ tabConv: tabConv })),
resetTabConv: () => set((state) => ({tabConv: undefined})),
resetTabConv: () => set((state) => ({tabConv: null})),
}));

@ -1,5 +1,4 @@
import MatchSolo from '../Match/matchSolo';
import { Conversation } from '../Conversation';
import { Skin } from '../Skin';
import { User } from '../User/user';
import { GameSolo } from '../GameSolo';
@ -21,10 +20,12 @@ let myMap = new Map<number, number>([
[100, 5],
[150, 6]
]);
let game=new GameSolo(1, "bo jeu", img, "super jeu", 1, 1, myMap);
let match = new MatchSolo(1, false, tabU, game);
let tabU2:User[] = [];
let game=new GameSolo(1, "bo jeu", img, "super jeu", 1, 1, myMap);
let game2 = new GameSolo(2, "jeu magnifique", img, "wow jeu", 1, 1, myMap)
let match = new MatchSolo(1, false, tabU, game);
let match2 = new MatchSolo(1, false, tabU2, game2);
let match3 = new MatchSolo(1, false, tabU, game);
// Get tests
@ -36,50 +37,47 @@ describe('Match get tests', () => {
expect(match.getInGame()).toBe(false);
})
it('should return tabU [usr] (users)', () => {
expect(match.getTabUsers()).toBe(tabU);
expect(match.getTabUsers()).toEqual(match3.getTabUsers());
})
it('should return game', () => {
expect(match.getGame).toBe(game);
expect(match.getGame()).toEqual(match3.getGame());
})
})
// Setting new values
match.setGame(game2);
match.setInGame(true);
match.setTabUser(tabU2);
// Set tests
describe('Match set tests', () => {
it('should return tabU2 [] (users)', () => {
expect(match.getTabUsers()).toBe(tabU2);
match.setTabUser(tabU2);
expect(match.getTabUsers()).toEqual(match2.getTabUsers());
})
it('should return true', () => {
match.setInGame(true);
expect(match.getInGame()).toBe(true);
})
it('should return game2', () => {
expect(match.getGame).toBe(game2);
match.setGame(game2);
expect(match.getGame()).toEqual(match2.getGame());
})
})
// Update Post-Match tests
describe('Update post-match tests', () => {
it('should return 3', () => {
match.updatePostMatch(tabU[0],50);
expect(tabU[0].getCurrentCoins()).toBe(3);
it('should return 50', () => {
match.updatePostMatch(tabU[0],3);
expect(tabU[0].getCurrentCoins()).toBe(50);
})
it('should return 8', () => {
match.updatePostMatch(tabU[0],100);
expect(tabU[0].getCurrentCoins()).toBe(8);
it('should return 75', () => {
match.updatePostMatch(usr2,4);
expect(usr2.getCurrentCoins()).toBe(75);
})
it('should return 4', () => {
match.updatePostMatch(usr2,75);
expect(usr2.getCurrentCoins()).toBe(4);
it('should return 150', () => {
match.updatePostMatch(tabU[0],5);
expect(tabU[0].getCurrentCoins()).toBe(150);
})
it('should return 10', () => {
match.updatePostMatch(usr2,150);
expect(usr2.getCurrentCoins()).toBe(10);
it('should return 225', () => {
match.updatePostMatch(usr2,6);
expect(usr2.getCurrentCoins()).toBe(225);
})
})

@ -17,6 +17,8 @@ import CookieClicker from '../Games/CookieClicker/cookieClicker'
import Conversation from '../screens/Conversation'
import Test from '../screens/Test'
import MatchMaking from '../screens/MatchMaking'
import TicTacToe from '../Games/Tic-Tac-Toe/tic-tac-toe'
const HomeStack = createStackNavigator();
@ -97,8 +99,9 @@ const GameSoloStack = createStackNavigator();
function GameSoloStackScreen() {
return (
<GameSoloStack.Navigator screenOptions={{headerShown: false}}>
<GameSoloStack.Screen name='LobbySolo' component={LobbySolo} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='MatchMaking' component={MatchMaking} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='CookieClicker' component={CookieClicker} />
<GameSoloStack.Screen name='TicTacToe' component={TicTacToe} />
</GameSoloStack.Navigator>
);
}

@ -1,10 +1,11 @@
/*
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
import { Skin } from "../../core/Skin";
import { User } from "../../core/User/user";
const dateNull = new Date();
const userNull:User= new User("","","","","",dateNull);
const userNull:User | null= null;
var currentUser:User = userNull;
@ -72,3 +73,4 @@ export const { updateNationality } = currentUserSlice.actions
export const { updateSex } = currentUserSlice.actions
export default currentUserSlice.reducer;
*/

@ -0,0 +1,47 @@
import { StatusBar } from 'expo-status-bar'
import { View, Image, Text, Button} from 'react-native'
import React from 'react';
import stylesScreen from './style/screens.style';
import styles from './style/Settings.style';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { Conversation } from '../core/conversation';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { useMatchStore } from '../context/matchContext';
import { FlatList, TextInput } from 'react-native-gesture-handler';
import { PlayerBox } from '../components/PlayerBox';
function MatchMaking(props: { navigation: any; }) {
const { navigation } = props
const match = useMatchStore().match;
return (
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
state='matchmacking'
/>
<FlatList
data={match?.getTabUsers()}
keyExtractor={usr =>usr.getUsername()}
renderItem={({item}) => <PlayerBox user={item}/>}
/>
<View style={stylesScreen.bodyCenter}>
<Button
title='Lancer la partie'
onPress={() => navigation.navigate(match?.getGame().getName().replace(/\s/g, ''))}
/>
</View>
<Image
style={{width:100, height:100}}
source={{uri: match?.getGame().getImageSource()}}
/>
</View>
);
}
export default MatchMaking

@ -5,12 +5,13 @@ import stylesScreen from './style/screens.style'
import { TextInput } from 'react-native-gesture-handler';
import styles from "./style/SignIn.style";
import { useDispatch, useSelector } from 'react-redux';
import { loginUser } from '../redux/features/currentUserSlice';
import { RootState } from '../redux/store';
import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice';
import Dialog from "react-native-dialog";
import { useUserStore } from '../context/userContext';
import { MANAGER_USER } from '../../appManagers';
import { MANAGER_CONVERSATION, MANAGER_USER } from '../../appManagers';
import { socket } from "../../socketConfig";
import { useConversationStore } from '../context/conversationContext';
@ -18,6 +19,8 @@ import { MANAGER_USER } from '../../appManagers';
function SignIn(props: { navigation: any; }) {
const { navigation } = props
const setUser = useUserStore((state) => state.setUser);
const setTabConv = useConversationStore((state) => state.setTabConv);
const errorList = useSelector((state: RootState) => state.credentialErrors.loginErrorList);
const [pseudo, setPseudo] = useState('');
@ -29,19 +32,46 @@ function SignIn(props: { navigation: any; }) {
dispatch(updateIncorrectCredentials(true));
}
let waitConnect=0;
const handleUserConnect = useCallback(async (pseudo: string, password: string) => {
async function handleUserConnect(username: string, password: string){
await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => {
if (waitConnect==0){
waitConnect=1;
await MANAGER_USER.getLoaderUser().loadByUsernamePassword(username, password).then(async (res) => {
if (res!=null){
MANAGER_USER.setCurrentUser(res);
setUser(MANAGER_USER.getCurrentUser());
socket.emit("signIn", res);
await handleConversationLoad();
MANAGER_CONVERSATION.getCurrentTabConv()?.forEach( conv =>{
socket.emit("inConv", conv);
socket.emit("messageSent", conv);
});
navigation.navigate('HomeTab');
}
});
waitConnect=0;
}
return;
}
async function handleConversationLoad(){
const tmp = MANAGER_USER.getCurrentUser();
if (tmp !== null) {
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {
MANAGER_CONVERSATION.setCurrentTabConv(res);
setTabConv(res);
});
}
}
}, []);
socket.on("messageReceived", () =>{
console.log("Message reçu");
handleConversationLoad();
});
return (

@ -2,6 +2,7 @@ import { StyleSheet } from "react-native";
export default StyleSheet.create({
container: {
top: window.innerHeight,
flex: 1,
backgroundColor: '#45444E',
flexDirection: "column",

@ -27,18 +27,11 @@ export class LoaderConversationApi implements ILoaderConversation{
})
.then(function (response: any) {
let skin= new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0);
let skin2= new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBlue.png", 0);
let user1 = new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]);
let user2 = new User(3, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, skin2, [skin]);
tabConv=[new Conversation(1,
[user1, user2],
[
new Message(1, "bonjour", user1, new Date(2022,12,12)),
new Message(2, "test", user2, new Date(2022,12,13)),
new Message(3, "Je m'appelle alban et j'aime trop faire les messages quand ça marche mais ya encore qq trucs qui marche pas donc un peu cool mais pas trop", user1, new Date(2022,12,14)),
new Message(4, "Fefe63 est dans la place", user2, new Date(2022,12,15)),
]
, user1.getUsername()+user2.getUsername())];
tabConv=[new Conversation(40,
[new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]),
new User(3, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, skin, [skin])],
[new Message(1, "bonjour", new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,12)),
new Message(2, "test", new User(2, "Fefe63", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,13))], "leNom")];
});
return tabConv;
}

@ -24,7 +24,9 @@ export default class LoaderGameApi implements ILoaderGame{
map.set(300,150);
map.set(450,1000);
const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
tab=[cookieClicker];
const ticTacToe= new GameSolo(2,"TicTacToe", "https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/f2/06/ef/f206ef53-7206-ffae-af6b-52460ba5636f/source/256x256bb.jpg", "/Games/Tic-Tac-Toe/tic-tac-toe.tsx", 1, 1, map);
tab=[cookieClicker,ticTacToe];
});
return tab;

@ -1,62 +0,0 @@
import LoaderUserApi from '../userServices/loaderUserApi';
import ILoaderUser from '../userServices/ILoaderUser';
import { Match } from '../../core/Match/match';
import MatchSolo from '../../core/Match/matchSolo';
import { GameSolo } from '../../core/gameSolo';
import tabUS from '../../constUser';
import { Conversation } from '../../core/conversation';
// Instances
const img = "";
let loader:ILoaderUser = new LoaderUserApi();
let map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
let match:Match = new MatchSolo(1, false, tabUS, game);
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
// Tests
describe('LoaderUserApi tests', () => {
describe('loadById tests', () => {
it('should return UserTest (id: 48)', () => {
expect(loader.loadByID(48)).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByID(99999999999)).toBe(null);
})
})
describe('loadByUserName tests', () => {
it('should return USerTest (name: WeshWesh)', () => {
expect(loader.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByUsername('jExistePas')).toBe(null);
})
})
describe('loadByUserNamePassword tests', () => {
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
expect(loader.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
})
})
describe('loadUserByMatch tests', () => {
it('should return tabUS', () => {
expect(loader.loadUserByMatch(match)).toEqual(tabUS);
})
it('should return null', () => {
expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
})
})
describe('loadUserByConversation tests', () => {
it('should return tabUS', () => {
expect(loader.loadUserByConversation(convo)).toEqual(tabUS);
})
})
})

@ -1,21 +0,0 @@
/*
import LoaderUserApi from '../userServices/loaderUserApi';
import SaverUserApi from '../userServices/saverUserApi';
// Instances
let saver:SaverUserApi = new SaverUserApi();
let loader = new LoaderUserApi();
// Tests
describe('SaverUserApi tests', () => {
describe('saverUser tests', () => {
})
})
*/
it('should return true', () => {
expect(1+1).toBe(2);
})

@ -1,78 +0,0 @@
import StubUser from '../userServices/stub';
import { User } from '../../core/User/user';
import { Skin } from '../../core/skin';
import { GameSolo } from '../../core/gameSolo';
import MatchSolo from '../../core/Match/matchSolo';
import { Match } from '../../core/Match/match';
import { Conversation } from '../../core/conversation';
// Instances
const img = "";
let stub:StubUser = new StubUser();
let map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
let tabUS:User[] = [
new User(1, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
new User(2, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
new User(3, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)],),
new User(4, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin(1, "Bob", img, 0), [new Skin(1, "Bob", img, 0)]),
];
let game:GameSolo = new GameSolo(1, 'SuperJeu', img, 'source', 1, 1, map);
let match:Match = new MatchSolo(1, false, tabUS, game);
let convo:Conversation = new Conversation(1, tabUS, [], 'superConvo');
// Tests
describe('StubUser tests', () => {
describe('loadAllUser tests', () => {
it('should return tabUS', () => {
expect(stub.loadAllUser()).toEqual(tabUS);
})
})
describe('loadById tests', () => {
it('should return UserTest (id: 48)', () => {
expect(stub.loadByID(48)).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByID(999999999999)).toBe(null);
})
})
describe('loadByUserName tests', () => {
it('should return USerTest (name: WeshWesh)', () => {
expect(stub.loadByUsername('WeshWesh')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByUsername('jExistePas')).toBe(null);
})
})
describe('loadByUserNamePassword tests', () => {
it('should return UserTest (name: WeshWesh, password: MdpDeOuf)', () => {
expect(stub.loadByUsernamePassword('WeshWesh', 'MdpDeOuf')).toEqual(tabUS[0]);
})
it('should return null', () => {
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toBe(null);
})
})
describe('loadUserByMatch tests', () => {
it('should return tabUS', () => {
expect(stub.loadUserByMatch(match)).toEqual(tabUS);
})
it('should return null', () => {
expect(stub.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null);
})
})
describe('loadUserByConversation tests', () => {
it('should return tabUS', () => {
expect(stub.loadUserByConversation(convo)).toEqual(tabUS);
})
})
describe('loadLastId', () => {
it('should return U0005', () => {
expect(stub.loadLastId()).toBe('U0005');
})
})
})

@ -43,10 +43,4 @@ export default interface ILoaderUser{
* return an array of User
*/
loadUserByConversation(c:Conversation): Promise<User[]>;
/**
* loadLastId methode that load the last id used to create a user
* return a String
*/
loadLastId(): Promise<number>;
}

@ -104,7 +104,7 @@ export default class LoaderUserApi implements ILoaderUser{
.then(function (response: any) {
const tabTest=[new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0),
new Skin(2, "Bob Blue","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBlue.png", 100)];
user=new User(1, username, password, "ouioui", "homme", new Date(2022,12,12), 200, 123324, 12, new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0), tabTest);
user=new User(1, username, password, "ouioui", "homme", new Date(2022,12,12), 0, 0, 12, tabTest[0], tabTest);
});
return user;
}
@ -129,8 +129,4 @@ export default class LoaderUserApi implements ILoaderUser{
}
return 1;
}
}

@ -1,5 +1,7 @@
import { Conversation } from "../../core/conversation";
import { GameSolo } from "../../core/gameSolo";
import { Match } from "../../core/Match/match";
import MatchSolo from "../../core/Match/matchSolo";
import { Skin } from "../../core/skin";
import { User } from "../../core/User/user";
import ILoaderUser from "./ILoaderUser";
@ -8,12 +10,24 @@ export default class StubUser implements ILoaderUser{
skin:Skin=new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0);
tabUS:User[]=[
new User(1, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]),
new User(2, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]),
];
convo:Conversation = new Conversation(1, this.tabUS, [], 'superConvo');
map = new Map<number, number>([
[50, 3],
[75, 4],
[100, 5],
[150, 6]
]);
game:GameSolo = new GameSolo(1, 'SuperJeu', "", 'source', 1, 1, this.map);
match:Match = new MatchSolo(1, false, this.tabUS, this.game);
async loadAllUser(): Promise<User[]> {
return this.tabUS;
}
@ -58,8 +72,4 @@ export default class StubUser implements ILoaderUser{
return tabUser;
}
async loadLastId(): Promise<number> {
throw new Error("Method not implemented.");
}
}

@ -9,4 +9,5 @@ let myMap = new Map<number, number>([
let game=new GameSolo(1, "bo jeu", "", "super jeu", 1, 1, myMap);
export default game;

@ -22,6 +22,6 @@
"include": [
"**/*.ts",
"**/*.tsx"
],
, "socketConfig.js", "server.js" ],
"extends": "expo/tsconfig.base"
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save