Skip to content

Commit

Permalink
improve remote ui
Browse files Browse the repository at this point in the history
  • Loading branch information
flmichel committed Oct 29, 2023
1 parent 5420815 commit e32f3ac
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 61 deletions.
2 changes: 1 addition & 1 deletion remote/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lAPI_BASE_URL=http://192.168.0.107:8000/api
API_BASE_URL=http://192.168.0.107:8000/api
CORS=true
52 changes: 26 additions & 26 deletions remote/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"webpack-dev-server": "^4.13.3"
},
"dependencies": {
"lit": "^2.7.4"
"lit": "^3.0.1"
}
}
Binary file added remote/public/emoji-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions remote/src/actions/game-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sendStringToGame, sendToGame } from "../api/game";
import { GamePhase, state } from "../state/state";
import { Action } from "./actions";
import { ConfigureGameChannel } from "./webrtc";

export class UpdatePlayerName implements Action {
playerName: string;
Expand Down Expand Up @@ -52,3 +53,15 @@ function generateRandomId(): string {

return base64;
}

export class EnterGame implements Action {
roomId: string;

constructor(roomId: string) {
this.roomId = roomId;
}

execute(): void {
new ConfigureGameChannel(this.roomId).execute();
}
}
2 changes: 2 additions & 0 deletions remote/src/state/displayState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { DisplaySettings, GameState, State } from "./state";
export interface DisplayState {
route: string;
gameState: GameState;
isInRoom: boolean;
displaySettings: DisplaySettings;
}

export function computeDisplayState(state: State): DisplayState {
return {
route: state.route,
gameState: state.game.state,
isInRoom: state.game.roomId != null,
displaySettings: state.displaySettings,
};
}
5 changes: 3 additions & 2 deletions remote/src/view/game-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { customElement, property } from "lit/decorators.js";
import { GamePhase, State } from "../state/state";
import "./navbar";
import "./pages/homepage";
import "./pages/remote";
import "./pages/game-remote";
import "./pages/game-configuration";
import { DisplayState } from "../state/displayState";

Expand All @@ -16,13 +16,14 @@ export class View extends LitElement {
switch (this.state.gameState.phase) {
case GamePhase.BeforeNextGame:
return html`
<nav-bar></nav-bar>
<game-configuration
.state=${this.state.gameState}
></game-configuration>
`;
case GamePhase.InGame:
console.log("InGame phase updated");
return html` <remote-canvas .state=${this.state}></remote-canvas> `;
return html` <game-remote .state=${this.state}></game-remote> `;
default:
return html` <p>this is not normal</p> `;
}
Expand Down
34 changes: 25 additions & 9 deletions remote/src/view/navbar.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators.js";
import { trigger, Route } from "../actions/actions";
import { DisplayState } from "../state/displayState";
import { StyledElement } from "./style/styled-element";

@customElement("nav-bar")
export class Navbar extends LitElement {
static styles = css`
li {
color: blue;
}
`;
static styles = [
StyledElement.styles,
css`
ul {
list-style: none;
display: flex;
background-color: #000000;
justify-content: center;
align-items: center;
}
@property({ type: Object, reflect: true })
state!: DisplayState;
li {
margin: 0;
padding: 10px;
}
li img {
width: 40px;
height: 40px;
cursor: pointer;
}
`,
];

render() {
return html`
<ul>
<li><button @click=${() => trigger(new Route("/"))}>Home</button></li>
<li><img src="emoji-icon.png" @click=${() =>
trigger(new Route("/"))}></button></li>
<li>
<button @click=${() => trigger(new Route("/login"))}>Login</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { customElement, property } from "lit/decorators.js";
import { CanvasData, ControllerId } from "../../actions/remote";
import { DisplayState } from "../../state/displayState";

@customElement("remote-canvas")
export class CanvasTouch extends LitElement {
@customElement("game-remove")
export class GameRemote extends LitElement {
static get styles() {
return css`
#remote {
Expand Down
58 changes: 52 additions & 6 deletions remote/src/view/pages/homepage.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators.js";
import { Authentication } from "../../state/state";
import { DisplayState } from "../../state/displayState";
import { StyledElement } from "../style/styled-element";
import { trigger } from "../../actions/actions";
import { EnterGame } from "../../actions/game-configuration";

@customElement("home-page")
export class HomePage extends LitElement {
static styles = css`
li {
color: blue;
}
`;
static styles = [
StyledElement.styles,
css`
form,
div {
text-align: center;
}
input {
margin: 10px 0;
}
`,
];

@property({ type: Object })
state!: DisplayState;

render() {
return html` The is the homepage `;
return html`
<nav-bar .state=${this.state}></nav-bar>
${this.renderPage(this.state.route)}
`;
}

renderPage(route: string) {
switch (route) {
case "/":
return html`
<form
@submit=${() =>
trigger(
new EnterGame(
this.shadowRoot!.getElementById("inputField")!.innerHTML
)
)}
>
<input
type="text"
id="inputField"
placeholder="Enter game room ID"
required
/>
<br />
<button type="submit">Join room</button>
</form>
<div>
<p>Or</p>
<button>Scan QR Code</button>
</div>
`;
}
}
}
26 changes: 26 additions & 0 deletions remote/src/view/style/styled-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { LitElement, html, css, CSSResultGroup } from "lit";
import { customElement } from "lit/decorators.js";

export abstract class StyledElement extends LitElement {
static styles = css`
button {
color: black;
font-size: 30px;
background-color: #ffbe0a;
border-radius: 10px;
}
button:hover {
background-color: #ffdf9a;
}
input {
font-size: 20px;
border-radius: 10px;
}
p {
font-size: 20px;
}
`;
}
18 changes: 4 additions & 14 deletions remote/src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,10 @@ export class View extends LitElement {
}

render() {
return html` <div>
<nav-bar .state=${this.state}></nav-bar>
${this.renderPage(this.state.route)}
</div>`;
}

renderPage(route: string) {
console.log("rerendering page (root view)", this.state.gameState.isReady);
switch (route) {
case "/":
return html`
<home-page></home-page>
<game-view .state=${this.state}></game-view>
`;
if (this.state.isInRoom) {
return html`<game-view .state=${this.state}></game-view>`;
} else {
return html` <home-page .state=${this.state}></home-page> `;
}
}
}

0 comments on commit e32f3ac

Please sign in to comment.