Compare commits

..

No commits in common. "4b22c5ead8fa5453420e3782f628a46b8415eb74" and "97de40a396c8874244dcb40d39927181d5b53397" have entirely different histories.

21 changed files with 128 additions and 2859 deletions

1
.gitignore vendored
View File

@ -142,7 +142,6 @@ dist
# production
/build
*/build/
# misc
.DS_Store

View File

@ -6,12 +6,12 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "npm run lint && nest build",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "npm run build && nest start --watch",
"start": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"src/**/*.ts\" --fix",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",

View File

@ -1,13 +1,7 @@
import { Injectable, Logger } from '@nestjs/common';
import {
ConnectedSocket,
OnGatewayConnection,
MessageBody,
SubscribeMessage,
WebSocketGateway,
} from '@nestjs/websockets';
import { ConnectedSocket, MessageBody, OnGatewayConnection, SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
import { PlayerService } from './players/player.service';
import { Socket } from 'socket.io';
import { Socket } from 'socket.io'
@WebSocketGateway({ cors: true })
@Injectable()
@ -20,15 +14,9 @@ export class AppService implements OnGatewayConnection {
}
@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 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}`};
}
}

View File

@ -1,4 +1,5 @@
import { Injectable, Logger } from '@nestjs/common';
import { MessageBody, OnGatewayConnection, SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
@Injectable()
export class PlayerService {

View File

@ -1,17 +0,0 @@
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: {},
};

View File

@ -1,5 +1,5 @@
export enum ClientEvent {
CREATE_LOBBY = "create-lobby",
JOIN_LOBBY = "join-lobby",
START_GAME = "start-game",
START_GAME = "start-game"
}

View File

@ -1,3 +1,3 @@
export type CreateLobbyEvent = {
userName: string;
};
}

View File

@ -1,4 +1,4 @@
export type JoinLobbyEvent = {
userName: string;
lobbyId: string;
};
}

View File

@ -1,4 +1,4 @@
export enum TrackType {
RAIL = "RAIL",
ROAD = "ROAD",
}
ROAD = "ROAD"
};

File diff suppressed because it is too large Load Diff

View File

@ -5,21 +5,13 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "npm run lint && tsc",
"lint": "eslint \"*.ts\" \"*/**/*.ts\" --fix"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/js": "^8.0.0",
"@types/node": "^22.9.0",
"@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"
"typescript": "^5.6.3"
}
}

View File

@ -1,4 +1,4 @@
export enum ServerError {
CREATE_LOBBY_ERROR = "create-lobby-error",
JOIN_LOBBY_ERROR = "join-lobby-error",
JOIN_LOBBY_ERROR = "join-lobby-error"
}

View File

@ -1,4 +1,4 @@
export enum ServerEvent {
LOBBY_UPDATE = "lobby-update",
START_ROUND = "start-round",
START_ROUND = "start-round"
}

View File

@ -1,17 +0,0 @@
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: {},
};

926
web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,10 +22,9 @@
},
"scripts": {
"start": "react-scripts start",
"build": "npm run lint && react-scripts build",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint \"*/**/*.tsx\" \"*/**/*.ts\" --fix"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
@ -44,13 +43,5 @@
"last 1 firefox 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"
}
}

8
web/src/App.test.tsx Normal file
View File

@ -0,0 +1,8 @@
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();
});

View File

@ -1,9 +1,11 @@
import React from "react";
import React from 'react';
import { io } from "socket.io-client";
import LandingPage from "./pages/landing/LandingPage";
import LandingPage from './pages/landing/LandingPage';
function App() {
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 (
<div className="App">

View File

@ -1,13 +1,13 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./App.scss";
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './App.scss'
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement,
document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
</React.StrictMode>
);

View File

@ -1,15 +1,12 @@
import React, { ChangeEvent } from "react";
import React from "react"
import { Socket } from "socket.io-client";
const LandingPage = (props:{socket:Socket})=>{
let username = "";
const registerUsername = (event: ChangeEvent<HTMLInputElement>) =>
(username = event.target.value);
var username = "";
const registerUsername = (event:any) => username = event.target.value;
const socket = props.socket;
const handleCreateLobby = () =>
socket.emit("create-lobby", { username: username });
return (
<React.Fragment>
const handleCreateLobby = () => socket.emit("create-lobby", {username:username});
return <React.Fragment>
<div className="LandingPageTitle">
<h1>Trains And Roads</h1>
</div>
@ -24,6 +21,5 @@ const LandingPage = (props: { socket: Socket }) => {
<button className="JoinLobbyButton secondary">Join Lobby</button>
</div>
</React.Fragment>
);
};
export default LandingPage;

View File

@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";
import '@testing-library/jest-dom';