mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:00:42 +00:00
fix: Resolve userSettings is null error in worker
This commit fixes the "userSettings is null" error that occurred in the worker when trying to join or create a game. - Introduced IUserSettings interface to define the contract for user settings used in the worker. - Updated UserSettings class to implement IUserSettings and provide a getData() method for serialization. - Modified WorkerMessages to include serialized user settings in the InitMessage. - Passed user settings from ClientGameRunner to WorkerClient, and then to the worker. - Updated createGameRunner to accept IUserSettings and pass it to getConfig. - Corrected type inconsistencies across various configuration and theme classes to align with IUserSettings. - Re-added missing imports in relevant files.
This commit is contained in:
@@ -162,7 +162,7 @@ async function createClientGame(
|
||||
const worker = new WorkerClient(
|
||||
lobbyConfig.gameStartInfo,
|
||||
lobbyConfig.clientID,
|
||||
userSettings,
|
||||
userSettings.getData(),
|
||||
);
|
||||
await worker.initialize();
|
||||
const gameView = new GameView(
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from "../game/Game";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { ErrorUpdate, GameUpdateViewData } from "../game/GameUpdates";
|
||||
import { UserSettingsData } from "../game/UserSettings";
|
||||
import { ClientID, GameStartInfo, Turn } from "../Schemas";
|
||||
import { generateID } from "../Util";
|
||||
import { WorkerMessage } from "./WorkerMessages";
|
||||
@@ -22,7 +23,7 @@ export class WorkerClient {
|
||||
constructor(
|
||||
private gameStartInfo: GameStartInfo,
|
||||
private clientID: ClientID,
|
||||
private userSettings: UserSettings,
|
||||
private userSettingsData: UserSettingsData,
|
||||
) {
|
||||
this.worker = new Worker(new URL("./Worker.worker.ts", import.meta.url));
|
||||
this.messageHandlers = new Map();
|
||||
@@ -71,7 +72,7 @@ export class WorkerClient {
|
||||
id: messageId,
|
||||
gameStartInfo: this.gameStartInfo,
|
||||
clientID: this.clientID,
|
||||
userSettings: this.userSettings.getData(),
|
||||
userSettings: this.userSettingsData,
|
||||
});
|
||||
|
||||
// Add timeout for initialization
|
||||
|
||||
Reference in New Issue
Block a user