added deployment

This commit is contained in:
evanpelle
2024-08-13 20:07:20 -07:00
parent efd5f65787
commit 001722bd59
11 changed files with 90 additions and 70 deletions
+4 -2
View File
@@ -1,8 +1,8 @@
import {defaultConfig} from "../core/configuration/DefaultConfig";
import {TerrainMap} from "../core/Game";
import {PseudoRandom} from "../core/PseudoRandom";
import {ServerMessage, ServerMessageSchema} from "../core/Schemas";
import {loadTerrainMap} from "../core/TerrainMapLoader";
import {generateUniqueID} from "../core/Util";
import {ClientGame, createClientGame} from "./ClientGame";
import {v4 as uuidv4} from 'uuid';
@@ -18,6 +18,8 @@ class Client {
private lobbiesContainer: HTMLElement | null;
private lobbiesInterval: NodeJS.Timeout | null = null;
private random = new PseudoRandom(1234)
constructor() {
this.lobbiesContainer = document.getElementById('lobbies-container');
@@ -84,7 +86,7 @@ class Client {
if (this.game != null) {
return
}
this.game = createClientGame(getUsername(), generateUniqueID(), lobbyID, defaultConfig, map)
this.game = createClientGame(getUsername(), this.random.nextID(), lobbyID, defaultConfig, map)
this.game.joinLobby()
})
}
+2 -1
View File
@@ -60,7 +60,8 @@ export class ClientGame {
) { }
public joinLobby() {
this.socket = new WebSocket(`ws://localhost:3000`)
const wsHost = process.env.WEBSOCKET_URL || window.location.host;
this.socket = new WebSocket(`ws://${wsHost}`)
this.socket.onopen = () => {
console.log('Connected to game server!');
this.socket.send(
+4
View File
@@ -30,4 +30,8 @@ export class PseudoRandom {
nextFloat(min: number, max: number): number {
return this.next() * (max - min) + min;
}
nextID(): string {
return this.nextInt(0, 1000000).toString(36).padStart(5, '0');
}
}
-6
View File
@@ -1,11 +1,5 @@
import {Cell} from "./Game";
export function generateUniqueID(): string {
const array = new Uint8Array(16);
crypto.getRandomValues(array);
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
}
export function manhattanDist(c1: Cell, c2: Cell): number {
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
}
+5 -3
View File
@@ -3,8 +3,8 @@ import {Client} from "./Client";
import {Lobby} from "./Lobby";
import {GameServer} from "./GameServer";
import {Config} from "../core/configuration/Config";
import {generateUniqueID} from "../core/Util";
import {defaultConfig} from "../core/configuration/DefaultConfig";
import {PseudoRandom} from "../core/PseudoRandom";
export class GameManager {
@@ -14,6 +14,8 @@ export class GameManager {
private games: Map<GameID, GameServer> = new Map()
private random = new PseudoRandom(123)
constructor(private settings: Config) { }
@@ -42,7 +44,7 @@ export class GameManager {
}
startGame(lobby: Lobby) {
const gs = new GameServer(generateUniqueID(), lobby.clients, defaultConfig)
const gs = new GameServer(this.random.nextID(), lobby.clients, defaultConfig)
this.games.set(gs.id, gs)
gs.start()
}
@@ -61,7 +63,7 @@ export class GameManager {
if (now > this.lastNewLobby + this.settings.lobbyCreationRate()) {
this.lastNewLobby = now
this.addLobby(new Lobby(generateUniqueID(), this.settings.lobbyLifetime()))
this.addLobby(new Lobby(this.random.nextID(), this.settings.lobbyLifetime()))
}
}
}