comment out gpio stuff

This commit is contained in:
dylan 2024-04-04 08:58:39 -07:00
parent 85cbf665f0
commit 903c66b1d9
3 changed files with 76 additions and 48 deletions

View File

@ -19,19 +19,19 @@ export const GamePage = () => {
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;
}
}
}
// 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);
}
})
@ -95,13 +95,17 @@ export const GamePage = () => {
border: 2px solid limegreen;
}
`}>
<Pico8Console ref={picoRef} carts={info.release.carts} onGpioChange={(gpio: number[]) => {
console.log("sending gpio");
socket.sendMessage({
type: "gpio",
gpio,
});
}} />
<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;

View File

@ -8,13 +8,16 @@ export type Pico8ConsoleImperatives = {
export type Pico8ConsoleProps = {
carts: PicoCart[],
onGpioChange?(gpio: number[]): void,
// onGpioChange?(gpio: number[]): void,
}
const noop = () => {};
// const noop = () => {};
export const Pico8Console = forwardRef((props: Pico8ConsoleProps, forwardedRef: ForwardedRef<Pico8ConsoleImperatives>) => {
const {carts, onGpioChange = noop} = props;
const {
carts,
// onGpioChange = noop
} = props;
const [playing, setPlaying] = useState(false);
const ref = useRef<HTMLDivElement>(null);
const [handle, setHandle] = useState<PicoPlayerHandle | null>(null);
@ -33,7 +36,7 @@ export const Pico8Console = forwardRef((props: Pico8ConsoleProps, forwardedRef:
picoConsole.canvas.focus();
}
setHandle(picoConsole);
picoConsole.gpio.subscribe(onGpioChange);
// picoConsole.gpio.subscribe(onGpioChange);
picoConsole.canvas.addEventListener('keydown',(event) => {
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event.key)) {
event.preventDefault();

View File

@ -35,7 +35,10 @@ export type PicoPlayerHandle = {
rightClick: boolean;
}) => void;
setGamepadCount: (count: number) => void;
gpio: number[] & {subscribe: (f: (gpio: number[]) => void) => void}; // read + write (should be 256-tuple)
gpio: (
number[]
// & {subscribe: (f: (gpio: number[]) => void) => void}
); // read + write (should be 256-tuple)
// state
readonly state: {
@ -97,8 +100,7 @@ export const makePicoConsole = async (props: {
handle.pico8_state = {};
handle.pico8_buttons = [0,0,0,0,0,0,0,0];
handle.pico8_mouse = [0,0,0];
let gpioChanged = (gpio: number[]) => {};
const gpioInner = [
handle.pico8_gpio = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -116,27 +118,46 @@ export const makePicoConsole = async (props: {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
handle.pico8_gpio = new Proxy(gpioInner, {
get(target, prop) {
return target[prop as any];
},
set(target, prop, newValue) {
const t = target as any;
if (t.setting) {
return false;
}
const prev = [...target];
target[prop as any] = newValue;
const next = [...target];
if (!t.dontSend && prev.some((p, i) => p !== next[i])) {
gpioChanged(target);
}
return true;
}
});
(handle as any).pico8_gpio.subscribe = (f: (gpio: number[]) => void) => {
gpioChanged = f;
}
// let gpioChanged = (gpio: number[]) => {};
// const gpioInner = [
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// ];
// handle.pico8_gpio = new Proxy(gpioInner, {
// get(target, prop) {
// return target[prop as any];
// },
// set(target, prop, newValue) {
// const t = target as any;
// if (t.setting) {
// return false;
// }
// const prev = [...target];
// target[prop as any] = newValue;
// const next = [...target];
// if (!t.dontSend && prev.some((p, i) => p !== next[i])) {
// gpioChanged(target);
// }
// return true;
// }
// });
// (handle as any).pico8_gpio.subscribe = (f: (gpio: number[]) => void) => {
// gpioChanged = f;
// }
handle.pico8_gamepads = {count: 0};
return {
raw: handle,