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
Mathilde JEAN 3 years ago
commit 0730d1621f

@ -2,13 +2,21 @@ import MainTabNavigator from './src/navigation/AppNavigator'
import store from './src/redux/store'
import { Provider } from 'react-redux'
import LoaderUserApi from './src/services/userServices/loaderUserApi'
import ManagerUser from './src/services/userServices/ManagerUser'
import ManagerUser from './src/services/userServices/managerUser'
import FakeSaverUser from './src/services/userServices/fakeSaverUser'
import React, { useCallback } from 'react';
import { useUserStore } from './userContext';
import { useUserStore } from './src/context/userContext';
import ManagerConversation from './src/services/conversationService/managerConversation'
import { LoaderConversationApi } from './src/services/conversationService/loaderConversationApi'
import { FakeSaverConversation } from './src/services/conversationService/fakeSaverConversation'
import ManagerMatch from './src/services/matchServices/managerMatch'
import LoaderMatchApi from './src/services/matchServices/loaderMatchApi'
import SaverMatchApi from './src/services/matchServices/saverMatchApi'
export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser);
export const MANAGER_CONVERSATION = new ManagerConversation(new LoaderConversationApi, new FakeSaverConversation);
export const MANAGER_MATCH = new ManagerMatch(new LoaderMatchApi, new SaverMatchApi);
export default function App() {

@ -0,0 +1,221 @@
import React, { Component, useEffect, useState } from 'react'
import {
StyleSheet,
TouchableOpacity,
Text,
View,
Pressable,
Image,
TouchableHighlight,
Alert,
} from 'react-native'
import { MANAGER_USER } from '../../../App';
import { useMatchStore } from '../../context/matchContext';
import { useUserStore } from '../../context/userContext';
import { Match } from '../../core/Match/match';
import { User } from '../../core/User/user';
function CookieClicker(props: { navigation: any}){
const { navigation } = props
const GAMING_TIME=15;
const setUser = useUserStore((state) => state.setUser);
const resetMatch = useMatchStore((state) => state.resetMatch);
const [count, setCount] = useState(0);
const [money, setMoney] = useState(0);
const [clickSpeed, setClickSpeed] = useState(1);
const [grandmaCost, setGrandmaCost] = useState(10);
const [farmCost, setFarmCost] = useState(250);
const [factoryCost, setFactoryCost] = useState(2000);
const [wizardCost, setWizardCost] = useState(25000);
const [portalCost, setPortalCost] = useState(200000);
const [timer, setTimer] = useState(GAMING_TIME);
function onPressCookie(){
setMoney(money+clickSpeed);
setCount(count+clickSpeed);
}
function onPressGrandma(){
if (money>=grandmaCost){
setMoney(money-grandmaCost);
setClickSpeed(clickSpeed+1);
setGrandmaCost(grandmaCost+10);
}
}
function onPressFarm(){
if (money>=farmCost){
setMoney(money-farmCost);
setClickSpeed(clickSpeed+25);
setFarmCost(farmCost+250);
}
}
function onPressFactory(){
if (money>=factoryCost){
setMoney(money-factoryCost);
setClickSpeed(clickSpeed+200);
setFactoryCost(factoryCost+2000);
}
}
function onPressWizard(){
if (money>=wizardCost){
setMoney(money-wizardCost);
setClickSpeed(clickSpeed+2500);
setWizardCost(wizardCost+25000);
}
}
function onPressPortal(){
if (money>=portalCost){
setMoney(money-portalCost);
setClickSpeed(clickSpeed+20000);
setPortalCost(portalCost+200000);
}
}
function endGame(){
let tmp: User | null;
tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
if (useMatchStore().match?.getTabUsers().includes(tmp)){
useMatchStore().match?.updatePostMatch(tmp, count);
setUser(tmp);
}
resetMatch();
navigation.goBack();
}
}
useEffect(() => {
let counter=GAMING_TIME;
var oneSecInterval = setInterval(() => {
setTimer(timer => timer - 1);
counter --;
if (counter == 0) {
clearInterval(oneSecInterval);
Alert.alert("fin du jeu");
endGame();
}
}, 1000);
},[]);
return (
<View style={styles.container}>
<View >
<Text>
Timer: {timer}
</Text>
<TouchableHighlight onPress={onPressCookie} >
<Image style={styles.photo} source={{uri: 'https://cdn-icons-png.flaticon.com/512/614/614131.png'}}/>
</TouchableHighlight>
<Text>
Argent {money}
</Text>
<Text>
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'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {grandmaCost}
</Text>
</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'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {farmCost}
</Text>
</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'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {factoryCost}
</Text>
</View>
<TouchableHighlight onPress={onPressWizard}>
<Image style={styles.photo} source={{uri: 'https://www.clasher.us/images/coc/units/Wizard_Tower7.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {wizardCost}
</Text>
</View>
<TouchableHighlight onPress={onPressPortal}>
<Image style={styles.photo} source={{uri: 'https://i.pinimg.com/originals/98/29/21/9829215db6f9210c0ae4e318e854cb1f.png'}}/>
</TouchableHighlight>
<View>
<Text style={styles.cout}>
Cost {portalCost}
</Text>
</View>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
top: 20,
margin: 10,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
containerRight: {
flex: 1,
flexWrap: "wrap",
top: 100,
marginBottom: 20,
left: 100,
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10,
marginBottom: 10
},
button2: {
alignItems: 'center',
backgroundColor: '#FFDDFF',
padding: 10,
marginBottom: 10
},
photo: {
width: 50,
height: 50
},
cout: {
marginBottom: 20
}
})
export default CookieClicker;

@ -1,4 +1,4 @@
import { FC, ReactNode } from "react"
import { FC, ReactNode, useCallback } from "react"
import { Pressable, Image, View} from "react-native"
import React from "react"
@ -6,6 +6,10 @@ import React from "react"
Importing the correct stylesheet
*/
import styles from './style/BotBar.style';
import { useStoreStore } from "../context/storeContext";
import { MANAGER_CONVERSATION, MANAGER_USER } from "../../App";
import tabSkinApp from "../constSkin";
import { useConversationStore } from "../context/conversationContext";
/*
Images that are required to create a bottom bar
@ -35,6 +39,37 @@ export const BotBar :
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];
let tmp=MANAGER_USER.getCurrentUser()?.getTabSkin();
if (tmp!=undefined){
tmp.forEach(skin => {
for (let i=0; i<tabSkinStore.length; i++){
if(skin.isEqual(tabSkinStore[i])){
tabSkinStore.splice(i,1);
}
}
});
setTabSkin(tabSkinStore);
}
}, []);
const handleConversationChange = useCallback(async () => {
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=undefined){
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {
MANAGER_CONVERSATION.setCurrentTabConv(res);
setTabConv(res);
});
}
}, []);
/*
By default, all the images are the white ones
*/
@ -66,7 +101,7 @@ FC<{nav: any, state?: String}> =
*/
return (
<View style={styles.footer}>
<Pressable onPress={() => nav.navigate('ChatTab')}>
<Pressable onPress={() => {handleConversationChange() ;nav.navigate('ChatTab')}}>
<Image
style={styles.icon}
source={imgLeft}
@ -78,7 +113,7 @@ FC<{nav: any, state?: String}> =
source={imgMid}
/>
</Pressable>
<Pressable onPress={() => nav.navigate('StoreTab')}>
<Pressable onPress={() => {handleStoreChange(); nav.navigate('StoreTab')}}>
<Image
style={styles.icon}
source={imgRight}

@ -9,30 +9,34 @@ import { Conversation } from "../core/conversation"
*/
import styles from "./style/ConverstationComponent.style"
import { SkinComponent } from "./Skin"
import { User } from "../core/User/user"
import { MANAGER_USER } from "../../App"
export const ConversationComponent :
/* Parameters :
* skin : Skin to be displayed
* state : Indicates from wich screen the component has been called
*/
FC<{conv: Conversation, state: String}> =
({conv, state}) =>
{
FC<{conv: Conversation, state: String, navigation: any}> =
({conv, state, navigation}) =>
{
/* The display of this component depends of the screen from where it has been called:
* From the TopBar (icon) : Small image in a circle
* From the shop (shop) : Image + Name + Price, Pressable => Buy the skin
* From the profile (profile) : Name + Image, Pressable => Change the skin
*/
switch (state) {
case 'Preview':
return(
<View style={{flexDirection: 'row', height: 70, borderBottomWidth: 2,borderBottomColor: '#2D2C33', paddingLeft: '5%',}}>
<View style={{alignSelf: 'center'}}>
<SkinComponent skin={conv.getTabUser()[1].getCurrentSkin()} state='icon'/>
<SkinComponent skin={conv.getLastMessage().getMessageSender().getCurrentSkin()} state='icon' nav={navigation}/>
</View>
<View style={{marginLeft: '5%', justifyContent: 'space-evenly'}}>
<Text style={styles.textNom}>{conv.getTabUser()[1].getUsername()}</Text>
<Text style={styles.textMess}>{conv.getLastMessage()}</Text>
<Text style={styles.textNom}>{conv.getLastMessage().getMessageSender().getUsername()}</Text>
<Text style={styles.textMess}>{conv.getLastMessage().getMessageContent()}</Text>
</View>
</View>
)

@ -8,8 +8,14 @@ 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 { MANAGER_MATCH, MANAGER_USER } from "../../App"
import { useMatchStore } from "../context/matchContext"
export const GameComponent :
/*
* game : Game that must be displayed
* nav : tool needed to allow the navigation between the screens
@ -17,15 +23,33 @@ export const GameComponent :
FC<{game: Game, nav: any}> =
({game, nav}) =>
{
const setMatch = useMatchStore((state) => state.setMatch);
async function createNewMatchSolo(game : Game, nav: any) {
const m=new MatchCreator();
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
let match=await m.createMatch(tmp, game);
MANAGER_MATCH.setCurrentMatch(match);
setMatch(match);
nav.navigate("GameSolo");
}
}
return (
<View>
<Pressable onPress={() => Alert.alert("Lancement du jeu")}>
<Pressable onPress={() => createNewMatchSolo(game, nav)}>
<Image
style={styles.image}
source={game.getImageSource()}
source={{uri: game.getImageSource()}}
/>
<Text style={styles.name}>{game.getName()}</Text>
</Pressable>
</View>
)
}
)
}

@ -1,4 +1,4 @@
import { FC, ReactNode } from "react"
import { FC, ReactNode, useCallback } from "react"
import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native"
import React from "react"
import { Skin } from "../core/skin"
@ -11,16 +11,87 @@ import { useDispatch, useSelector } from "react-redux"
import { loginUser } from "../redux/features/currentUserSlice"
import { RootState } from "../redux/store"
import { MANAGER_USER } from "../../App"
import { useUserStore } from "../context/userContext"
import { ManagerCoinsUser } from "../core/User/userCoinsModifier"
import ManagerUser from "../services/userServices/managerUser"
import UserSkinModifier from "../core/User/userSkinModifier"
import { useStoreStore } from "../context/storeContext"
import tabSkinApp from "../constSkin"
export const SkinComponent :
/* Parameters :
* skin : Skin to be displayed
* state : Indicates from wich screen the component has been called
*/
FC<{skin: Skin, state: String}> =
({skin, state}) =>
FC<{nav : any, skin: Skin, state: String}> =
({nav, skin, state}) =>
{
const navigation = nav;
const dispatch=useDispatch();
const setUser = useUserStore((state) => state.setUser);
const setTabSkin = useStoreStore((state) => state.setTabSkin);
async function changerSkin(skin:Skin) {
const m=new UserSkinModifier();
const tmp = MANAGER_USER.getCurrentUser();
if (tmp!=null){
await m.changeCurrentSkin(tmp, skin);
setUser(tmp);
MANAGER_USER.setCurrentUser(tmp);
}
}
const handleStoreChange = useCallback(async () => {
let tabSkinStore=[...tabSkinApp];
let tmp=MANAGER_USER.getCurrentUser()?.getTabSkin();
if (tmp!=undefined){
tmp.forEach(skin => {
for (let i=0; i<tabSkinStore.length; i++){
if(skin.isEqual(tabSkinStore[i])){
tabSkinStore.splice(i,1);
}
}
});
setTabSkin(tabSkinStore);
}
}, []);
async function buySkin(skin:Skin) {
const mSkin=new UserSkinModifier();
const mCoins= new ManagerCoinsUser();
const tmp = MANAGER_USER.getCurrentUser();
if (tmp!=null){
await mCoins.removeCoins(tmp,skin.getSkinCost()).then(async (res) => {
if(res==true){
await mSkin.addSkin(tmp, skin);
setUser(tmp);
MANAGER_USER.setCurrentUser(tmp);
Alert.alert("Achat du skin");
handleStoreChange();
}
else{
Alert.alert("Pas assez d'argent pour acheter le skin");
}
});
}
}
/* The display of this component depends of the screen from where it has been called:
@ -32,38 +103,38 @@ FC<{skin: Skin, state: String}> =
case 'icon':
return (
<View>
<Image source={skin.getSkinSource()} style={styles.icon}/>
<Image source={{uri: skin.getSkinSource()}} style={styles.icon}/>
</View>
)
case 'shop':
return(
<Pressable onPress={() => Alert.alert("Achat du skin")} style={styles.imageWrapper}>
<Pressable onPress={() => buySkin(skin)} style={styles.imageWrapper}>
<Text style={styles.nomSkin}>{skin.getSkinName()}</Text>
<Image
style={styles.imageSkin}
source={skin.getSkinSource()}
source={{uri: skin.getSkinSource()}}
/>
<Text style={styles.nomSkin}>100</Text>
</Pressable>
)
case 'liste':
return(
<Pressable onPress={() => {MANAGER_USER.getCurrentUser().setCurrentSkin(skin)}} style={styles.imageWrapper}>
<Pressable onPress={() => {changerSkin(skin); navigation.goBack()}} style={styles.imageWrapper}>
<Text style={styles.nomSkin}>{skin.getSkinName()}</Text>
<Image
style={styles.imageSkin}
source={skin.getSkinSource()}
source={{uri: skin.getSkinSource()}}
/>
</Pressable>
)
case 'profile':
return(
<Pressable onPress={() => Alert.alert("Achat du skin")} style={styles.imageWrapperProfil}>
<Pressable onPress={() => Alert.alert("cool")} style={styles.imageWrapperProfil}>
<Text style={styles.nomSkin}>{skin.getSkinName()}</Text>
<Image
style={styles.imageSkin}
source={skin.getSkinSource()}
source={{uri: skin.getSkinSource()}}
/>
</Pressable>
)
@ -71,7 +142,7 @@ FC<{skin: Skin, state: String}> =
return(
<Image
style={styles.imageSkin}
source={skin.getSkinSource()}
source={{uri: skin.getSkinSource()}}
/>
)
}

@ -12,6 +12,8 @@ import styles from './style/TopBar.style';
import { useSelector } from "react-redux"
import { RootState } from "../redux/store"
import { MANAGER_USER } from "../../App"
import { useUserStore } from "../context/userContext"
import { useMatchStore } from "../context/matchContext"
/*
Images required
@ -30,6 +32,9 @@ export const TopBar :
FC<{nav: any, state?: string}> =
({nav, state}) =>
{
const resetMatch = useMatchStore((state) => state.resetMatch);
/* The display of this component depends of the screen from where it has been called:
* From the Settings (icon) : Name of the page + cross button
@ -48,11 +53,25 @@ FC<{nav: any, state?: string}> =
</Pressable>
</View>
)
case 'matchmacking':
return (
<View style={styles.header}>
<Pressable>
<Image source={msc} style={styles.icon}/>
</Pressable>
<Text style={styles.titre}>BOB PARTY</Text>
<Pressable onPress={() => { resetMatch(); nav.goBack()}}>
<Image source={cross} style={styles.icon}/>
</Pressable>
</View>
)
default:
return (
<View style={styles.header}>
<Pressable onPress={() => nav.navigate('ProfileTab', {screen: 'Profile'})}>
<SkinComponent skin={MANAGER_USER.getCurrentUser().getCurrentSkin()} state='icon' />
<SkinComponent skin={MANAGER_USER.getCurrentUser().getCurrentSkin()} state='icon' nav={nav} />
</Pressable>
<Text style={styles.titre}>BOB PARTY</Text>
<Pressable onPress={() => nav.navigate('Settings')}>

@ -2,13 +2,13 @@ import { Skin } from "./core/skin";
const img = "";
let tabSkinApp:Skin[]=[
new Skin("S0001", "Bob", img, 0),
new Skin("S0002", "Bob Blue", img, 100),
new Skin("S0003", "Bob BW", img, 100),
new Skin("S0004", "Bob Green", img, 100),
new Skin("S0005", "Bob P&T", img, 100),
new Skin("S0006", "Bob Red", img, 100),
new Skin("S0007", "Bob Cute", img, 100),
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),
new Skin(3, "Bob BW","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBW.png", 100),
new Skin(4, "Bob Green","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobGreen.png", 100),
new Skin(5, "Bob P&T", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobPinkTurquoise.png", 100),
new Skin(6, "Bob Red", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobRed.png", 100),
new Skin(7, "Bob Cute", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png", 100),
]

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

@ -0,0 +1,18 @@
import React from "react";
import create from "zustand";
import { Match } from "../core/Match/match";
// Define store types
interface MatchState {
match: Match | null;
setMatch: (match: Match|null) => void;
resetMatch: () => void;
}
// Define store data and methods
export const useMatchStore = create<MatchState>()((set, get) => ({
match: null,
setMatch: (match) => set((state) => ({ match: match })),
resetMatch: () => set((state) => ({ match: null })),
}));

@ -0,0 +1,22 @@
import React from "react";
import create from "zustand";
import { MANAGER_USER } from "../../App";
import tabSkinApp from "../constSkin";
import { Skin } from "../core/Skin";
import { User } from "../core/User/user";
// Define store types
interface StoreState {
tabSkin: Skin[];
setTabSkin: (tabSkin: Skin[]) => void;
resetTabSkin: () => void;
}
// Define store data and methods
export const useStoreStore = create<StoreState>()((set, get) => ({
tabSkin: tabSkinApp,
setTabSkin: (tabSkin) => set((state) => ({ tabSkin: tabSkin })),
resetTabSkin: () => set((state) => ({ tabSkin: tabSkinApp })),
}));

@ -1,6 +1,6 @@
import React from "react";
import create from "zustand";
import { User } from "./src/core/User/user";
import { User } from "../core/User/user";
// Define store types
@ -14,5 +14,5 @@ interface UserState {
export const useUserStore = create<UserState>()((set, get) => ({
user: null,
setUser: (user) => set((state) => ({ user: user })),
resetUser: () => set((state) => ({ user: undefined })),
resetUser: () => set((state) => ({ user: null })),
}));

@ -3,7 +3,7 @@ import { ImageSourcePropType } from "react-native";
import internal from "stream";
export abstract class Game{
readonly id:string;
readonly id:number;
private name:string;
private imageSource:string;
private gameSource:string;
@ -11,7 +11,7 @@ export abstract class Game{
private nbPlayerMax:number;
/* Constructor of the class */
constructor (id:string, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
constructor (id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
this.id=id;
this.name=name;
this.imageSource=imageSource;

@ -1,17 +1,17 @@
import { ImageSourcePropType } from 'react-native';
import { Game } from './game';
import { User } from "./User/user";
import { Game } from '../game';
import { User } from "../User/user";
export abstract class Match{
readonly code:string;
private inGame:Boolean;
readonly code:number;
private inGame:Boolean=false;
private tabUsers:User[];
private theGame:Game;
constructor(code:string, inGame:Boolean, tabUser:User[], game:Game){
constructor(code:number, inGame:Boolean, tabUser:User[], game:Game){
this.code=code;
this.inGame=false;
this.inGame=inGame;
this.tabUsers=[...tabUser];
this.theGame=game;
}

@ -1,12 +1,12 @@
import { Match } from "./match";
import { User } from "./User/user";
import { Game } from "./game";
import { GameCasino } from "./gameCasino";
import { ManagerCoinsUser } from "./User/userCoinsModifier";
import { User } from "../User/user";
import { Game } from "../game";
import { GameCasino } from "../gameCasino";
import { ManagerCoinsUser } from "../User/userCoinsModifier";
export class MatchMulti extends Match{
export default class MatchCasino extends Match{
constructor(code:string, inGame:Boolean, tabUser:User[], game:GameCasino){
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameCasino){
super(code, inGame, tabUser, game);
}

@ -0,0 +1,12 @@
import { MANAGER_MATCH } from "../../../App";
import ManagerMatch from "../../services/matchServices/managerMatch";
import { Game } from "../game";
import { User } from "../User/user";
import { Match } from "./match";
export default class MatchCreator{
async createMatch(u:User, g:Game): Promise<Match>{
return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g);
}
}

@ -0,0 +1,17 @@
import { Match } from "./match";
import { User } from "../User/user";
import { Game } from "../game";
import { GameMulti } from "../gameMulti";
import { ManagerCoinsUser } from "../User/userCoinsModifier";
export default class MatchMulti extends Match{
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameMulti){
super(code, inGame, tabUser, game);
}
updatePostMatch(user:User, points: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(points));
}
}

@ -0,0 +1,17 @@
import { Match } from "./match";
import { GameSolo } from "../gameSolo";
import { User } from "../User/user";
import { Game } from "../game";
import { ManagerCoinsUser } from "../User/userCoinsModifier";
export default class MatchSolo extends Match{
constructor(code:number, inGame:Boolean, tabUser:User[], game:GameSolo){
super(code, inGame, tabUser, game);
}
updatePostMatch(user:User, points: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(points));
}
}

@ -5,7 +5,7 @@ import { TextBase } from 'react-native';
export class User{
readonly id: string;
readonly id: number;
private username: string;
private password: string;
private nationality: string;
@ -18,7 +18,7 @@ export class User{
private tabSkin: Skin[];
/* Consturctor of the class */
constructor(id: string, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number,
constructor(id: number, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number,
nbGamesPlayed:number, currentSkin: Skin, tabSkin: Skin[]){
this.id=id;
this.username=username;
@ -30,7 +30,7 @@ export class User{
this.currentCoins=currentCoins;
this.totalCoins=totalCoins;
this.currentSkin=currentSkin;
this.tabSkin=[];
this.tabSkin=tabSkin;
}

@ -1,5 +1,5 @@
import { MANAGER_USER } from "../../../App";
import ManagerUser from "../../services/userServices/ManagerUser";
import ManagerUser from "../../services/userServices/managerUser";
import { User } from "./user";
export class ManagerCoinsUser{
@ -11,9 +11,13 @@ export class ManagerCoinsUser{
await MANAGER_USER.getsaverUser().updateUser(u);
}
async removeCoins(u:User, coins:number){
u.setCurrentCoins(u.getCurrentCoins()-coins);
await MANAGER_USER.getsaverUser().updateUser(u);
async removeCoins(u:User, coins:number): Promise<boolean>{
if (u.getCurrentCoins()>=coins){
u.setCurrentCoins(u.getCurrentCoins()-coins);
await MANAGER_USER.getsaverUser().updateUser(u);
return true;
}
return false;
}
async changeCurrentCoins(u:User, coins:number){

@ -1,28 +1,14 @@
import { User } from "./user";
import tabSkinApp from "../../constSkin";
import { Conversation } from "../conversation";
import ManagerUser from "../../services/userServices/ManagerUser";
import ManagerUser from "../../services/userServices/managerUser";
import { MANAGER_USER } from "../../../App";
export class UserCreator{
async createUser(username:string, password:string, nationality:string, sexe:string, date:Date){
//Récup l'ID d'après dans la bdd
let u:User;
let newId:string="";
let oldId = await MANAGER_USER.getLoaderUser().loadLastId();
oldId=oldId.slice(1);
let leInt=parseInt(oldId);
newId+="U";
for (let i = 0; i < 4-leInt.toString().length; i++) {
newId = newId + "0";
}
leInt+=1;
newId=newId+leInt;
console.log(newId);
u = new User(newId, username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]);
await MANAGER_USER.getsaverUser().saveUser(u);
let u:null|User = await MANAGER_USER.getsaverUser().saveUser(username, password, nationality, sexe, date);
MANAGER_USER.setCurrentUser(u);
return u;
}

@ -9,7 +9,7 @@ export default class UserModificationManager{
}
async changeUsername(user:User, username:string){
user.setPassword(username);
user.setUsername(username);
await MANAGER_USER.getsaverUser().updateUser(user);
}

@ -3,14 +3,14 @@ import { User } from "./User/user";
export class Conversation{
private Id: string;
private id: number;
private tabUser: User[];
private tabMessage: Message[];
private name: string;
/* Constructor of the class */
constructor(id: string, tabUser: User[], tabMessage:Message[], name:string){
this.Id=id;
constructor(id: number, tabUser: User[], tabMessage:Message[], name:string){
this.id=id;
this.tabUser=[...tabUser];
this.tabMessage=[...tabMessage];
this.name=name;
@ -40,7 +40,7 @@ export class Conversation{
/* Brief : function returning the id of a conversation */
getId(){
return this.Id;
return this.id;
}
/* Brief : function returning the name to a conversation */
@ -56,7 +56,7 @@ export class Conversation{
/* Brief : function returning the last message of a conversation */
getLastMessage(){
this.sortMessageDesc();
return this.tabMessage[0].getMessageContent();
return this.tabMessage[0];
}
/* Brief : function sorting the messages of a conversation to be in the discussion order */

@ -3,7 +3,7 @@ import { Game } from './game'
export class GameCasino extends Game{
constructor(id:string, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){
super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
}

@ -4,7 +4,7 @@ import { Game } from './game'
export class GameMulti extends Game{
readonly rankToCoins:Map<number,number>
constructor(id:string, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map<number,number>){
super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax);
this.rankToCoins=rankToCoins;
}

@ -4,7 +4,7 @@ import { Game } from './game'
export class GameSolo extends Game{
readonly ptsToCoins:Map<number,number>
constructor(id:string, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map<number,number>){
super(id, name, imageSource, gameSource, nbPlayerMin,nbPlayerMax);
this.ptsToCoins=ptsToCoins;
}

@ -1,17 +0,0 @@
import { Match } from "./match";
import { User } from "./User/user";
import { Game } from "./game";
import { GameMulti } from "./gameMulti";
import { ManagerCoinsUser } from "./User/userCoinsModifier";
export class MatchMulti extends Match{
constructor(code:string, inGame:Boolean, tabUser:User[], game:GameMulti){
super(code, inGame, tabUser, game);
}
updatePostMatch(user:User, points: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(points));
}
}

@ -1,17 +0,0 @@
import { Match } from "./match";
import { GameSolo } from "./gameSolo";
import { User } from "./User/user";
import { Game } from "./game";
import { ManagerCoinsUser } from "./User/userCoinsModifier";
export class MatchSolo extends Match{
constructor(code:string, inGame:Boolean, tabUser:User[], game:GameSolo){
super(code, inGame, tabUser, game);
}
updatePostMatch(user:User, points: number): void {
const manage= new ManagerCoinsUser();
manage.addCoins(user, this.getGame().coinsCalculator(points));
}
}

@ -2,52 +2,52 @@ import { User } from './User/user'
export class Message{
private Id: string;
private Content: string;
private Sender: User;
private DateEnvoie: Date;
private id: number;
private content: string;
private sender: User;
private dateEnvoie: Date;
/* Constructor of the class */
constructor(id: string, content: string, sender:User, dateEnvoie:Date){
this.Id=id;
this.Content=content;
this.Sender=sender;
this.DateEnvoie=dateEnvoie;
constructor(id: number, content: string, sender:User, dateEnvoie:Date){
this.id=id;
this.content=content;
this.sender=sender;
this.dateEnvoie=dateEnvoie;
}
/* Brief : Function setting the content of a message */
setMessageContent(content: string){
this.Content=content;
this.content=content;
}
/* Brief : Function setting the sender of a message */
setMessageSender(sender: User){
this.Sender=sender;
this.sender=sender;
}
/* Brief : Function setting the date of a message */
setMessageDate(dateEnvoie: Date){
this.DateEnvoie=dateEnvoie;
this.dateEnvoie=dateEnvoie;
}
/* Brief : Function getting the id of a message */
getMessageId(){
return this.Id;
return this.id;
}
/* Brief : Function getting the content of a message */
getMessageContent(){
return this.Content;
return this.content;
}
/* Brief : Function getting the sender of a message */
getMessageSender(){
return this.Sender;
return this.sender;
}
/* Brief : Function getting the date of a message */
getMessageDate(){
return this.DateEnvoie;
return this.dateEnvoie;
}

@ -1,13 +1,13 @@
import { ImageSourcePropType } from "react-native";
export class Skin{
readonly id: string;
readonly id: number;
private name: string;
private source: string;
private cost:number;
/* Constructor of the class */
constructor(id:string, name: string, source:string, Cost:number){
constructor(id:number, name: string, source:string, Cost:number){
this.id=id;
this.name=name;
this.source=source;
@ -48,4 +48,8 @@ export class Skin{
setSkinCost(cost:number){
this.cost=cost;
}
isEqual(s:Skin){
return this.id==s.id;
}
}

@ -7,20 +7,20 @@ import { User } from '../User/user';
// Instances
const img = "";
let tab:Skin[] = [];
let classique = new Skin("S0001", "Bob", img, 0);
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 dateBirth = new Date(2010,0o3,0o7);
let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab);
let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab);
let usr = new User(1, 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab);
let usr2 = new User(2, 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab);
let theDate = new Date(2022,10,14);
let theDate2 = new Date(2022,10,13);
let theDate3 = new Date(2022,10,15);
let mess = new Message('M0001', 'Bob Party est le meilleur projet', usr, theDate2);
let mess = new Message(1, 'Bob Party est le meilleur projet', usr, theDate2);
let tabU:User[] = [usr, usr2];
let mess2 = new Message('M0002', 'Oui tout à fait', usr2, theDate);
let mess3 = new Message('M0003', 'Mais oui trop de ouf', usr, theDate3);
let mess2 = new Message(2, 'Oui tout à fait', usr2, theDate);
let mess3 = new Message(3, 'Mais oui trop de ouf', usr, theDate3);
let tabM:Message[] = [mess, mess2];
let convo = new Conversation('C0001', tabU, tabM, 'the conv');
let usr3 = new User('00003', 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab);
let convo = new Conversation(1, tabU, tabM, 'the conv');
let usr3 = new User(4, 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab);
// Get tests

@ -1,4 +1,5 @@
import { MatchSolo } from '../MatchSolo';
import { MatchSolo } from '../Match/matchSolo';
import { Conversation } from '../Conversation';
import { Skin } from '../Skin';
import { User } from '../User/user';
import { GameSolo } from '../GameSolo';

@ -12,7 +12,8 @@ import SkinList from '../screens/SkinList'
import GameChoice from '../screens/GameChoice'
import SignIn from '../screens/SignIn'
import SignUp from '../screens/SignUp'
import LobbySolo from '../screens/LobbySolo'
import CookieClicker from '../Games/CookieClicker/cookieClicker'
const HomeStack = createStackNavigator();
@ -25,7 +26,7 @@ function HomeStackScreen() {
<HomeStack.Navigator screenOptions={{ headerShown: false}}>
<HomeStack.Screen name="Home" component={Home} options={{animationEnabled: false,}}/>
<HomeStack.Screen name="Settings" component={Settings} />
<HomeStack.Screen name='GameChoice' component={GameChoice} options={{animationEnabled: false,}}/>
<HomeStack.Screen name='GameChoiceTab' component={GameChoiceStackScreen} options={{animationEnabled: false,}}/>
</HomeStack.Navigator>
);
}
@ -70,6 +71,34 @@ function ProfileStackScreen() {
);
}
const GameChoiceStack = createStackNavigator();
/*
Stack of screens for the profile and the changement of informations
*/
function GameChoiceStackScreen() {
return (
<GameChoiceStack.Navigator screenOptions={{headerShown: false}}>
<GameChoiceStack.Screen name='GameChoice' component={GameChoice} options={{animationEnabled: false,}}/>
<GameChoiceStack.Screen name='GameSolo' component={GameSoloStackScreen} options={{animationEnabled: false,}}/>
</GameChoiceStack.Navigator>
);
}
const GameSoloStack = createStackNavigator();
/*
Stack of screens for the profile and the changement of informations
*/
function GameSoloStackScreen() {
return (
<GameSoloStack.Navigator screenOptions={{headerShown: false}}>
<GameSoloStack.Screen name='LobbySolo' component={LobbySolo} options={{animationEnabled: false,}}/>
<GameSoloStack.Screen name='CookieClicker' component={CookieClicker} />
</GameSoloStack.Navigator>
);
}
const Tab = createBottomTabNavigator()
/*
Tab navigator to navigate between the stacks

@ -1,15 +1,17 @@
import { StatusBar } from 'expo-status-bar'
import {View} from 'react-native'
import React from 'react';
import React, { useCallback } from 'react';
import stylesScreen from './style/screens.style';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { FlatList } from 'react-native-gesture-handler';
import { ConversationComponent } from '../components/ConversationComponent';
import { Conversation } from '../core/conversation';
import { MANAGER_CONVERSATION, MANAGER_USER } from '../../App';
import { useConversationStore } from '../context/conversationContext';
function Chat(props: { navigation: any; }) {
const { navigation } = props
return (
<View style={stylesScreen.container}>
@ -18,12 +20,10 @@ function Chat(props: { navigation: any; }) {
/>
<View style={stylesScreen.bodyStart}>
{/*
<FlatList
data={MANAGER_USER.getCurrentUser().getTabConv()}
renderItem={({item}) => <ConversationComponent conv={item} state='Preview'/>}
data={useConversationStore().tabConv}
renderItem={({item}) => <ConversationComponent conv={item} state='Preview' navigation={navigation}/>}
/>
*/}
</View>
<BotBar
nav={navigation}

@ -13,12 +13,17 @@ import { GameSolo } from '../core/gameSolo';
let tabConv:Conversation[]=[];
const msc = require('../../assets/Icons/FondGris.png');
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, new Map([
[100, 100],
[1000, 300],
[10000, 400]
]));
//const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv);
const jeuTest= new GameSolo("1", "SNAKE", require('../../assets/Icons/UnSelected/Gamepad.png'),"ouin", 1, 1, new Map<number,number>);
function GameChoice(props: { navigation: any; }) {
const { navigation } = props
return (
<View style={styles.container}>
<TopBar
@ -26,7 +31,7 @@ function GameChoice(props: { navigation: any; }) {
/>
<View style={styles.body}>
<GameComponent
game={jeuTest}
game={cookieClicker}
nav={navigation}
/>
</View>

@ -6,41 +6,38 @@ import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { Conversation } from '../core/conversation';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { useSelector } from 'react-redux';
import { RootState } from '../redux/store';
//const test= new GameSolo("test", require('bob_party/assets/ImagesJeux/BatailleNavale.jpeg'), "test", );
let tabConv:Conversation[]=[];
function Home(props: { navigation: any; }) {
const { navigation } = props
return (
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
state= 'Home'
/>
<View style={stylesScreen.bodyCenter}>
<ButtonGameTypeChoice
title='Jouer Seul'
onPress={() => navigation.navigate('GameChoice')}
/>
<ButtonGameTypeChoice
title='Défier mes amis'
onPress={() => navigation.navigate('GameChoice')}
/>
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
state= 'Home'
/>
<View style={stylesScreen.bodyCenter}>
<ButtonGameTypeChoice
title='Jouer Seul'
onPress={() => navigation.navigate('GameChoiceTab')}
/>
<ButtonGameTypeChoice
title='Défier mes amis'
onPress={() => navigation.navigate('GameChoiceTab')}
/>
</View>
<BotBar
nav={navigation}
state='Home'
/>
</View>
<BotBar
nav={navigation}
state='Home'
/>
</View>
);
);
}
export default Home

@ -0,0 +1,40 @@
import { StatusBar } from 'expo-status-bar'
import { View, Image} from 'react-native'
import React from 'react';
import stylesScreen from './style/screens.style'
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { Conversation } from '../core/conversation';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { MANAGER_MATCH } from '../../App';
import { useMatchStore } from '../context/matchContext';
function LobbySolo(props: { navigation: any; }) {
const { navigation } = props
const match = useMatchStore().match;
return (
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
state='matchmacking'
/>
<View style={stylesScreen.bodyCenter}>
<ButtonGameTypeChoice
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 LobbySolo

@ -9,6 +9,7 @@ import { SkinComponent } from '../components/Skin';
import { ButtonGreySmall } from '../components/ButtonGreySmall';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { MANAGER_USER } from '../../App';
import { useUserStore } from '../context/userContext';
const coin = require('../../assets/Icons/Coin.png')
@ -24,22 +25,22 @@ function Profile(props: { navigation: any; }) {
/>
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Profil'/>
<Text style={styles.pseudoText}>{MANAGER_USER.getCurrentUser().getUsername()}</Text>
<Text style={styles.pseudoText}>{useUserStore().user?.getUsername()}</Text>
<View style={styles.coinSkinView}>
<View style={styles.coinView}>
<Image
style={styles.coin}
source={coin}
/>
<Text style={styles.coinText}>{MANAGER_USER.getCurrentUser().getCurrentCoins()}</Text>
<Text style={styles.coinText}>{useUserStore().user?.getCurrentCoins()}</Text>
</View>
<View style={styles.skinView}>
<SkinComponent skin={MANAGER_USER.getCurrentUser().getCurrentSkin()} state='profile' />
<ButtonGreySmall onPress={() => navigation.navigate('SkinList')} title='Changer de skin' state='Profile'/>
<SkinComponent skin={useUserStore().user?.getCurrentSkin()} state='profile' nav={navigation}/>
<ButtonGreySmall onPress={() => {navigation.navigate('SkinList');}} title='Changer de skin' state='Profile'/>
</View>
</View>
<View style={styles.infoView}>
<Text style={styles.infoText}>Total de BobCoin gagnés: {MANAGER_USER.getCurrentUser().getTotalCoins()}</Text>
<Text style={styles.infoText}>Total de BobCoin gagnés: {useUserStore().user?.getTotalCoins()}</Text>
<Text style={styles.infoText}>Total de BobCoin gagnés: </Text>
</View>
</View>

@ -11,8 +11,9 @@ import Dialog from "react-native-dialog"
import RNPickerSelect from "react-native-picker-select";
import { PickerGreySmall } from '../components/PickerGreySmall';
import { MANAGER_USER } from '../../App';
import { useUserStore } from '../../userContext';
import { useUserStore } from '../context/userContext';
import DialogInput from 'react-native-dialog-input';
import UserModificationManager from '../core/User/userModificationManager';
function Settings(props: { navigation: any; }) {
const { navigation } = props
@ -27,18 +28,24 @@ function Settings(props: { navigation: any; }) {
const [selectedNationality, setSelectedNationality] = useState("");
function changeUsername(username:string){
MANAGER_USER.getCurrentUser()?.setUsername(username);
console.log(MANAGER_USER.getCurrentUser()?.getUsername());
setUser(MANAGER_USER.getCurrentUser());
MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser());
async function changeUsername(username:string){
const m = new UserModificationManager();
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
await m.changeUsername(tmp, username);
setUser(tmp);
MANAGER_USER.setCurrentUser(tmp);
}
}
function changePassword(password:string){
MANAGER_USER.getCurrentUser()?.setPassword(password);
console.log(MANAGER_USER.getCurrentUser()?.getPassword());
setUser(MANAGER_USER.getCurrentUser());
MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser());
async function changePassword(password:string){
const m = new UserModificationManager();
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
await m.changePassword(tmp, password);
setUser(tmp);
MANAGER_USER.setCurrentUser(tmp);
}
}
const dispatch=useDispatch();
@ -55,24 +62,24 @@ function Settings(props: { navigation: any; }) {
<View style={{flexDirection: 'row', justifyContent: 'space-between',}}>
<View>
<View>
<Text style={styles.text}>Pseudo: {MANAGER_USER.getCurrentUser().getUsername()}</Text>
<Text style={styles.text}>Pseudo: {useUserStore().user?.getUsername()}</Text>
<ButtonGreySmall onPress={() => {console.log(dialogPseudoVisible);
;setDialogPseudoVisible(true)}} title='Changer le pseudo'/>
</View>
<View>
<Text style={styles.text}>Mot de passe: {MANAGER_USER.getCurrentUser().getPassword()}</Text>
<Text style={styles.text}>Mot de passe: {useUserStore().user?.getPassword()}</Text>
<ButtonGreySmall onPress={() => setDialogPasswordVisible(true) } title='Changer le mot de passe'/>
</View>
<View>
<Text style={styles.text}>Nationalité: {MANAGER_USER.getCurrentUser().getNationality()}</Text>
<Text style={styles.text}>Nationalité: {useUserStore().user?.getNationality()}</Text>
<PickerGreySmall title='Changer la nationalité' valueChange={(value:string) => setSelectedNationality(value)} donePress={() => dispatch(updateNationality(selectedNationality))} values={["Francais", "Anglais"]} />
</View>
<View>
<Text style={styles.text}>Sexe: {MANAGER_USER.getCurrentUser().getSexe()}</Text>
<Text style={styles.text}>Sexe: {useUserStore().user?.getSexe()}</Text>
<PickerGreySmall title='Changer le sexe' valueChange={(value:string) => setSelectedSex(value)} donePress={() => dispatch(updateSex(selectedSex))} values={["Homme", "Femme", "Autre"]} />
</View>
</View>
<Text style={styles.textID}>ID: {MANAGER_USER.getCurrentUser().getId()}</Text>
<Text style={styles.textID}>ID: {useUserStore().user?.getId()}</Text>
</View>
</View>
</View>

@ -10,7 +10,7 @@ import { RootState } from '../redux/store';
import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice';
import Dialog from "react-native-dialog";
import { MANAGER_USER } from '../../App';
import { useUserStore } from '../../userContext';
import { useUserStore } from '../context/userContext';
@ -32,18 +32,18 @@ function SignIn(props: { navigation: any; }) {
const handleUserConnect = useCallback(async (pseudo: string, password: string) => {
const us =await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => {
await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => {
if (res!=null){
MANAGER_USER.setCurrentUser(res);
navigation.navigate('HomeTab');
setUser(MANAGER_USER.getCurrentUser());
navigation.navigate('HomeTab');
}
else{
console.log("wesh c'est null");
}
});
});
}, []);
}, []);
return (

@ -8,6 +8,7 @@ import { FlatList } from 'react-native-gesture-handler';
import { SkinComponent } from '../components/Skin';
import tabSkinApp from '../constSkin';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { MANAGER_USER } from '../../App';
@ -22,11 +23,11 @@ function SkinList(props: { navigation: any; }) {
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Mes Skins'/>
<FlatList
data={tabSkinApp}
data={MANAGER_USER.getCurrentUser()?.getTabSkin()}
numColumns={2}
columnWrapperStyle={{ flex: 1, justifyContent: "space-around"}}
keyExtractor={item =>item.getSkinName()}
renderItem={({item}) => <SkinComponent skin={item} state='liste'/>} />
renderItem={({item}) => <SkinComponent skin={item} state='liste' nav={navigation}/>} />
</View>
<BotBar
nav={navigation}

@ -1,18 +1,24 @@
import { StatusBar } from 'expo-status-bar'
import { View } from 'react-native'
import React from 'react';
import React, { useCallback } from 'react';
import stylesScreen from './style/screens.style';
import { TopBar } from '../components/TopBar';
import { BotBar } from '../components/BotBar';
import { FlatList } from 'react-native-gesture-handler';
import { SkinComponent } from '../components/Skin';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { useSelector } from 'react-redux';
import { RootState } from '../redux/store';
import tabSkinApp from '../constSkin';
import { MANAGER_USER } from '../../App';
import { useUserStore } from '../context/userContext';
import { useStoreStore } from '../context/storeContext';
function Store(props: { navigation: any; }) {
const { navigation } = props
function Store(props: { navigation: any; }) {
const { navigation } = props
return (
<View style={stylesScreen.container}>
<TopBar
@ -21,11 +27,11 @@ function Store(props: { navigation: any; }) {
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Store'/>
<FlatList
data={MANAGER_USER.getCurrentUser().getTabSkin()}
data={useStoreStore().tabSkin}
numColumns={2}
columnWrapperStyle={{ flex: 1, justifyContent: "space-around"}}
keyExtractor={item =>item.getSkinName()}
renderItem={({item}) => <SkinComponent skin={item} state='shop'/>} />
renderItem={({item}) => <SkinComponent skin={item} state='shop' nav={navigation}/>} />
</View>
<BotBar
nav={navigation}

@ -0,0 +1,14 @@
import { Conversation } from "../../core/conversation";
import ISaverConversation from "./ISaverConversation";
export class FakeSaverConversation implements ISaverConversation{
async saveConversation(c: Conversation): Promise<void> {
return;
}
async deleteConversation(c: Conversation): Promise<void> {
return;
}
async updateConversation(c: Conversation): Promise<void> {
return;
}
}

@ -0,0 +1,39 @@
import { Conversation } from "../../core/conversation";
import { Message } from "../../core/message";
import { Skin } from "../../core/skin";
import { User } from "../../core/User/user";
import ILoaderConversation from "./ILoaderConversation";
export class LoaderConversationApi implements ILoaderConversation{
private axios = require('axios').default;
loadAllConversation(): Promise<Conversation[]> {
throw new Error("Method not implemented.");
}
loadByID(id: string): Promise<Conversation | null> {
throw new Error("Method not implemented.");
}
async loadByUser(u: User): Promise<Conversation[]> {
let tabConv:Conversation[]=[];
await this.axios({
method: 'get',
url: 'https://jsonplaceholder.typicode.com/todos/1',
params: {
name: "getConversationByUser",
//Les params genre nom de la fonction en php
}
})
.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);
tabConv=[new Conversation(1,
[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;
}
}

@ -0,0 +1,34 @@
import { Conversation } from "../../core/conversation";
import { User } from "../../core/User/user";
import ILoaderConversation from "./ILoaderConversation";
import ISaverConversation from "./ISaverConversation";
export default class ManagerConversation{
private currentTabConv:Conversation[]=[];
private loaderConversation: ILoaderConversation;
private saverConversation: ISaverConversation;
constructor(loaderConversation:ILoaderConversation, saverConversation:ISaverConversation){
this.loaderConversation=loaderConversation;
this.saverConversation=saverConversation;
}
getCurrentTabConv(){
return this.currentTabConv;
}
setCurrentTabConv(c:Conversation[]){
this.currentTabConv=c;
}
getLoaderConversation(){
return this.loaderConversation;
}
getsaverConversation(){
return this.saverConversation;
}
}

@ -1,4 +1,4 @@
import { Match } from "../../core/match";
import { Match } from "../../core/Match/match";
export default interface ILoaderMatch{

@ -1,4 +1,6 @@
import { Match } from "../../core/match";
import { Game } from "../../core/game";
import { Match } from "../../core/Match/match";
import { User } from "../../core/User/user";
export default interface ISaverMatch{
@ -7,7 +9,7 @@ export default interface ISaverMatch{
* m the Match we want to save
*/
saveMatch(m:Match): Promise<void>;
saveMatch(u:User, g:Game): Promise<Match>;
/**
* deleteMatch methode that delete a Match in the data management system

@ -0,0 +1,13 @@
import { Match } from "../../core/Match/match";
import ILoaderMatch from "./ILoaderMatch";
export default class LoaderMatchApi implements ILoaderMatch{
async loadAllMatch(): Promise<Match[]> {
throw new Error("Method not implemented.");
}
async loadByID(id: string): Promise<Match | null> {
throw new Error("Method not implemented.");
}
}

@ -0,0 +1,41 @@
import { Match } from "../../core/Match/Match";
import ILoaderMatch from "./ILoaderMatch";
import ISaverMatch from "./ISaverMatch";
export default class ManagerMatch{
private currentMatch: Match | null=null;
private loaderMatch: ILoaderMatch;
private saverMatch: ISaverMatch;
constructor(loader:ILoaderMatch, saver:ISaverMatch){
this.loaderMatch=loader;
this.saverMatch=saver;
}
getCurrentMatch(){
return this.currentMatch;
}
setCurrentMatch(u:Match | null){
this.currentMatch=u;
}
getLoaderMatch(){
return this.loaderMatch;
}
setLoaderMatch(l:ILoaderMatch){
this.loaderMatch=l;
}
getsaverMatch(){
return this.saverMatch;
}
setsaverMatch(s:ISaverMatch){
this.saverMatch=s;
}
}

@ -0,0 +1,32 @@
import { Game } from "../../core/game";
import { Match } from "../../core/Match/match";
import { User } from "../../core/User/user";
import ISaverMatch from "./ISaverMatch";
import { GameSolo } from "../../core/gameSolo";
import { GameMulti } from "../../core/gameMulti";
import MatchSolo from "../../core/Match/matchSolo";
import MatchMulti from "../../core/Match/matchMulti";
import MatchCasino from "../../core/Match/matchCasino";
export default class SaverMatchApi implements ISaverMatch{
async saveMatch(u:User, g:Game): Promise<Match> {
//match = mettre dans bdd
if (g instanceof GameSolo){
return new MatchSolo(12, false, [u], g);
}
else if(g instanceof GameMulti){
return new MatchMulti(12, false, [u], g);
}
return new MatchCasino(12, false, [u], g);
}
async deleteMatch(m: Match): Promise<void> {
throw new Error("Method not implemented.");
}
async updateMatch(m: Match): Promise<void> {
throw new Error("Method not implemented.");
}
}

@ -1,5 +1,5 @@
import { Conversation } from "../../core/conversation";
import { Match } from "../../core/match";
import { Match } from "../../core/Match/match";
import { User } from "../../core/User/user";
export default interface ILoaderUser{
@ -15,7 +15,7 @@ export default interface ILoaderUser{
* id the id we want to search
* return a User if found, if not null
*/
loadByID(id:string): Promise<User | null>;
loadByID(id:number): Promise<User | null>;
/**
* loadByUsername methode that load a user from the data management system by his username
@ -48,5 +48,5 @@ export default interface ILoaderUser{
* loadLastId methode that load the last id used to create a user
* return a String
*/
loadLastId(): Promise<string>;
loadLastId(): Promise<number>;
}

@ -7,7 +7,7 @@ export default interface ISaverUser{
* u the user we want to save
*/
saveUser(u:User | null): Promise<void>;
saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise<User | null>;
/**
* deleteUser methode that delete a User in the data management system

@ -4,8 +4,8 @@ import ISaverUser from "./ISaverUser";
export default class FakeSaverUser implements ISaverUser{
async saveUser(u: User): Promise<void> {
return;
async saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise<User | null> {
return null;
}
async deleteUser(u: User): Promise<void> {
return;

@ -1,6 +1,6 @@
import tabSkinApp from "../../constSkin";
import { Conversation } from "../../core/conversation";
import { Match } from "../../core/match";
import { Match } from "../../core/Match/match";
import { Skin } from "../../core/skin";
import { User } from "../../core/User/user";
import ILoaderUser from "./ILoaderUser";
@ -37,14 +37,14 @@ export default class LoaderUserApi implements ILoaderUser{
.then(function (response: any) {
if (response.data != null && response.data != undefined){
Object.assign(test, response.data);
us.push(new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp));
us.push(new User(1, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp));
}
});
return us;
}
async loadByID(id: string): Promise<User | null> {
async loadByID(id: number): Promise<User | null> {
let test = new Test(true, 0, "wesh", 0);
try{
await this.axios({
@ -64,7 +64,7 @@ export default class LoaderUserApi implements ILoaderUser{
}catch (error) {
console.error(error);
}
return new User("17", "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp);
return new User(1, "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp);
}
@ -102,7 +102,9 @@ export default class LoaderUserApi implements ILoaderUser{
}
})
.then(function (response: any) {
user=new User("U0001", username, password, "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]);
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);
});
return user;
}
@ -117,7 +119,7 @@ export default class LoaderUserApi implements ILoaderUser{
}
async loadLastId(): Promise<string> {
async loadLastId(): Promise<number> {
let test = new Test(true, 0, "wesh", 0);
try {
const response = await this.axios.get('https://jsonplaceholder.typicode.com/todos/1');
@ -125,7 +127,7 @@ export default class LoaderUserApi implements ILoaderUser{
} catch (error) {
console.error(error);
}
return "U0001";
return 1;
}

@ -6,7 +6,8 @@ export default class SaverUserApi implements ISaverUser{
private axios = require('axios').default;
async saveUser(u: User): Promise<void> {
async saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise<User | null> {
let us:User|null=null;
this.axios({
method: 'post',
url: '/user/12345',
@ -14,8 +15,14 @@ export default class SaverUserApi implements ISaverUser{
firstName: 'Fred',
lastName: 'Flintstone'
}
});
}).then(function (response: any) {
if (response.data != null && response.data != undefined){
let test:any;
Object.assign(test, response.data);
us=test;
}
});
return us;
}
async deleteUser(u: User): Promise<void> {
throw new Error("Method not implemented.");

@ -1,24 +1,23 @@
import { Conversation } from "../../core/conversation";
import { Match } from "../../core/match";
import { Match } from "../../core/Match/match";
import { Skin } from "../../core/skin";
import { User } from "../../core/User/user";
import ILoaderUser from "./ILoaderUser";
export default class StubUser implements ILoaderUser{
public img = "";
public skin = new Skin("S0001", "Bob",this.img, 0);
private tabUS:User[]=[
new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]),
new User("48", "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",this.img, 0), [this.skin]),
new User("17", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",this.img, 0), [this.skin]),
new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",this.img, 0), [this.skin]),
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]),
];
async loadAllUser(): Promise<User[]> {
return this.tabUS;
}
async loadByID(id: string): Promise<User | null> {
async loadByID(id: number): Promise<User | null> {
for(let u of this.tabUS){
if (u.getId()==id){
return u;
@ -59,7 +58,7 @@ export default class StubUser implements ILoaderUser{
return tabUser;
}
async loadLastId(): Promise<string> {
async loadLastId(): Promise<number> {
throw new Error("Method not implemented.");
}

Loading…
Cancel
Save