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 2 years ago
commit ada683e922

@ -12,11 +12,14 @@ import { FakeSaverConversation } from './src/services/conversationService/fakeSa
import ManagerMatch from './src/services/matchServices/managerMatch'
import LoaderMatchApi from './src/services/matchServices/loaderMatchApi'
import SaverMatchApi from './src/services/matchServices/saverMatchApi'
import LoaderGameApi from './src/services/gameService/loaderGameApi'
import ManagerGame from './src/services/gameService/managerGame'
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 const MANAGER_GAME = new ManagerGame(new LoaderGameApi);
export default function App() {

@ -21,7 +21,7 @@ let points=0;
function CookieClicker(props: { navigation: any}){
const { navigation } = props
const GAMING_TIME=30;
const GAMING_TIME=45;
const setUser = useUserStore((state) => state.setUser);

@ -59,7 +59,7 @@ FC<{nav: any, state?: String}> =
}
}, []);
const handleConversationChange = useCallback(async () => {
const handleConversationChange = useCallback(async () => {
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=undefined){
await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => {

@ -0,0 +1,23 @@
import React from "react";
import create from "zustand";
import { MANAGER_USER } from "../../App";
import tabSkinApp from "../constSkin";
import { Game } from "../core/game";
import { Skin } from "../core/Skin";
import { User } from "../core/User/user";
// Define store types
interface GameState {
tabGame: Game[] | undefined;
setTabGame: (tabGame: Game[]) => void;
resetTabGame: () => void;
}
// Define store data and methods
export const useGameStore = create<GameState>()((set, get) => ({
tabGame: undefined,
setTabGame: (tabGame) => set((state) => ({ tabGame: tabGame })),
resetTabGame: () => set((state) => ({ tabGame: undefined })),
}));

@ -1,5 +1,5 @@
import { StatusBar } from 'expo-status-bar'
import { StyleSheet, View, Text, Alert, Pressable, Image} from 'react-native'
import { StyleSheet, View, Text, Alert, Pressable, Image, FlatList} from 'react-native'
import React from 'react';
import { Game } from '../core/game';
import { Skin } from '../core/skin';
@ -10,33 +10,34 @@ import { User } from '../core/User/user';
import tabSkinApp from '../constSkin';
import { Conversation } from '../core/conversation';
import { GameSolo } from '../core/gameSolo';
import { ScreenIndicator } from '../components/ScreenIndicator';
import stylesScreen from './style/screens.style'
import { MANAGER_GAME } from '../../App';
import { useGameStore } from '../context/gameContext';
let tabConv:Conversation[]=[];
const map = new Map();
map.set(0,0);
map.set(15,10);
map.set(20,15);
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);
function GameChoice(props: { navigation: any; }) {
const { navigation } = props
function GameChoice(props: { navigation: any}) {
const { navigation} = props
console.log(MANAGER_GAME.getTabGame());
return (
<View style={styles.container}>
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
/>
<View style={styles.body}>
<GameComponent
game={cookieClicker}
nav={navigation}
/>
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Game Choice'/>
<FlatList
data={MANAGER_GAME.getTabGame()}
numColumns={2}
columnWrapperStyle={{ flex: 1, justifyContent: "space-around"}}
keyExtractor={item =>item.getName()}
renderItem={({item}) => <GameComponent game={item} nav={navigation}/>} />
</View>
<BotBar
nav={navigation}
state='Home'
state='Store'
/>
</View>
);

@ -1,11 +1,13 @@
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 { Conversation } from '../core/conversation';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { MANAGER_GAME } from '../../App';
import { useGameStore } from '../context/gameContext';
@ -15,6 +17,21 @@ function Home(props: { navigation: any; }) {
const { navigation } = props
const setTabGame = useGameStore((state) => state.setTabGame);
const handleGame = useCallback(async () => {
let tmp=MANAGER_GAME.getTabGame();
if (tmp==null){
await MANAGER_GAME.getLoaderGame().loadAllGame().then((res) => {
MANAGER_GAME.setTabGame(res);
setTabGame(res);
navigation.navigate('GameChoiceTab')
});
}
else{
navigation.navigate('GameChoiceTab')
}
}, []);
return (
<View style={stylesScreen.container}>
@ -25,11 +42,11 @@ function Home(props: { navigation: any; }) {
<View style={stylesScreen.bodyCenter}>
<ButtonGameTypeChoice
title='Jouer Seul'
onPress={() => navigation.navigate('GameChoiceTab')}
onPress={() => {handleGame()}}
/>
<ButtonGameTypeChoice
title='Défier mes amis'
onPress={() => navigation.navigate('GameChoiceTab')}
onPress={() => handleGame()}
/>
</View>
<BotBar

@ -0,0 +1,17 @@
import { Game } from "../../core/game";
export default interface ILoaderGame{
/**
* loadAllGame methode that load every Game from the data management system
* return an array of Game
*/
loadAllGame(): Promise<Game[]>;
/**
* loadByID methode that load a match from the data management system by its id
* id the id we want to search
* return a Game if found, if not null
*/
loadByID(id:string): Promise<Game | null>;
}

@ -0,0 +1,38 @@
import { Game } from "../../core/game";
import { GameSolo } from "../../core/gameSolo";
import ILoaderGame from "./ILoaderGame";
export default class LoaderGameApi implements ILoaderGame{
private axios = require('axios').default;
async loadAllGame(): Promise<Game[]> {
let tab: Game[]=[];
await this.axios({
method: 'get',
url: 'https://jsonplaceholder.typicode.com/todos/1',
params: {
name: "getAllUser",
//Les params genre nom de la fonction en php
}
})
.then(function (response: any) {
const map = new Map();
map.set(0,0);
map.set(100,50);
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);
const test= new GameSolo(1, "Test", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pendu.jpg", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, map);
tab=[cookieClicker, test];
console.log(tab);
});
return tab;
}
async loadByID(id: string): Promise<Game | null> {
throw new Error("Method not implemented.");
}
}

@ -0,0 +1,30 @@
import { Game } from "../../core/game";
import ILoaderGame from "./ILoaderGame";
export default class ManagerGame{
private tabGame: Game[] | null=null;
private loaderGame: ILoaderGame;
constructor(loader:ILoaderGame){
this.loaderGame=loader;
}
getTabGame(){
return this.tabGame;
}
setTabGame(g:Game[] | null){
this.tabGame=g;
}
getLoaderGame(){
return this.loaderGame;
}
setLoaderGame(l:ILoaderGame){
this.loaderGame=l;
}
}
Loading…
Cancel
Save