Structure de données jeu client
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
import { AuthState } from "@/utils/features/location/authSlice"
 | 
			
		||||
import { AuthState } from "@/utils/features/auth/authSlice"
 | 
			
		||||
import { useMutation } from "@tanstack/react-query"
 | 
			
		||||
import { LocationObject } from "expo-location"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import { AuthPayload } from "@/utils/features/location/authSlice"
 | 
			
		||||
import { AuthPayload } from "@/utils/features/auth/authSlice"
 | 
			
		||||
import { useMutation } from "@tanstack/react-query"
 | 
			
		||||
 | 
			
		||||
type ErrorResponse = {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import { useAppDispatch, useAppSelector } from "./useStore"
 | 
			
		||||
import { AuthPayload, login, logout } from "@/utils/features/location/authSlice"
 | 
			
		||||
import { AuthPayload, login, logout } from "@/utils/features/auth/authSlice"
 | 
			
		||||
 | 
			
		||||
export const useAuth = () => useAppSelector((state) => state.auth)
 | 
			
		||||
export const useAuthLogin = () => {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								client/hooks/useChallengeActions.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								client/hooks/useChallengeActions.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
import { useAppSelector } from "./useStore"
 | 
			
		||||
 | 
			
		||||
export const useChallengeActions = () => useAppSelector((state) => state.challengeActions)
 | 
			
		||||
							
								
								
									
										3
									
								
								client/hooks/useChallenges.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								client/hooks/useChallenges.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
import { useAppSelector } from "./useStore"
 | 
			
		||||
 | 
			
		||||
export const useTrain = () => useAppSelector((state) => state.challenges)
 | 
			
		||||
							
								
								
									
										12
									
								
								client/hooks/useGame.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								client/hooks/useGame.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
import { useAppDispatch, useAppSelector } from "./useStore"
 | 
			
		||||
import { setPlayerId, updateMoney } from "@/utils/features/game/gameSlice"
 | 
			
		||||
 | 
			
		||||
export const useGame = () => useAppSelector((state) => state.game)
 | 
			
		||||
export const useSetPlayerId = () => {
 | 
			
		||||
  const dispath = useAppDispatch()
 | 
			
		||||
  return (playerId: number) => dispath(setPlayerId(playerId))
 | 
			
		||||
}
 | 
			
		||||
export const useUpdateMoney = () => {
 | 
			
		||||
    const dispatch = useAppDispatch()
 | 
			
		||||
    return (money: number) => dispatch(updateMoney(money))
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								client/hooks/useTrain.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								client/hooks/useTrain.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
import { useAppSelector } from "./useStore"
 | 
			
		||||
 | 
			
		||||
export const useTrain = () => useAppSelector((state) => state.train)
 | 
			
		||||
@@ -17,27 +17,3 @@ export function setItem(key: string, value: string): void {
 | 
			
		||||
export async function setItemAsync(key: string, value: string): Promise<void> {
 | 
			
		||||
  localStorage.setItem(key, value)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
import AsyncStorage from '@react-native-async-storage/async-storage'
 | 
			
		||||
 | 
			
		||||
export async function deleteItemAsync(key: string): Promise<void> {
 | 
			
		||||
  return AsyncStorage.removeItem(key)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getItem(key: string): string | null {
 | 
			
		||||
  return Promise.apply(AsyncStorage.getItem(key))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getItemAsync(key: string): Promise<string | null> {
 | 
			
		||||
  return AsyncStorage.getItem(key)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function setItem(key: string, value: string): void {
 | 
			
		||||
  AsyncStorage.setItem(key, value)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function setItemAsync(key: string, value: string): Promise<void> {
 | 
			
		||||
  return AsyncStorage.setItem(key, value)
 | 
			
		||||
}
 | 
			
		||||
 */
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
import { createSlice } from '@reduxjs/toolkit'
 | 
			
		||||
 | 
			
		||||
export interface ChallengeAction {
 | 
			
		||||
  id: number
 | 
			
		||||
  challengeId: number
 | 
			
		||||
  title: string,
 | 
			
		||||
  description: string,
 | 
			
		||||
  reward: number,
 | 
			
		||||
  success: boolean,
 | 
			
		||||
  start: Date,
 | 
			
		||||
  end: Date | null,
 | 
			
		||||
  penaltyStart: Date | null,
 | 
			
		||||
  penaltyEnd: Date | null,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ActionsState {
 | 
			
		||||
  challengeActions: ChallengeAction[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState: ActionsState = {
 | 
			
		||||
  challengeActions: []
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const challengeActionsSlice = createSlice({
 | 
			
		||||
  name: 'challengeActions',
 | 
			
		||||
  initialState: initialState,
 | 
			
		||||
  reducers: {
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export const { } = challengeActionsSlice.actions
 | 
			
		||||
 | 
			
		||||
export default challengeActionsSlice.reducer
 | 
			
		||||
							
								
								
									
										27
									
								
								client/utils/features/challenges/challengesSlice.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								client/utils/features/challenges/challengesSlice.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
import { createSlice } from '@reduxjs/toolkit'
 | 
			
		||||
 | 
			
		||||
export interface Challenge {
 | 
			
		||||
  id: number
 | 
			
		||||
  title: string,
 | 
			
		||||
  description: string,
 | 
			
		||||
  reward: number,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ChallengesState {
 | 
			
		||||
  challenges: Challenge[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState: ChallengesState = {
 | 
			
		||||
  challenges: []
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const challengesSlice = createSlice({
 | 
			
		||||
  name: 'challenges',
 | 
			
		||||
  initialState: initialState,
 | 
			
		||||
  reducers: {
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export const { } = challengesSlice.actions
 | 
			
		||||
 | 
			
		||||
export default challengesSlice.reducer
 | 
			
		||||
							
								
								
									
										38
									
								
								client/utils/features/game/gameSlice.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								client/utils/features/game/gameSlice.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
 | 
			
		||||
 | 
			
		||||
export interface GameState {
 | 
			
		||||
  playerId: number | null
 | 
			
		||||
  gameStarted: boolean
 | 
			
		||||
  money: number
 | 
			
		||||
  currentRunner: boolean
 | 
			
		||||
  chaseFreeTime: Date | null
 | 
			
		||||
  penaltyStart: Date | null
 | 
			
		||||
  penaltyEnd: Date | null
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState: GameState = {
 | 
			
		||||
  playerId: null,
 | 
			
		||||
  gameStarted: false,
 | 
			
		||||
  money: 0,
 | 
			
		||||
  currentRunner: false,
 | 
			
		||||
  chaseFreeTime: null,
 | 
			
		||||
  penaltyStart: null,
 | 
			
		||||
  penaltyEnd: null,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const gameSlice = createSlice({
 | 
			
		||||
  name: 'game',
 | 
			
		||||
  initialState: initialState,
 | 
			
		||||
  reducers: {
 | 
			
		||||
    setPlayerId: (state, action: PayloadAction<number>) => {
 | 
			
		||||
      state.playerId = action.payload
 | 
			
		||||
    },
 | 
			
		||||
    updateMoney: (state, action: PayloadAction<number>) => {
 | 
			
		||||
      state.money = action.payload
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export const { setPlayerId, updateMoney } = gameSlice.actions
 | 
			
		||||
 | 
			
		||||
export default gameSlice.reducer
 | 
			
		||||
							
								
								
									
										107
									
								
								client/utils/features/train/trainSlice.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								client/utils/features/train/trainSlice.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,107 @@
 | 
			
		||||
import { createSlice } from '@reduxjs/toolkit'
 | 
			
		||||
 | 
			
		||||
export interface InterrailLeg {
 | 
			
		||||
  infoJson?: string
 | 
			
		||||
  info?: InterrailLegInfo
 | 
			
		||||
  sortOrder: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailTravel {
 | 
			
		||||
  date: string
 | 
			
		||||
  infoJson?: string
 | 
			
		||||
  info?: InterrailTravelInfo
 | 
			
		||||
  from: string
 | 
			
		||||
  to: string
 | 
			
		||||
  type: number
 | 
			
		||||
  legs: InterrailLeg[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailJourneyData {
 | 
			
		||||
  travels: InterrailTravel[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailJourney {
 | 
			
		||||
  data: InterrailJourneyData
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailTime {
 | 
			
		||||
  hours: number
 | 
			
		||||
  minutes: number
 | 
			
		||||
  offset: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailDate {
 | 
			
		||||
  day: number
 | 
			
		||||
  month: number
 | 
			
		||||
  year: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailTravelInfo {
 | 
			
		||||
  arrivalTime: InterrailTime
 | 
			
		||||
  date: InterrailDate
 | 
			
		||||
  departureTime: InterrailTime
 | 
			
		||||
  haconVersion: number
 | 
			
		||||
  dataSource: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailStopExtraInfo {
 | 
			
		||||
  departureTime: InterrailTime
 | 
			
		||||
  index: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailStopCoordinates {
 | 
			
		||||
  latitude: number
 | 
			
		||||
  longitude: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailStopStation {
 | 
			
		||||
  coordinates: InterrailStopCoordinates
 | 
			
		||||
  country: string
 | 
			
		||||
  name: string
 | 
			
		||||
  stationId: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface InterrailLegInfo {
 | 
			
		||||
  attributeCodes: string[]
 | 
			
		||||
  attributes: object
 | 
			
		||||
  duration: InterrailTime
 | 
			
		||||
  directionStation: string
 | 
			
		||||
  endTime: InterrailTime
 | 
			
		||||
  isSeparateTicket: boolean
 | 
			
		||||
  operationDays: string
 | 
			
		||||
  operator: object
 | 
			
		||||
  dataSource: number
 | 
			
		||||
  startTime: InterrailTime
 | 
			
		||||
  stopExtraInfo: InterrailStopExtraInfo[]
 | 
			
		||||
  trainName: string
 | 
			
		||||
  trainStopStations: InterrailStopStation[]
 | 
			
		||||
  trainType: number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface TrainTrip {
 | 
			
		||||
  id: string
 | 
			
		||||
  distance: number,
 | 
			
		||||
  from: string,
 | 
			
		||||
  to: string,
 | 
			
		||||
  departureTime: Date,
 | 
			
		||||
  arrivalTime: Date,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface TrainsState {
 | 
			
		||||
  trains: TrainTrip[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState: TrainsState = {
 | 
			
		||||
  trains: []
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const trainSlice = createSlice({
 | 
			
		||||
  name: 'train',
 | 
			
		||||
  initialState: initialState,
 | 
			
		||||
  reducers: {
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export const { } = trainSlice.actions
 | 
			
		||||
 | 
			
		||||
export default trainSlice.reducer
 | 
			
		||||
@@ -1,11 +1,19 @@
 | 
			
		||||
import { configureStore } from '@reduxjs/toolkit'
 | 
			
		||||
import authReducer from './features/location/authSlice'
 | 
			
		||||
import authReducer from './features/auth/authSlice'
 | 
			
		||||
import challengesReducer from './features/challenges/challengesSlice'
 | 
			
		||||
import challengeActionsReducer from './features/challengeActions/challengeActionsSlice'
 | 
			
		||||
import gameReducer from './features/game/gameSlice'
 | 
			
		||||
import locationReducer from './features/location/locationSlice'
 | 
			
		||||
import trainReducer from './features/train/trainSlice'
 | 
			
		||||
 | 
			
		||||
const store = configureStore({
 | 
			
		||||
  reducer: {
 | 
			
		||||
    auth: authReducer,
 | 
			
		||||
    challenges: challengesReducer,
 | 
			
		||||
    challengeActions: challengeActionsReducer,
 | 
			
		||||
    game: gameReducer,
 | 
			
		||||
    location: locationReducer,
 | 
			
		||||
    train: trainReducer,
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user