Implement GBA-Frontend
This commit is contained in:
parent
6ca02566c6
commit
612cf7ab48
0
backend/README.md
Normal file
0
backend/README.md
Normal file
16835
frontend/package-lock.json
generated
16835
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1 +1,134 @@
|
|||||||
|
@media (orientation: landscape) {
|
||||||
|
body {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (orientation: portrait) {
|
||||||
|
body {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--button-color: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.button {
|
||||||
|
line-height: var(--button-height);
|
||||||
|
height: var(--button-height);
|
||||||
|
width: var(--button-width);
|
||||||
|
text-align: center;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: bold;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-a, .button-b {
|
||||||
|
--button-height: 50px;
|
||||||
|
--button-width: 50px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: var(--button-color);
|
||||||
|
}
|
||||||
|
.button-l, .button-r {
|
||||||
|
--button-height: 50px;
|
||||||
|
--button-width: 50px;
|
||||||
|
background-color: var(--button-color);
|
||||||
|
}
|
||||||
|
.button-up, .button-down, .button-right, .button-left, .button-dummy {
|
||||||
|
--button-height: 50px;
|
||||||
|
--button-width: 50px;
|
||||||
|
background-color: var(--button-color);
|
||||||
|
}
|
||||||
|
.button-start, .button-select {
|
||||||
|
--button-height: 40px;
|
||||||
|
--button-width: 80px;
|
||||||
|
background-color: var(--button-color);
|
||||||
|
border-radius: calc( var(--button-height) * .5 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.button-up {
|
||||||
|
border-radius: 15% 15% 0% 0%;
|
||||||
|
}
|
||||||
|
.button-down {
|
||||||
|
border-radius: 0% 0% 15% 15%;
|
||||||
|
}
|
||||||
|
.button-left {
|
||||||
|
border-radius: 15% 0% 0% 15%;
|
||||||
|
}
|
||||||
|
.button-right {
|
||||||
|
border-radius: 0% 15% 15% 0%;
|
||||||
|
}
|
||||||
|
.button-l {
|
||||||
|
border-radius: 35% 5% 35% 5%;
|
||||||
|
}
|
||||||
|
.button-r {
|
||||||
|
border-radius: 5% 35% 5% 35%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.buttonwrap {
|
||||||
|
position: absolute;
|
||||||
|
height: calc(100% - 20px);
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
top: 0px;
|
||||||
|
left: 0px;
|
||||||
|
}
|
||||||
|
.buttons {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
display: grid;
|
||||||
|
/*grid-template-columns: auto auto auto 1fr auto auto;*/
|
||||||
|
grid-template-columns: auto 10px auto auto auto auto 1fr auto auto 10px auto;
|
||||||
|
grid-template-rows: auto 10px auto auto auto 1fr auto auto;
|
||||||
|
}
|
||||||
|
.button-up {
|
||||||
|
grid-column: 4;
|
||||||
|
grid-row: 3;
|
||||||
|
}
|
||||||
|
.button-left {
|
||||||
|
grid-column: 3;
|
||||||
|
grid-row: 4;
|
||||||
|
}
|
||||||
|
.button-right {
|
||||||
|
grid-column: 5;
|
||||||
|
grid-row: 4;
|
||||||
|
}
|
||||||
|
.button-down {
|
||||||
|
grid-column: 4;
|
||||||
|
grid-row: 5;
|
||||||
|
}
|
||||||
|
.button-dummy {
|
||||||
|
grid-column: 4;
|
||||||
|
grid-row: 4;
|
||||||
|
}
|
||||||
|
.button-a {
|
||||||
|
grid-column: 9;
|
||||||
|
grid-row: 4;
|
||||||
|
transform: scale(1.5);
|
||||||
|
}
|
||||||
|
.button-b {
|
||||||
|
grid-column: 8;
|
||||||
|
grid-row: 4;
|
||||||
|
transform: scale(1.5) translate(-45%, 45%);
|
||||||
|
}
|
||||||
|
.button-l {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
.button-r {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: 11;
|
||||||
|
}
|
||||||
|
.button-start {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
grid-column: 6;
|
||||||
|
grid-row: 7;
|
||||||
|
}
|
||||||
|
.button-select {
|
||||||
|
grid-column: 6;
|
||||||
|
grid-row: 8;
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import logo from './logo.svg';
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
@ -8,35 +7,44 @@ type State = {
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
const [state, setState] = useState<State>();
|
const [state, setState] = useState<State>({});
|
||||||
const socket = useRef<WebSocket>();
|
const [socket, setSocket] = useState<WebSocket>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const url = new URL(`api/client`, window.location.href);
|
const url = new URL(`api/client`, window.location.href);
|
||||||
url.protocol = url.protocol.replace("http", "ws");
|
url.protocol = url.protocol.replace("http", "ws");
|
||||||
socket.current = new WebSocket(url.href);
|
const sock = new WebSocket(url.href);
|
||||||
|
|
||||||
socket.current.onmessage = (e) => {
|
sock.onmessage = (e) => {
|
||||||
const newState = JSON.parse(e.data) as State;
|
const newState = JSON.parse(e.data) as State;
|
||||||
setState(newState);
|
setState(newState);
|
||||||
}
|
}
|
||||||
|
setSocket(sock);
|
||||||
|
|
||||||
return () => socket.current && socket.current.close()
|
return () => {
|
||||||
})
|
sock.close();
|
||||||
|
setSocket(undefined);
|
||||||
|
};
|
||||||
|
}, [])
|
||||||
|
|
||||||
const buttonHandler = (e: React.MouseEvent<HTMLButtonElement>) => {
|
const clickButton = (button: string) => (e: React.MouseEvent) => {
|
||||||
socket.current && socket.current.send(JSON.stringify({ "type": "ping" }));
|
if (!socket) return;
|
||||||
}
|
socket.send(JSON.stringify({ "button": button }));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div>
|
||||||
<p>Ok Brudi Pokemon</p>
|
<div style={{ position: "absolute", top: 10, left: "50%" }}>
|
||||||
<p>
|
|
||||||
State: <pre>{JSON.stringify(state)}</pre>
|
State: <pre>{JSON.stringify(state)}</pre>
|
||||||
</p>
|
</div>
|
||||||
<p>
|
<div className="buttonwrap">
|
||||||
<button onClick={buttonHandler}>ping</button>
|
<div className="buttons">
|
||||||
</p>
|
{"up down left right a b l r start select".split(" ").map((b) =>
|
||||||
|
<div className={`button button-${b}`} onClick={clickButton(b)}>{b}</div>
|
||||||
|
)}
|
||||||
|
<div className="button button-dummy" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user