From 1e4237175de01b2f3f834a41c2998cffc274dc1f Mon Sep 17 00:00:00 2001 From: AnthonyFuller <24512050+AnthonyFuller@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:35:40 +0000 Subject: [PATCH] fix(ingame options): don't load from the static folder at runtime I throughly hate this code and what I had to do. This is a band-aid fix until we figure out something better. I cannot wait for this to be the permanent fix. --- components/menus/settings.ts | 49 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/components/menus/settings.ts b/components/menus/settings.ts index 39965008..263144c2 100644 --- a/components/menus/settings.ts +++ b/components/menus/settings.ts @@ -1,10 +1,18 @@ -import { existsSync, readFileSync } from "fs" -import path from "path" import { IIniObjectSection, IniValue } from "js-ini" import { menuSystemDatabase } from "./menuSystem" import { Flag, FlagSection, GameVersion } from "../types/types" import { defaultFlags, getAllFlags, saveFlags, setFlag } from "../flags" import { CommandFunction, commandService } from "../commandService" +// @ts-expect-error This is fine. +import PeacockMenuIndex from "../../static/peacock-menu/index.json" +// @ts-expect-error This is fine. +import PeacockMenuOptions from "../../static/peacock-menu/options.json" +// @ts-expect-error This is fine. +import PeacockMenuFlagIndex from "../../static/peacock-menu/flags/index.json" +// @ts-expect-error This is fine. +import PeacockMenuFlagCategory from "../../static/peacock-menu/flags/category.json" +// @ts-expect-error This is fine. +import PeacockMenuFlag from "../../static/peacock-menu/flags/flag.json" interface GetAllFlagsResponse { key: string @@ -27,7 +35,18 @@ const commandMap = new Map([ ["setFlagEnum", commandSetFlagEnum as CommandFunction], ]) -const pluginPrefix = "/pages/peacock-menu/" +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const builtInPages: Record = { + "/pages/peacock-menu/index.json": JSON.parse(PeacockMenuIndex), + "/pages/peacock-menu/options.json": JSON.parse(PeacockMenuOptions), + "/pages/peacock-menu/flags/index.json": JSON.parse(PeacockMenuFlagIndex), + "/pages/peacock-menu/flags/category.json": JSON.parse( + PeacockMenuFlagCategory, + ), + "/pages/peacock-menu/flags/flag.json": JSON.parse(PeacockMenuFlag), +} + +const pagePrefix = "/pages/peacock-menu/" const jsonExtension = ".json" function getDatabaseDiff(configs: string[], gameVersion: GameVersion) { @@ -44,29 +63,17 @@ function getConfig(name: string, _gameVersion: GameVersion) { name = "/pages/peacock-menu/index.json" } - if (!name.startsWith(pluginPrefix)) { + if (!name.startsWith(pagePrefix)) { return } - const fileName = name.substring(pluginPrefix.length) - const cacheBusterIndex = fileName.indexOf(jsonExtension) - const fileNameWithCacheBuster = + const cacheBusterIndex = name.indexOf(jsonExtension) + const fileNameNoCacheBuster = cacheBusterIndex < 0 - ? fileName - : fileName.substring(0, cacheBusterIndex + jsonExtension.length) - - const filePath = path.join( - process.cwd(), - "static", - "peacock-menu", - fileNameWithCacheBuster, - ) - - if (existsSync(filePath)) { - return JSON.parse(readFileSync(filePath).toString()) - } + ? name + : name.substring(0, cacheBusterIndex + jsonExtension.length) - return undefined + return builtInPages[fileNameNoCacheBuster] ?? undefined } function getFlagType(