Compare commits
5 Commits
97de40a396
...
4b22c5ead8
| Author | SHA1 | Date |
|---|---|---|
|
|
4b22c5ead8 | |
|
|
0fc8a7383f | |
|
|
d78b47fb07 | |
|
|
695ae069d5 | |
|
|
a1eaab6534 |
|
|
@ -142,6 +142,7 @@ dist
|
||||||
|
|
||||||
# production
|
# production
|
||||||
/build
|
/build
|
||||||
|
*/build/
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nest build",
|
"build": "npm run lint && nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "nest start --watch",
|
"start": "npm run build && nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint": "eslint \"src/**/*.ts\" --fix",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"test:cov": "jest --coverage",
|
"test:cov": "jest --coverage",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { ConnectedSocket, MessageBody, OnGatewayConnection, SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
|
import {
|
||||||
|
ConnectedSocket,
|
||||||
|
OnGatewayConnection,
|
||||||
|
MessageBody,
|
||||||
|
SubscribeMessage,
|
||||||
|
WebSocketGateway,
|
||||||
|
} from '@nestjs/websockets';
|
||||||
import { PlayerService } from './players/player.service';
|
import { PlayerService } from './players/player.service';
|
||||||
import { Socket } from 'socket.io'
|
import { Socket } from 'socket.io';
|
||||||
|
|
||||||
@WebSocketGateway({ cors: true })
|
@WebSocketGateway({ cors: true })
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -9,14 +15,20 @@ export class AppService implements OnGatewayConnection {
|
||||||
private readonly logger = new Logger(AppService.name);
|
private readonly logger = new Logger(AppService.name);
|
||||||
|
|
||||||
constructor(private readonly playerService: PlayerService) {}
|
constructor(private readonly playerService: PlayerService) {}
|
||||||
handleConnection(client:Socket) {
|
handleConnection(client: Socket) {
|
||||||
this.logger.log(client.id);
|
this.logger.log(client.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeMessage('example-request')
|
@SubscribeMessage('example-request')
|
||||||
handleCustomEvent(@ConnectedSocket() client:Socket,@MessageBody() data: string): unknown {
|
handleCustomEvent(
|
||||||
|
@ConnectedSocket() client: Socket,
|
||||||
|
@MessageBody() data: string,
|
||||||
|
): unknown {
|
||||||
this.logger.debug(`Received request in backend with data: ${data}`);
|
this.logger.debug(`Received request in backend with data: ${data}`);
|
||||||
this.logger.debug(`Received data id from client: ${client.id}`);
|
this.logger.debug(`Received data id from client: ${client.id}`);
|
||||||
return {event: "example-response", data: `Replying from backend, received data: ${data}`};
|
return {
|
||||||
|
event: 'example-response',
|
||||||
|
data: `Replying from backend, received data: ${data}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { MessageBody, OnGatewayConnection, SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PlayerService {
|
export class PlayerService {
|
||||||
private readonly logger = new Logger(PlayerService.name);
|
private readonly logger = new Logger(PlayerService.name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
module.exports = {
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
project: "tsconfig.json",
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
plugins: ["@typescript-eslint/eslint-plugin"],
|
||||||
|
extends: ["plugin:@typescript-eslint/strict", "plugin:prettier/recommended"],
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
ignorePatterns: [".eslintrc.js", "dist/"],
|
||||||
|
rules: {},
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export enum ClientEvent {
|
export enum ClientEvent {
|
||||||
CREATE_LOBBY = "create-lobby",
|
CREATE_LOBBY = "create-lobby",
|
||||||
JOIN_LOBBY = "join-lobby",
|
JOIN_LOBBY = "join-lobby",
|
||||||
START_GAME = "start-game"
|
START_GAME = "start-game",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export type CreateLobbyEvent = {
|
export type CreateLobbyEvent = {
|
||||||
userName: string;
|
userName: string;
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export type JoinLobbyEvent = {
|
export type JoinLobbyEvent = {
|
||||||
userName: string;
|
userName: string;
|
||||||
lobbyId: string;
|
lobbyId: string;
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export enum TrackType {
|
export enum TrackType {
|
||||||
RAIL = "RAIL",
|
RAIL = "RAIL",
|
||||||
ROAD = "ROAD"
|
ROAD = "ROAD",
|
||||||
};
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -5,13 +5,21 @@
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"build": "npm run lint && tsc",
|
||||||
"build": "tsc"
|
"lint": "eslint \"*.ts\" \"*/**/*.ts\" --fix"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^8.0.0",
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"typescript": "^5.6.3"
|
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
||||||
|
"@typescript-eslint/parser": "^8.15.0",
|
||||||
|
"eslint": "^8.0.0",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
|
"globals": "^15.12.0",
|
||||||
|
"typescript": "^5.6.3",
|
||||||
|
"typescript-eslint": "^8.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export enum ServerError {
|
export enum ServerError {
|
||||||
CREATE_LOBBY_ERROR = "create-lobby-error",
|
CREATE_LOBBY_ERROR = "create-lobby-error",
|
||||||
JOIN_LOBBY_ERROR = "join-lobby-error"
|
JOIN_LOBBY_ERROR = "join-lobby-error",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export enum ServerEvent {
|
export enum ServerEvent {
|
||||||
LOBBY_UPDATE = "lobby-update",
|
LOBBY_UPDATE = "lobby-update",
|
||||||
START_ROUND = "start-round"
|
START_ROUND = "start-round",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
module.exports = {
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
project: "tsconfig.json",
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
plugins: ["@typescript-eslint/eslint-plugin"],
|
||||||
|
extends: ["plugin:@typescript-eslint/strict", "plugin:prettier/recommended"],
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
ignorePatterns: [".eslintrc.js", "dist/", "node_modules/", "build/"],
|
||||||
|
rules: {},
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -22,9 +22,10 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "npm run lint && react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject",
|
||||||
|
"lint": "eslint \"*/**/*.tsx\" \"*/**/*.ts\" --fix"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
|
@ -43,5 +44,13 @@
|
||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^8.0.0",
|
||||||
|
"@typescript-eslint/parser": "^8.15.0",
|
||||||
|
"eslint": "^8.0.0",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
|
"typescript-eslint": "^8.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import { render, screen } from '@testing-library/react';
|
|
||||||
import App from './App';
|
|
||||||
|
|
||||||
test('Renders hello world', () => {
|
|
||||||
render(<App />);
|
|
||||||
expect(screen.getByText("Hello World! Front")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
import { io } from "socket.io-client";
|
import { io } from "socket.io-client";
|
||||||
import LandingPage from './pages/landing/LandingPage';
|
import LandingPage from "./pages/landing/LandingPage";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const socket = io("http://localhost:3010");
|
const socket = io("http://localhost:3010");
|
||||||
const emitData = () => console.log(socket.emit("example-request", "custom-request"));
|
|
||||||
socket.on("example-response", (data) => console.log(`Received response in front end with data: ${data}`));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<LandingPage socket={socket}/>
|
<LandingPage socket={socket} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from "react-dom/client";
|
||||||
import App from './App';
|
import App from "./App";
|
||||||
import './App.scss'
|
import "./App.scss";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById("root") as HTMLElement,
|
||||||
);
|
);
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App />
|
||||||
</React.StrictMode>
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,29 @@
|
||||||
import React from "react"
|
import React, { ChangeEvent } from "react";
|
||||||
import { Socket } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
|
|
||||||
const LandingPage = (props:{socket:Socket})=>{
|
const LandingPage = (props: { socket: Socket }) => {
|
||||||
var username = "";
|
let username = "";
|
||||||
const registerUsername = (event:any) => username = event.target.value;
|
const registerUsername = (event: ChangeEvent<HTMLInputElement>) =>
|
||||||
const socket = props.socket;
|
(username = event.target.value);
|
||||||
const handleCreateLobby = () => socket.emit("create-lobby", {username:username});
|
const socket = props.socket;
|
||||||
return <React.Fragment>
|
const handleCreateLobby = () =>
|
||||||
<div className="LandingPageTitle">
|
socket.emit("create-lobby", { username: username });
|
||||||
<h1>Trains And Roads</h1>
|
return (
|
||||||
</div>
|
<React.Fragment>
|
||||||
<div className="UserNameImput">
|
<div className="LandingPageTitle">
|
||||||
<input placeholder="Enter username" onChange={registerUsername}></input>
|
<h1>Trains And Roads</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="CreateLobbyButton">
|
<div className="UserNameImput">
|
||||||
<button onClick={handleCreateLobby}>Create Lobby</button>
|
<input placeholder="Enter username" onChange={registerUsername}></input>
|
||||||
</div>
|
</div>
|
||||||
<div className="JoinLobby">
|
<div className="CreateLobbyButton">
|
||||||
<input className="LobbyIdInput" placeholder="Enter Lobby Id"></input>
|
<button onClick={handleCreateLobby}>Create Lobby</button>
|
||||||
<button className="JoinLobbyButton secondary">Join Lobby</button>
|
</div>
|
||||||
</div>
|
<div className="JoinLobby">
|
||||||
|
<input className="LobbyIdInput" placeholder="Enter Lobby Id"></input>
|
||||||
|
<button className="JoinLobbyButton secondary">Join Lobby</button>
|
||||||
|
</div>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
export default LandingPage;
|
export default LandingPage;
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
// allows you to do things like:
|
// allows you to do things like:
|
||||||
// expect(element).toHaveTextContent(/react/i)
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
// learn more: https://github.com/testing-library/jest-dom
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
import '@testing-library/jest-dom';
|
import "@testing-library/jest-dom";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue