2020-01-09 10:06:38 +01:00
|
|
|
import React, {useContext} from "react"
|
2020-01-22 07:58:35 +01:00
|
|
|
import {GameModeContext} from "../contexts/gameModeContext"
|
|
|
|
|
import { MorseBufferContext } from "../contexts/morseBufferContext"
|
2020-01-30 10:23:56 +01:00
|
|
|
import { WordFeederContext } from "../contexts/wordFeederContext"
|
2020-02-04 22:38:22 +01:00
|
|
|
import { GameClockContext } from "../contexts/gameClockContext"
|
2019-12-27 09:41:53 +01:00
|
|
|
|
|
|
|
|
function ModePicker() {
|
2020-01-09 10:06:38 +01:00
|
|
|
|
2020-01-19 04:35:11 +01:00
|
|
|
const {setGameMode} = useContext(GameModeContext)
|
2020-01-22 07:58:35 +01:00
|
|
|
const {setMorseCharBuffer} = useContext(MorseBufferContext)
|
2020-01-30 10:23:56 +01:00
|
|
|
const {resetFeeder} = useContext(WordFeederContext)
|
2020-02-04 22:38:22 +01:00
|
|
|
const {stopGameClock, clockIsRunning} = useContext(GameClockContext)
|
2020-01-09 10:06:38 +01:00
|
|
|
|
|
|
|
|
function handleClick(e) {
|
2020-01-22 07:58:35 +01:00
|
|
|
setMorseCharBuffer('')
|
2020-01-30 10:23:56 +01:00
|
|
|
resetFeeder()
|
|
|
|
|
|
2020-01-19 04:35:11 +01:00
|
|
|
setGameMode(e.target.id)
|
2020-01-29 08:46:23 +01:00
|
|
|
|
2020-02-04 22:38:22 +01:00
|
|
|
if (clockIsRunning) { stopGameClock() }
|
|
|
|
|
|
2020-01-29 08:46:23 +01:00
|
|
|
let buttons = document.querySelector(".mode-picker#gameMode #buttons").childNodes
|
|
|
|
|
buttons.forEach(button => {
|
|
|
|
|
if (button.id === e.target.id) {
|
|
|
|
|
button.classList.add('selected')
|
|
|
|
|
} else { button.classList.remove('selected')}
|
|
|
|
|
})
|
2020-01-09 10:06:38 +01:00
|
|
|
console.log("Switched to " + e.target.id + " mode.");
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 09:41:53 +01:00
|
|
|
return (
|
2020-01-17 21:23:17 +01:00
|
|
|
<div id="gameMode" className="mode-picker">
|
2020-01-29 08:46:23 +01:00
|
|
|
<div id="title">
|
|
|
|
|
Mode
|
|
|
|
|
</div>
|
|
|
|
|
<div id='buttons'>
|
2020-01-30 10:23:56 +01:00
|
|
|
<button id="practice" className="selected" onClick={handleClick}>
|
2020-01-29 08:46:23 +01:00
|
|
|
Practice
|
|
|
|
|
</button>
|
|
|
|
|
<button id="training" onClick={handleClick}>
|
|
|
|
|
Training
|
|
|
|
|
</button>
|
|
|
|
|
<button id="challenge" onClick={handleClick}>
|
|
|
|
|
Challenge
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2020-01-03 08:53:56 +01:00
|
|
|
</div>
|
2019-12-27 09:41:53 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 11:37:04 +01:00
|
|
|
export default React.memo(ModePicker)
|