|
1 | | -import { h, Component } from 'preact' |
| 1 | +import { createSignal } from 'solid-js' |
2 | 2 | import { classes } from 'typestyle' |
3 | 3 | import { type Game, PlayerMode } from '../../../Game' |
4 | | -import { SettingsButtonStyle as s } from './style' |
5 | 4 | import { ControlsStyle as cs } from '../../Controls.style' |
| 5 | +import { SettingsButtonStyle as s } from './style' |
6 | 6 |
|
7 | | -interface SettingsButtonProps { |
8 | | - game: Game |
9 | | -} |
10 | | - |
11 | | -interface SettingsButtonState { |
12 | | - isOpen: boolean |
13 | | -} |
| 7 | +export function SettingsButton(props: { game: Game }) { |
| 8 | + const [isOpen, setIsOpen] = createSignal(false) |
| 9 | + const hasReplay = !!props.game.player.replay |
14 | 10 |
|
15 | | -export class SettingsButton extends Component<SettingsButtonProps, SettingsButtonState> { |
16 | | - onFreeModeClick = () => { |
17 | | - if (this.props.game.mode === PlayerMode.FREE) { |
| 11 | + const onFreeModeClick = () => { |
| 12 | + if (props.game.mode === PlayerMode.FREE) { |
18 | 13 | return |
19 | 14 | } |
20 | 15 |
|
21 | | - this.props.game.changeMode(PlayerMode.FREE) |
22 | | - this.props.game.player.pause() |
| 16 | + props.game.changeMode(PlayerMode.FREE) |
| 17 | + props.game.player.pause() |
23 | 18 | } |
24 | 19 |
|
25 | | - onReplayModeClick = () => { |
26 | | - if (this.props.game.mode === PlayerMode.REPLAY) { |
| 20 | + const onReplayModeClick = () => { |
| 21 | + if (props.game.mode === PlayerMode.REPLAY) { |
27 | 22 | return |
28 | 23 | } |
29 | 24 |
|
30 | | - this.props.game.changeMode(PlayerMode.REPLAY) |
| 25 | + props.game.changeMode(PlayerMode.REPLAY) |
31 | 26 | } |
32 | 27 |
|
33 | | - toggleMenu = () => { |
34 | | - this.setState({ isOpen: !this.state.isOpen }) |
35 | | - } |
| 28 | + return ( |
| 29 | + <div class={s.settings}> |
| 30 | + <button type="button" class={classes(cs.button, s.button)} onClick={() => setIsOpen(!isOpen())}> |
| 31 | + <svg xmlns="http://www.w3.org/2000/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 12.5 24 11.6 23.9 10.7zM12 18c-3.3 0-6-2.7-6-6s2.7-6 6-6c3.3 0 6 2.7 6 6S15.3 18 12 18zM12 16" |
| 38 | + /> |
| 39 | + </svg> |
| 40 | + </button> |
36 | 41 |
|
37 | | - render() { |
38 | | - const hasReplay = !!this.props.game.player.replay |
39 | | - |
40 | | - return ( |
41 | | - <div class={s.settings}> |
42 | | - <button type="button" class={classes(cs.button, s.button)} onClick={this.toggleMenu}> |
43 | | - <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> |
44 | | - <title>Toggle</title> |
45 | | - <path |
46 | | - fill-rule="evenodd" |
47 | | - clip-rule="evenodd" |
48 | | - fill="#ffffff" |
49 | | - d="M23.9 10.7c0-0.3-0.4-0.6-0.8-0.6 -1.1 0-2.1-0.6-2.5-1.6 -0.4-1-0.1-2.2 0.7-3 0.3-0.2 0.3-0.6 0.1-0.9 -0.6-0.7-1.2-1.4-1.9-1.9 -0.3-0.2-0.7-0.2-0.9 0.1 -0.7 0.8-2 1.1-3 0.7 -1-0.4-1.7-1.5-1.6-2.6 0-0.4-0.2-0.7-0.6-0.7 -0.9-0.1-1.8-0.1-2.7 0C10.4 0.1 10.1 0.4 10.1 0.8 10.1 1.9 9.5 2.9 8.5 3.3 7.5 3.7 6.2 3.4 5.5 2.6c-0.2-0.3-0.6-0.3-0.9-0.1 -0.7 0.6-1.4 1.2-1.9 1.9C2.4 4.8 2.5 5.2 2.7 5.4c0.8 0.8 1.1 2 0.7 3 -0.4 1-1.4 1.6-2.6 1.6 -0.4 0-0.7 0.2-0.7 0.6 -0.1 0.9-0.1 1.8 0 2.7 0 0.3 0.4 0.6 0.8 0.6 1 0 2 0.6 2.5 1.6 0.4 1 0.2 2.2-0.7 3 -0.3 0.2-0.3 0.6-0.1 0.9 0.6 0.7 1.2 1.4 1.9 1.9 0.3 0.2 0.7 0.2 0.9-0.1 0.7-0.8 2-1.1 3-0.7 1 0.4 1.7 1.5 1.6 2.6 0 0.4 0.2 0.7 0.6 0.7C11.1 24 11.5 24 12 24c0.4 0 0.9 0 1.3-0.1 0.3 0 0.6-0.3 0.6-0.7 0-1.1 0.6-2.1 1.6-2.6 1-0.4 2.3-0.1 3 0.7 0.2 0.3 0.6 0.3 0.9 0.1 0.7-0.6 1.4-1.2 1.9-1.9 0.2-0.3 0.2-0.7-0.1-0.9 -0.8-0.8-1.1-2-0.7-3 0.4-1 1.4-1.6 2.5-1.6l0.1 0c0.3 0 0.7-0.2 0.7-0.6C24 12.5 24 11.6 23.9 10.7zM12 18c-3.3 0-6-2.7-6-6s2.7-6 6-6c3.3 0 6 2.7 6 6S15.3 18 12 18zM12 16" |
50 | | - /> |
51 | | - </svg> |
52 | | - </button> |
53 | | - |
54 | | - <div class={this.state.isOpen ? s.menuOpen : s.menu}> |
55 | | - <span class={s.menuItemTitle}>Mode</span> |
56 | | - {hasReplay ? ( |
57 | | - <button |
58 | | - type="button" |
59 | | - class={this.props.game.mode === PlayerMode.REPLAY ? s.menuItemSelected : s.menuItem} |
60 | | - onClick={this.onReplayModeClick} |
61 | | - > |
62 | | - Replay |
63 | | - </button> |
64 | | - ) : ( |
65 | | - <span /> |
66 | | - )} |
| 42 | + <div class={isOpen() ? s.menuOpen : s.menu}> |
| 43 | + <span class={s.menuItemTitle}>Mode</span> |
| 44 | + {hasReplay ? ( |
67 | 45 | <button |
68 | 46 | type="button" |
69 | | - class={this.props.game.mode === PlayerMode.FREE ? s.menuItemSelected : s.menuItem} |
70 | | - onClick={this.onFreeModeClick} |
| 47 | + class={props.game.mode === PlayerMode.REPLAY ? s.menuItemSelected : s.menuItem} |
| 48 | + onClick={() => onReplayModeClick()} |
71 | 49 | > |
72 | | - Free |
| 50 | + Replay |
73 | 51 | </button> |
74 | | - </div> |
| 52 | + ) : ( |
| 53 | + <span /> |
| 54 | + )} |
| 55 | + <button |
| 56 | + type="button" |
| 57 | + class={props.game.mode === PlayerMode.FREE ? s.menuItemSelected : s.menuItem} |
| 58 | + onClick={() => onFreeModeClick()} |
| 59 | + > |
| 60 | + Free |
| 61 | + </button> |
75 | 62 | </div> |
76 | | - ) |
77 | | - } |
| 63 | + </div> |
| 64 | + ) |
78 | 65 | } |
0 commit comments