update aws deployment, have client get env from server

This commit is contained in:
Evan
2025-03-05 12:37:37 -08:00
parent be5157a25c
commit 2b26cfbbc9
15 changed files with 159 additions and 66 deletions
+4 -5
View File
@@ -18,12 +18,13 @@ import {
} from "../core/game/GameUpdates";
import { WorkerClient } from "../core/worker/WorkerClient";
import { consolex, initRemoteSender } from "../core/Consolex";
import { getConfig, getServerConfig } from "../core/configuration/Config";
import { getConfig, ServerConfig } from "../core/configuration/Config";
import { GameView, PlayerView } from "../core/game/GameView";
import { GameUpdateViewData } from "../core/game/GameUpdates";
import { UserSettings } from "../core/game/UserSettings";
export interface LobbyConfig {
serverConfig: ServerConfig;
flag: () => string;
playerName: () => string;
clientID: ClientID;
@@ -51,8 +52,6 @@ export function joinLobby(
`joinging lobby: gameID: ${lobbyConfig.gameID}, clientID: ${lobbyConfig.clientID}, persistentID: ${lobbyConfig.persistentID}`,
);
const serverConfig = getServerConfig();
const userSettings: UserSettings = new UserSettings();
let gameConfig: GameConfig = null;
if (lobbyConfig.gameType == GameType.Singleplayer) {
@@ -72,7 +71,7 @@ export function joinLobby(
lobbyConfig,
gameConfig,
eventBus,
serverConfig,
lobbyConfig.serverConfig,
);
const onconnect = () => {
@@ -106,7 +105,7 @@ export async function createClientGame(
transport: Transport,
userSettings: UserSettings,
): Promise<ClientGameRunner> {
const config = getConfig(gameConfig, userSettings);
const config = await getConfig(gameConfig, userSettings);
const gameMap = await loadTerrainMap(gameConfig.gameMap);
const worker = new WorkerClient(
+16 -13
View File
@@ -7,7 +7,10 @@ import "./components/Difficulties";
import { DifficultyDescription } from "./components/Difficulties";
import "./components/Maps";
import { generateID } from "../core/Util";
import { getConfig, getServerConfig } from "../core/configuration/Config";
import {
getConfig,
getServerConfigFromClient,
} from "../core/configuration/Config";
@customElement("host-lobby-modal")
export class HostLobbyModal extends LitElement {
@@ -584,8 +587,9 @@ export class HostLobbyModal extends LitElement {
}
private async putGameConfig() {
const config = await getServerConfigFromClient();
const response = await fetch(
`${window.location.origin}/${getServerConfig().workerPath(this.lobbyId)}/game/${this.lobbyId}`,
`${window.location.origin}/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`,
{
method: "PUT",
headers: {
@@ -609,8 +613,9 @@ export class HostLobbyModal extends LitElement {
`Starting private game with map: ${GameMapType[this.selectedMap]}`,
);
this.close();
const config = await getServerConfigFromClient();
const response = await fetch(
`${window.location.origin}/${getServerConfig().workerPath(this.lobbyId)}/start_game/${this.lobbyId}`,
`${window.location.origin}/${config.workerPath(this.lobbyId)}/start_game/${this.lobbyId}`,
{
method: "POST",
headers: {
@@ -636,15 +641,13 @@ export class HostLobbyModal extends LitElement {
}
private async pollPlayers() {
fetch(
`/${getServerConfig().workerPath(this.lobbyId)}/game/${this.lobbyId}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
const config = await getServerConfigFromClient();
fetch(`/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
)
})
.then((response) => response.json())
.then((data: GameInfo) => {
console.log(`got response: ${data}`);
@@ -654,11 +657,11 @@ export class HostLobbyModal extends LitElement {
}
async function createLobby(): Promise<GameInfo> {
const serverConfig = getServerConfig();
const config = await getServerConfigFromClient();
try {
const id = generateID();
const response = await fetch(
`/${serverConfig.workerPath(id)}/create_game/${id}`,
`/${config.workerPath(id)}/create_game/${id}`,
{
method: "POST",
headers: {
+6 -4
View File
@@ -1,9 +1,9 @@
import { LitElement, css, html } from "lit";
import { customElement, query, state } from "lit/decorators.js";
import { getServerConfig } from "../core/configuration/Config";
import { consolex } from "../core/Consolex";
import { GameMapType, GameType } from "../core/game/Game";
import { GameInfo } from "../core/Schemas";
import { getServerConfigFromClient } from "../core/configuration/Config";
@customElement("join-private-lobby-modal")
export class JoinPrivateLobbyModal extends LitElement {
@@ -355,12 +355,13 @@ export class JoinPrivateLobbyModal extends LitElement {
}
}
private joinLobby() {
private async joinLobby() {
const lobbyId = this.lobbyIdInput.value;
consolex.log(`Joining lobby with ID: ${lobbyId}`);
this.message = "Checking lobby..."; // Set initial message
const url = `/${getServerConfig().workerPath(lobbyId)}/game/${lobbyId}/exists`;
const config = await getServerConfigFromClient();
const url = `/${config.workerPath(lobbyId)}/game/${lobbyId}/exists`;
fetch(url, {
method: "GET",
headers: {
@@ -398,9 +399,10 @@ export class JoinPrivateLobbyModal extends LitElement {
private async pollPlayers() {
if (!this.lobbyIdInput?.value) return;
const config = await getServerConfigFromClient();
fetch(
`/${getServerConfig().workerPath(this.lobbyIdInput.value)}/game/${this.lobbyIdInput.value}`,
`/${config.workerPath(this.lobbyIdInput.value)}/game/${this.lobbyIdInput.value}`,
{
method: "GET",
headers: {
+2 -7
View File
@@ -1,9 +1,4 @@
import {
Config,
GameEnv,
getServerConfig,
ServerConfig,
} from "../core/configuration/Config";
import { Config, GameEnv, ServerConfig } from "../core/configuration/Config";
import { consolex } from "../core/Consolex";
import { GameEvent } from "../core/EventBus";
import {
@@ -130,7 +125,7 @@ export class LocalServer {
const blob = new Blob([JSON.stringify(GameRecordSchema.parse(record))], {
type: "application/json",
});
const workerPath = getServerConfig().workerPath(this.lobbyConfig.gameID);
const workerPath = this.serverConfig.workerPath(this.lobbyConfig.gameID);
navigator.sendBeacon(`/${workerPath}/archive_singleplayer_game`, blob);
}
}
+3
View File
@@ -19,6 +19,7 @@ import "./DarkModeButton";
import { DarkModeButton } from "./DarkModeButton";
import { HelpModal } from "./HelpModal";
import { GameType } from "../core/game/Game";
import { getServerConfigFromClient } from "../core/configuration/Config";
class Client {
private gameStop: () => void;
@@ -135,9 +136,11 @@ class Client {
consolex.log("joining lobby, stopping existing game");
this.gameStop();
}
const config = await getServerConfigFromClient();
const gameType = event.detail.gameType;
this.gameStop = joinLobby(
{
serverConfig: config,
gameType: gameType,
flag: (): string => this.flagInput.getCurrentFlag(),
playerName: (): string => this.usernameInput.getCurrentUsername(),