mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 09:45:58 +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:
+20
-2
@@ -14,7 +14,7 @@ import {
|
||||
yellow,
|
||||
} from "../src/core/configuration/Colors";
|
||||
import { ColoredTeams } from "../src/core/game/Game";
|
||||
import { UserSettings } from "../src/core/game/UserSettings";
|
||||
import { IUserSettings } from "../src/core/game/UserSettings";
|
||||
|
||||
const mockColors: Colord[] = [
|
||||
colord({ r: 255, g: 0, b: 0 }),
|
||||
@@ -31,7 +31,7 @@ const fallbackColors = [...fallbackMockColors, ...mockColors];
|
||||
|
||||
const mockUserSettings = {
|
||||
colorblindMode: () => false,
|
||||
} as UserSettings;
|
||||
} as IUserSettings;
|
||||
|
||||
describe("ColorAllocator", () => {
|
||||
let allocator: ColorAllocator;
|
||||
@@ -157,6 +157,24 @@ describe("ColorAllocator", () => {
|
||||
|
||||
expect(redColorPlayerOne.isEqual(redColorPlayerTwo)).toBe(false);
|
||||
});
|
||||
|
||||
test("assignTeamColor returns colorblind-friendly colors when colorblind mode is enabled", () => {
|
||||
const mockUserSettingsColorblind = {
|
||||
colorblindMode: () => true,
|
||||
} as IUserSettings;
|
||||
|
||||
const allocator = new ColorAllocator(
|
||||
mockColors,
|
||||
fallbackMockColors,
|
||||
mockUserSettingsColorblind,
|
||||
);
|
||||
|
||||
const redColor = allocator.assignTeamColor(ColoredTeams.Red);
|
||||
const greenColor = allocator.assignTeamColor(ColoredTeams.Green);
|
||||
|
||||
expect(redColor.toHex()).toBe(colord({ h: 30, s: 100, l: 50 }).toHex()); // Orange
|
||||
expect(greenColor.toHex()).toBe(colord({ h: 210, s: 100, l: 50 }).toHex()); // Blue
|
||||
});
|
||||
});
|
||||
|
||||
describe("selectDistinctColor", () => {
|
||||
|
||||
Reference in New Issue
Block a user