Skip to content

Commit 7dac3ad

Browse files
committed
switch from preact to solid
1 parent ecb0d76 commit 7dac3ad

File tree

22 files changed

+627
-1008
lines changed

22 files changed

+627
-1008
lines changed

package-lock.json

Lines changed: 191 additions & 382 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
"dependencies": {
3232
"gl-matrix": "^3.4.3",
3333
"nanoevents": "^9.0.0",
34-
"preact": "^10.23.2",
34+
"solid-js": "^1.8.22",
3535
"typestyle": "^2.0.4"
3636
},
3737
"devDependencies": {
38-
"@preact/preset-vite": "^2.9.0",
3938
"@types/gl-matrix": "^3.2.0",
4039
"@types/pngjs": "^6.0.5",
4140
"pngjs": "^7.0.0",
4241
"typescript": "^5.5.4",
43-
"vite": "^5.4.3"
42+
"vite": "^5.4.3",
43+
"vite-plugin-solid": "^2.10.2"
4444
}
4545
}

src/Loader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class Loader {
198198
return
199199
}
200200

201-
const replay = await Replay.parseIntoChunks(buffer)
201+
const replay = Replay.parseIntoChunks(buffer)
202202
this.replay.done(replay)
203203

204204
this.loadMap(`${replay.maps[0].name}.bsp`)
@@ -243,7 +243,7 @@ export class Loader {
243243
return
244244
}
245245

246-
const map = await BspParser.parse(name, buffer)
246+
const map = BspParser.parse(name, buffer)
247247
this.map.done(map)
248248

249249
map.entities
@@ -360,7 +360,7 @@ export class Loader {
360360
return
361361
}
362362

363-
const wad = await Wad.parse(buffer)
363+
const wad = Wad.parse(buffer)
364364
wadItem.done(wad)
365365

366366
if (!this.map || !this.map.data) {

src/Parsers/BspParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface BspLumpTexInfo {
206206
export type BspLumpLightmap = Uint8Array
207207

208208
export const BspParser = {
209-
parse(name: string, buffer: ArrayBuffer): Bsp {
209+
parse(name: string, buffer: ArrayBuffer) {
210210
const r = new Reader(buffer)
211211
const version = r.ui()
212212
if (version !== 30) {
Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,45 @@
1-
import { h, Component } from 'preact'
1+
import { createSignal, onCleanup, onMount } from 'solid-js'
22
import { classes } from 'typestyle'
33
import { Fullscreen } from '../../../Fullscreen'
44
import { FullscreenButtonStyle as s } from './style'
55
import { ControlsStyle as cs } from '../../Controls.style'
66

7-
interface FullscreenButtonProps {
8-
active: boolean
9-
root: Element
10-
}
11-
12-
interface FullscreenButtonState {
13-
isInFullscreen: boolean
14-
}
15-
16-
export class FullscreenButton extends Component<FullscreenButtonProps, FullscreenButtonState> {
17-
state: FullscreenButtonState = {
18-
isInFullscreen: false
19-
}
7+
export function FullscreenButton(props: { active: boolean; root: Element }) {
8+
const [isInFullscreen, setIsInFullscreen] = createSignal(Fullscreen.isInFullscreen())
209

21-
componentDidMount() {
22-
Fullscreen.onChange(this.onFullscreen)
23-
}
10+
onMount(() => {
11+
Fullscreen.onChange(onFullscreen)
12+
})
2413

25-
componentWillUnmount() {
26-
Fullscreen.onChangeRemove(this.onFullscreen)
27-
}
14+
onCleanup(() => {
15+
Fullscreen.onChangeRemove(onFullscreen)
16+
})
2817

29-
onClick = () => {
18+
const onClick = () => {
3019
if (Fullscreen.isInFullscreen()) {
3120
Fullscreen.exit()
3221
} else {
33-
Fullscreen.enter(this.props.root)
22+
Fullscreen.enter(props.root)
3423
}
3524
}
3625

37-
onFullscreen = () => {
38-
this.setState({
39-
isInFullscreen: Fullscreen.isInFullscreen()
40-
})
26+
const onFullscreen = () => {
27+
setIsInFullscreen(Fullscreen.isInFullscreen())
4128
}
4229

43-
render() {
44-
return (
45-
<button type="button" class={classes(cs.button, s.button)} onClick={this.onClick}>
46-
{this.state.isInFullscreen ? (
47-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
48-
<title>Exit fullscreen</title>
49-
<path d="M0 22 L22 22 L22 0 L14 0 L14 14 L0 14 M42 0 L42 22 L64 22 L64 14 L50 14 L50 0 M14 50 L0 50 L0 42 L22 42 L22 64 L14 64 M42 64 L42 42 L64 42 L64 50 L50 50 L50 64 Z" />
50-
</svg>
51-
) : (
52-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
53-
<title>Fullscreen</title>
54-
<path d="M0 22 L8 22 L8 8 L22 8 L22 0 L0 0 M42 0 L42 8 L56 8 L56 22 L64 22 L64 0 M0 64 L0 42 L8 42 L8 56 L22 56 L22 64 M64 64 L42 64 L42 56 L56 56 L56 42 L64 42 Z" />
55-
</svg>
56-
)}
57-
</button>
58-
)
59-
}
30+
return (
31+
<button type="button" class={classes(cs.button, s.button)} onClick={onClick}>
32+
{isInFullscreen() ? (
33+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
34+
<title>Exit fullscreen</title>
35+
<path d="M0 22 L22 22 L22 0 L14 0 L14 14 L0 14 M42 0 L42 22 L64 22 L64 14 L50 14 L50 0 M14 50 L0 50 L0 42 L22 42 L22 64 L14 64 M42 64 L42 42 L64 42 L64 50 L50 50 L50 64 Z" />
36+
</svg>
37+
) : (
38+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
39+
<title>Fullscreen</title>
40+
<path d="M0 22 L8 22 L8 8 L22 8 L22 0 L0 0 M42 0 L42 8 L56 8 L56 22 L64 22 L64 0 M0 64 L0 42 L8 42 L8 56 L22 56 L22 64 M64 64 L42 64 L42 56 L56 56 L56 42 L64 42 Z" />
41+
</svg>
42+
)}
43+
</button>
44+
)
6045
}

src/PlayerInterface/Buttons/PauseButton/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { h } from 'preact'
21
import { ControlsStyle as cs } from '../../Controls.style'
32

43
export function PauseButton(props: { onClick(): void }) {

src/PlayerInterface/Buttons/PlayButton/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { h } from 'preact'
21
import { ControlsStyle as cs } from '../../Controls.style'
32

43
export function PlayButton(props: { onClick(): void }) {
54
return (
6-
<button type="button" class={cs.button} onClick={props.onClick}>
5+
<button type="button" class={cs.button} onClick={() => props.onClick()}>
76
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
87
<title>Play</title>
98
<path d="M0 0 L0 64 L64 32 Z" />
Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,65 @@
1-
import { h, Component } from 'preact'
1+
import { createSignal } from 'solid-js'
22
import { classes } from 'typestyle'
33
import { type Game, PlayerMode } from '../../../Game'
4-
import { SettingsButtonStyle as s } from './style'
54
import { ControlsStyle as cs } from '../../Controls.style'
5+
import { SettingsButtonStyle as s } from './style'
66

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
1410

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) {
1813
return
1914
}
2015

21-
this.props.game.changeMode(PlayerMode.FREE)
22-
this.props.game.player.pause()
16+
props.game.changeMode(PlayerMode.FREE)
17+
props.game.player.pause()
2318
}
2419

25-
onReplayModeClick = () => {
26-
if (this.props.game.mode === PlayerMode.REPLAY) {
20+
const onReplayModeClick = () => {
21+
if (props.game.mode === PlayerMode.REPLAY) {
2722
return
2823
}
2924

30-
this.props.game.changeMode(PlayerMode.REPLAY)
25+
props.game.changeMode(PlayerMode.REPLAY)
3126
}
3227

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/svg" viewBox="0 0 24 24">
32+
<title>Toggle</title>
33+
<path
34+
fill-rule="evenodd"
35+
clip-rule="evenodd"
36+
fill="#ffffff"
37+
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"
38+
/>
39+
</svg>
40+
</button>
3641

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 ? (
6745
<button
6846
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()}
7149
>
72-
Free
50+
Replay
7351
</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>
7562
</div>
76-
)
77-
}
63+
</div>
64+
)
7865
}

src/PlayerInterface/Buttons/SpeedDownButton/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { h } from 'preact'
21
import { classes } from 'typestyle'
32
import { SpeedDownButtonStyle as s } from './style'
43
import { ControlsStyle as cs } from '../../Controls.style'
54

65
export function SpeedDownButton(props: { onClick(): void }) {
76
return (
8-
<button type="button" class={classes(cs.button, s.button)} onClick={props.onClick}>
7+
<button type="button" class={classes(cs.button, s.button)} onClick={() => props.onClick()}>
98
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
109
<title>Speed Down</title>
1110
<path d="M0 0 L0 64 L32 32 L32 64 L64 32 L32 0 L32 32 Z" />

src/PlayerInterface/Buttons/SpeedUpButton/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { h } from 'preact'
21
import { ControlsStyle as cs } from '../../Controls.style'
32

43
export function SpeedUpButton(props: { onClick(): void }) {
54
return (
6-
<button type="button" class={cs.button} onClick={props.onClick}>
5+
<button type="button" class={cs.button} onClick={() => props.onClick()}>
76
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentcolor">
87
<title>Speed Up</title>
98
<path d="M0 0 L0 64 L32 32 L32 64 L64 32 L32 0 L32 32 Z" />

0 commit comments

Comments
 (0)