some stuff
This commit is contained in:
+23
-8
@@ -1,6 +1,6 @@
|
||||
import { Link, useParams, useSearchParams } from "react-router-dom"
|
||||
import { Pico8Console } from "./pico8-client/Pico8Console";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Pico8Console, Pico8ConsoleImperatives } from "./pico8-client/Pico8Console";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { DbRelease } from "../server/dbal/dbal";
|
||||
import { css } from "@emotion/css";
|
||||
import { useWebsocket } from "./hooks/useWebsocket";
|
||||
@@ -14,10 +14,24 @@ export const GamePage = () => {
|
||||
const {author, slug} = useParams();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const room = searchParams.get('room');
|
||||
const picoRef = useRef<Pico8ConsoleImperatives>(null);
|
||||
const socket = useWebsocket({
|
||||
url: `/api/ws/room?room=${room}`,
|
||||
// url: "wss://echo.websocket.org",
|
||||
onMessage({message}) {
|
||||
const msg = message as any;
|
||||
if (msg.type === "gpio") {
|
||||
if (picoRef.current) {
|
||||
const handle = picoRef.current.getPicoConsoleHandle();
|
||||
if (handle) {
|
||||
console.log("updating pico gpio");
|
||||
(handle.gpio as any).dontSend = true;
|
||||
handle.gpio.length = 0;
|
||||
handle.gpio.push(...msg.gpio);
|
||||
(handle.gpio as any).dontSend = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('message', message);
|
||||
}
|
||||
})
|
||||
@@ -81,7 +95,13 @@ export const GamePage = () => {
|
||||
border: 2px solid limegreen;
|
||||
}
|
||||
`}>
|
||||
<Pico8Console carts={info.release.carts} />
|
||||
<Pico8Console ref={picoRef} carts={info.release.carts} onGpioChange={(gpio: number[]) => {
|
||||
console.log("sending gpio");
|
||||
socket.sendMessage({
|
||||
type: "gpio",
|
||||
gpio,
|
||||
});
|
||||
}} />
|
||||
</div>
|
||||
<div className={css`
|
||||
display: flex;
|
||||
@@ -96,11 +116,6 @@ export const GamePage = () => {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button onClick={() => {
|
||||
room && socket.sendMessage({room, type: "hello", name: "world"});
|
||||
}}>Websocket</button>
|
||||
</div>
|
||||
{/* <div>
|
||||
<p>This is a paragraph about this game. It is a cool game. And a cool website to play it on. It automagically connects from GitHub.</p>
|
||||
</div> */}
|
||||
|
||||
Reference in New Issue
Block a user