Started work on 5spot
This commit is contained in:
@@ -5,36 +5,74 @@ export const ACTIONS = {
|
||||
ADD_ROUND: 'add_round',
|
||||
RESET_GAME: 'reset_game',
|
||||
SAVE_GAME: 'save_game',
|
||||
LOAD_HISTORY: 'load_history'
|
||||
LOAD_HISTORY: 'load_history',
|
||||
SET_TARGET_FACE: 'set_target_face'
|
||||
};
|
||||
|
||||
// Define the available score values for each game type and target face
|
||||
export const TARGET_FACES = {
|
||||
'300': {
|
||||
'standard': [0, 1, 2, 3, 4, 5, 'x'], // Standard scoring for 300 game
|
||||
'5-spot': [0, 4, 5, 'x'] // 5-spot target face for 300 game
|
||||
},
|
||||
'450': {
|
||||
'standard': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'x'], // Standard scoring for 450 game
|
||||
'3-spot': [0, 6, 7, 8, 9, 10, 'x'] // 3-spot target face for 450 game
|
||||
}
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
currentGame: {
|
||||
gameType: '',
|
||||
isLeague: false,
|
||||
targetFace: 'standard', // Default to standard target face
|
||||
rounds: [],
|
||||
totalScore: 0,
|
||||
totalBullseyes: 0,
|
||||
date: null
|
||||
date: null,
|
||||
availableScores: [] // Will be populated based on gameType and targetFace
|
||||
},
|
||||
history: []
|
||||
};
|
||||
|
||||
// Helper function to get available scores based on game type and target face
|
||||
const getAvailableScores = (gameType, targetFace) => {
|
||||
if (!gameType || !targetFace) return [];
|
||||
return TARGET_FACES[gameType]?.[targetFace] || [];
|
||||
};
|
||||
|
||||
const scoreReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case ACTIONS.START_NEW_ROUND:
|
||||
case ACTIONS.START_GAME: // Changed from START_NEW_ROUND to match the exported ACTIONS
|
||||
const gameType = action.payload.gameType;
|
||||
const targetFace = action.payload.targetFace || 'standard';
|
||||
|
||||
return {
|
||||
...state,
|
||||
currentGame: {
|
||||
gameType: action.payload.gameType,
|
||||
gameType,
|
||||
isLeague: action.payload.isLeague,
|
||||
targetFace,
|
||||
rounds: [],
|
||||
totalScore: 0,
|
||||
totalBullseyes: 0,
|
||||
dateStarted: new Date().toISOString(),
|
||||
availableScores: getAvailableScores(gameType, targetFace)
|
||||
},
|
||||
};
|
||||
|
||||
case ACTIONS.SET_TARGET_FACE:
|
||||
const newTargetFace = action.payload.targetFace;
|
||||
|
||||
return {
|
||||
...state,
|
||||
currentGame: {
|
||||
...state.currentGame,
|
||||
targetFace: newTargetFace,
|
||||
availableScores: getAvailableScores(state.currentGame.gameType, newTargetFace)
|
||||
}
|
||||
};
|
||||
|
||||
case ACTIONS.ADD_ROUND:
|
||||
const updatedRounds = [...state.currentGame.rounds];
|
||||
updatedRounds[action.payload.roundIndex] = {
|
||||
|
||||
Reference in New Issue
Block a user