working on unified API and major refactoring
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './useGameStatus';
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useState } from 'react';
|
||||
import type { GameStatus } from '../types';
|
||||
|
||||
export function useGameStatus() {
|
||||
const [gameStatus, setGameStatus] = useState<GameStatus>('waiting');
|
||||
|
||||
function startGame() {
|
||||
setGameStatus('started');
|
||||
}
|
||||
|
||||
function togglePause(pause?: boolean) {
|
||||
if (typeof pause === 'boolean') {
|
||||
setGameStatus(pause ? 'paused' : 'started');
|
||||
return;
|
||||
}
|
||||
setGameStatus(prevStatus => prevStatus === 'paused' ? 'started' : 'paused');
|
||||
}
|
||||
|
||||
function quitGame() {
|
||||
setGameStatus('waiting');
|
||||
}
|
||||
|
||||
return {
|
||||
gameStatus,
|
||||
setGameStatus,
|
||||
startGame,
|
||||
togglePause,
|
||||
quitGame,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user