From ef8c218b2a7492731549e09e2eb516e57f8797d7 Mon Sep 17 00:00:00 2001 From: "corey@blaishome.online" Date: Wed, 19 Mar 2025 22:18:11 -0400 Subject: [PATCH] fixed all buttons for all game modes --- asc/src/components/ScoreTracker.js | 157 ++++++++++---- asc/src/components/ScoreTracker.old | 324 ++++++++++++++++++++++++++++ 2 files changed, 443 insertions(+), 38 deletions(-) create mode 100644 asc/src/components/ScoreTracker.old diff --git a/asc/src/components/ScoreTracker.js b/asc/src/components/ScoreTracker.js index c153744..4e27d7b 100644 --- a/asc/src/components/ScoreTracker.js +++ b/asc/src/components/ScoreTracker.js @@ -54,38 +54,83 @@ const ScoreTracker = () => { // Calculate total for current end const calculateEndTotal = (arrows) => { return arrows.reduce((total, arrow) => { - if (arrow.toUpperCase() === 'X') { - return total + 10; - } else if (arrow.toUpperCase() === 'M') { - return total; - } else { - return total + parseInt(arrow); - } - }, 0); -}; + if (arrow.toUpperCase() === 'X') { + return total + 10; + } else if (arrow.toUpperCase() === 'M') { + return total; + } else { + return total + parseInt(arrow); + } + }, 0); + }; // Get button color based on score const getButtonColor = (score) => { - switch(score) { - case 'X': - return { bgcolor: '#FF9800', color: 'white' }; // Orange - case '10': - return { bgcolor: '#9C27B0', color: 'white' }; // Purple - case '9': - case '8': - return { bgcolor: '#2196F3', color: 'white' }; // Blue - case '7': - case '6': - case '5': - case '4': - case '3': - case '2': - case '1': - return { bgcolor: '#4CAF50', color: 'white' }; // Green - case 'M': - return { bgcolor: '#9E9E9E', color: 'white' }; // Gray - default: - return { bgcolor: 'default' }; + // For 450 game with single spot, use a specific color scheme + if (state.currentGame.gameType === '450' && state.currentGame.targetFace !== '3-spot') { + switch(score) { + case 'X': + return { bgcolor: '#FF9800', color: 'white' }; // Orange + case '10': + return { bgcolor: '#9C27B0', color: 'white' }; // Purple + case '9': + case '8': + return { bgcolor: '#2196F3', color: 'white' }; // Blue + case '7': + case '6': + case '5': + case '4': + case '3': + return { bgcolor: '#4CAF50', color: 'white' }; // Green + case '2': + case '1': + case 'M': + return { bgcolor: '#9E9E9E', color: 'white' }; // Gray + default: + return { bgcolor: 'default' }; + } + } + // For 450 game with 3-spot + else if (state.currentGame.gameType === '450' && state.currentGame.targetFace === '3-spot') { + switch(score) { + case 'X': + return { bgcolor: '#FF9800', color: 'white' }; // Orange + case '10': + return { bgcolor: '#9C27B0', color: 'white' }; // Purple + case '9': + case '8': + return { bgcolor: '#2196F3', color: 'white' }; // Blue + case 'M': + return { bgcolor: '#9E9E9E', color: 'white' }; // Gray + default: + return { bgcolor: 'default' }; + } + } + // Original color scheme for other game types (300 games) + else { + switch(score) { + case 'X': + return { bgcolor: '#FF9800', color: 'white' }; // Orange + case '5': + return { bgcolor: '#9C27B0', color: 'white' }; // Purple + case '4': + return { bgcolor: '#2196F3', color: 'white' }; // Blue + case '10': + return { bgcolor: '#9C27B0', color: 'white' }; // Purple + case '9': + case '8': + return { bgcolor: '#2196F3', color: 'white' }; // Blue + case '7': + case '6': + case '3': + case '2': + case '1': + return { bgcolor: '#4CAF50', color: 'white' }; // Green + case 'M': + return { bgcolor: '#9E9E9E', color: 'white' }; // Gray + default: + return { bgcolor: 'default' }; + } } }; @@ -132,10 +177,26 @@ const ScoreTracker = () => { } // Get the number of arrows per end based on game type - const arrowsPerEnd = state.currentGame.gameType === '450' ? 6 : 5; + const arrowsPerEnd = state.currentGame.gameType === '450' ? 3 : 5; - // Score button values - const scoreButtons = ['X', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'M']; + // Score button values based on game type and target face + const getScoreButtons = () => { + if (state.currentGame.gameType === '300' && state.currentGame.targetFace === '5-spot') { + return ['X', '5', '4', 'M']; + } else if (state.currentGame.gameType === '300' && state.currentGame.targetFace !== '5-spot') { + // For 300 game with single spot, exclude 10-6 + return ['X', '5', '4', '3', '2', '1', 'M']; + } else if (state.currentGame.gameType === '450' && state.currentGame.targetFace === '3-spot') { + // For 450 game with 3-spot, only X, 10-8, and M + return ['X', '10', '9', '8', 'M']; + } else { + // For other combinations, keep the full range + return ['X', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'M']; + } + }; + + // Use the function to get the appropriate buttons + const scoreButtons = getScoreButtons(); return ( @@ -208,13 +269,33 @@ const ScoreTracker = () => { {/* Current end display */} {currentEnd.map((arrow, index) => { + // Updated color mapping to match button colors let bgColor; - if (arrow.toUpperCase() === 'X') bgColor = '#FF9800'; // Orange - else if (arrow.toUpperCase() === '10') bgColor = '#9C27B0'; // Purple - else if (['9', '8'].includes(arrow)) bgColor = '#2196F3'; // Blue - else if (['7', '6', '5', '4', '3', '2', '1'].includes(arrow)) bgColor = '#4CAF50'; // Green - else if (arrow.toUpperCase() === 'M') bgColor = '#9E9E9E'; // Gray - else bgColor = 'default'; + + if (state.currentGame.gameType === '450' && state.currentGame.targetFace !== '3-spot') { + // For 450 games with single spot + if (arrow.toUpperCase() === 'X') bgColor = '#FF9800'; // Orange + else if (arrow === '10') bgColor = '#9C27B0'; // Purple + else if (['9', '8'].includes(arrow)) bgColor = '#2196F3'; // Blue + else if (['7', '6', '5', '4', '3'].includes(arrow)) bgColor = '#4CAF50'; // Green + else if (['2', '1', 'M'].includes(arrow) || arrow.toUpperCase() === 'M') bgColor = '#9E9E9E'; // Gray + else bgColor = 'default'; + } else if (state.currentGame.gameType === '450' && state.currentGame.targetFace === '3-spot') { + // For 450 games with 3-spot + if (arrow.toUpperCase() === 'X') bgColor = '#FF9800'; // Orange + else if (arrow === '10') bgColor = '#9C27B0'; // Purple + else if (['9', '8'].includes(arrow)) bgColor = '#2196F3'; // Blue + else if (arrow.toUpperCase() === 'M') bgColor = '#9E9E9E'; // Gray + else bgColor = 'default'; + } else { + // For other games (300 rounds) + if (arrow.toUpperCase() === 'X') bgColor = '#FF9800'; // Orange + else if (arrow === '5' || arrow === '10') bgColor = '#9C27B0'; // Purple + else if (arrow === '4' || ['9', '8'].includes(arrow)) bgColor = '#2196F3'; // Blue + else if (['7', '6', '3', '2', '1'].includes(arrow)) bgColor = '#4CAF50'; // Green + else if (arrow.toUpperCase() === 'M') bgColor = '#9E9E9E'; // Gray + else bgColor = 'default'; + } return ( { + const { state, dispatch } = useScore(); + const navigate = useNavigate(); + + // Local state for the current end + const [currentEnd, setCurrentEnd] = useState([]); + + // Check if we have an active game, if not redirect to setup + useEffect(() => { + if (!state.currentGame || !state.currentGame.gameType) { + navigate('/'); + } + }, [state.currentGame, navigate]); + + // Handle adding an arrow score + const handleAddArrow = (score) => { + // Add to current end + setCurrentEnd([...currentEnd, score]); + }; + + // Handle removing the last arrow + const handleRemoveArrow = () => { + if (currentEnd.length > 0) { + const newEnd = [...currentEnd]; + newEnd.pop(); + setCurrentEnd(newEnd); + } + }; + + // Calculate total for current end + const calculateEndTotal = (arrows) => { + return arrows.reduce((total, arrow) => { + if (arrow.toUpperCase() === 'X') { + return total + 10; + } else if (arrow.toUpperCase() === 'M') { + return total; + } else { + return total + parseInt(arrow); + } + }, 0); +}; + + // Get button color based on score + const getButtonColor = (score) => { + switch(score) { + case 'X': + return { bgcolor: '#FF9800', color: 'white' }; // Orange + case '10': + return { bgcolor: '#9C27B0', color: 'white' }; // Purple + case '9': + case '8': + return { bgcolor: '#2196F3', color: 'white' }; // Blue + case '7': + case '6': + case '5': + case '4': + case '3': + case '2': + case '1': + return { bgcolor: '#4CAF50', color: 'white' }; // Green + case 'M': + return { bgcolor: '#9E9E9E', color: 'white' }; // Gray + default: + return { bgcolor: 'default' }; + } + }; + + // Handle saving the current end + const handleSaveEnd = () => { + if (currentEnd.length > 0) { + // Create the end object + const endObject = { + arrows: [...currentEnd], + total: calculateEndTotal(currentEnd), + timestamp: new Date().toISOString() + }; + + // Dispatch to context + dispatch({ + type: ACTIONS.ADD_END, + payload: endObject + }); + + // Clear current end + setCurrentEnd([]); + } + }; + + // Handle ending the game + const handleEndGame = () => { + // Save final scores to history first + dispatch({ + type: ACTIONS.SAVE_GAME, + }); + + // Then end the current game + dispatch({ + type: ACTIONS.END_GAME, + }); + + // Navigate to setup page + navigate('/'); + }; + + // Early return if no game is active + if (!state.currentGame || !state.currentGame.gameType) { + return null; // Will be redirected by useEffect + } + + // Get the number of arrows per end based on game type + const arrowsPerEnd = state.currentGame.gameType === '450' ? 3 : 5; + + // Score button values + const scoreButtons = ['X', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'M']; + + return ( + + + + + + + Target Face: {state.currentGame.targetFace || 'Standard'} + + + {/* Current game stats */} + + + + Current Score: {state.currentGame.ends?.reduce((total, end) => total + end.total, 0) || 0} + + + Ends Completed: {state.currentGame.ends?.length || 0} + + + + + {/* Score input section */} + + + Score Current End + + + {/* Score buttons */} + + + {scoreButtons.map((score) => { + const colorStyle = getButtonColor(score); + return ( + + ); + })} + + + + + + + + {/* Current end display */} + + {currentEnd.map((arrow, index) => { + let bgColor; + if (arrow.toUpperCase() === 'X') bgColor = '#FF9800'; // Orange + else if (arrow.toUpperCase() === '10') bgColor = '#9C27B0'; // Purple + else if (['9', '8'].includes(arrow)) bgColor = '#2196F3'; // Blue + else if (['7', '6', '5', '4', '3', '2', '1'].includes(arrow)) bgColor = '#4CAF50'; // Green + else if (arrow.toUpperCase() === 'M') bgColor = '#9E9E9E'; // Gray + else bgColor = 'default'; + + return ( + + {arrow.toUpperCase()} + + ); + })} + {Array(arrowsPerEnd - currentEnd.length).fill(0).map((_, index) => ( + + - + + ))} + + + + + End Total: {calculateEndTotal(currentEnd)} + + + + + + + + {/* Previous ends display */} + {(state.currentGame.ends?.length > 0) && ( + + + Previous Ends + + + + + + End + Arrows + Total + Running Total + + + + {state.currentGame.ends.map((end, endIndex) => { + const runningTotal = state.currentGame.ends + .slice(0, endIndex + 1) + .reduce((total, e) => total + e.total, 0); + + return ( + + {endIndex + 1} + + {end.arrows.join(', ')} + + {end.total} + {runningTotal} + + ); + })} + +
+
+
+ )} + + +
+
+
+
+ ); +}; + +export default ScoreTracker;