[ROMM-2336] Config entry for EJS_CacheLimit

This commit is contained in:
Georges-Antoine Assi
2025-09-06 19:10:44 -04:00
parent 27189eb44b
commit 06768abb06
11 changed files with 30 additions and 3 deletions

View File

@@ -59,6 +59,7 @@ class Config:
FIRMWARE_FOLDER_NAME: str
HIGH_PRIO_STRUCTURE_PATH: str
EJS_DEBUG: bool
EJS_CACHE_LIMIT: int | None
EJS_SETTINGS: dict[str, EjsOption] # core_name -> EjsOption
EJS_CONTROLS: dict[str, EjsControls] # core_name -> EjsControls
@@ -169,6 +170,9 @@ class ConfigManager:
self._raw_config, "filesystem.firmware_folder", "bios"
),
EJS_DEBUG=pydash.get(self._raw_config, "emulatorjs.debug", False),
EJS_CACHE_LIMIT=pydash.get(
self._raw_config, "emulatorjs.cache_limit", None
),
EJS_SETTINGS=pydash.get(self._raw_config, "emulatorjs.settings", {}),
EJS_CONTROLS=self._get_ejs_controls(),
)
@@ -273,6 +277,14 @@ class ConfigManager:
log.critical("Invalid config.yml: emulatorjs.debug must be a boolean")
sys.exit(3)
if self.config.EJS_CACHE_LIMIT is not None and not isinstance(
self.config.EJS_CACHE_LIMIT, int
):
log.critical(
"Invalid config.yml: emulatorjs.cache_limit must be an integer"
)
sys.exit(3)
if not isinstance(self.config.EJS_SETTINGS, dict):
log.critical("Invalid config.yml: emulatorjs.settings must be a dictionary")
sys.exit(3)

View File

@@ -37,6 +37,7 @@ def get_config() -> ConfigResponse:
PLATFORMS_BINDING=cfg.PLATFORMS_BINDING,
PLATFORMS_VERSIONS=cfg.PLATFORMS_VERSIONS,
EJS_DEBUG=cfg.EJS_DEBUG,
EJS_CACHE_LIMIT=cfg.EJS_CACHE_LIMIT,
EJS_CONTROLS=cfg.EJS_CONTROLS,
EJS_SETTINGS=cfg.EJS_SETTINGS,
)

View File

@@ -13,5 +13,6 @@ class ConfigResponse(TypedDict):
PLATFORMS_BINDING: dict[str, str]
PLATFORMS_VERSIONS: dict[str, str]
EJS_DEBUG: bool
EJS_CACHE_LIMIT: int | None
EJS_SETTINGS: dict[str, dict[str, str]]
EJS_CONTROLS: dict[str, EjsControls]

View File

@@ -32,6 +32,7 @@ filesystem:
emulatorjs:
debug: true
cache_limit: 1000
settings:
parallel_n64:
vsync: disable

View File

@@ -20,6 +20,7 @@ def test_config_loader():
assert loader.config.ROMS_FOLDER_NAME == "ROMS"
assert loader.config.FIRMWARE_FOLDER_NAME == "BIOS"
assert loader.config.EJS_DEBUG
assert loader.config.EJS_CACHE_LIMIT == 1000
assert loader.config.EJS_SETTINGS == {
"parallel_n64": {"vsync": "disable"},
"snes9x": {"snes9x_region": "ntsc"},
@@ -52,5 +53,6 @@ def test_empty_config_loader():
assert loader.config.ROMS_FOLDER_NAME == "roms"
assert loader.config.FIRMWARE_FOLDER_NAME == "bios"
assert not loader.config.EJS_DEBUG
assert not loader.config.EJS_CACHE_LIMIT
assert loader.config.EJS_SETTINGS == {}
assert loader.config.EJS_CONTROLS == {}

View File

@@ -50,6 +50,7 @@ filesystem: {} # { roms_folder: 'roms' } For example if your folder structure is
# EmulatorJS per-core options
emulatorjs:
# debug: true # Available options will be logged to the browser console
# cache_limit: 100000000 # Cache limit per ROM (in bytes)
settings:
parallel_n64: # Use the exact core name
# vsync: disable

View File

@@ -13,6 +13,7 @@ export type ConfigResponse = {
PLATFORMS_BINDING: Record<string, string>;
PLATFORMS_VERSIONS: Record<string, string>;
EJS_DEBUG: boolean;
EJS_CACHE_LIMIT: (number | null);
EJS_SETTINGS: Record<string, Record<string, string>>;
EJS_CONTROLS: Record<string, EjsControls>;
};

View File

@@ -55,7 +55,7 @@ function enterConsoleMode() {
class="text-caption text-center"
:class="{ 'text-primary': route.path.startsWith('/console') }"
>
Play
Console
</span>
</v-expand-transition>
</div>

View File

@@ -420,7 +420,10 @@ async function boot() {
if (ejsControls) window.EJS_defaultControls = ejsControls;
window.EJS_language = selectedLanguage.value.value.replace("_", "-");
window.EJS_disableAutoLang = true;
window.EJS_DEBUG_XX = configStore.config.EJS_DEBUG;
const { EJS_DEBUG, EJS_CACHE_LIMIT } = configStore.config;
if (EJS_CACHE_LIMIT) window.EJS_CacheLimit = EJS_CACHE_LIMIT;
window.EJS_DEBUG_XX = EJS_DEBUG;
// Set a valid game name (affects per-game settings keys)
window.EJS_gameName = rom.fs_name_no_tags

View File

@@ -21,6 +21,7 @@ const defaultConfig = {
PLATFORMS_BINDING: {},
PLATFORMS_VERSIONS: {},
EJS_DEBUG: false,
EJS_CACHE_LIMIT: 1073741824,
EJS_SETTINGS: {},
EJS_CONTROLS: {},
} as ConfigResponse;

View File

@@ -80,6 +80,7 @@ declare global {
EJS_language: string;
EJS_disableAutoLang: boolean;
EJS_DEBUG_XX: boolean;
EJS_CacheLimit: number;
EJS_Buttons: Record<string, boolean>;
EJS_VirtualGamepadSettings: {};
EJS_onGameStart: () => void;
@@ -136,7 +137,10 @@ window.EJS_gameName = romRef.value.fs_name_no_tags
.trim();
window.EJS_language = selectedLanguage.value.value.replace("_", "-");
window.EJS_disableAutoLang = true;
window.EJS_DEBUG_XX = configStore.config.EJS_DEBUG;
const { EJS_DEBUG, EJS_CACHE_LIMIT } = configStore.config;
if (EJS_CACHE_LIMIT) window.EJS_CacheLimit = EJS_CACHE_LIMIT;
window.EJS_DEBUG_XX = EJS_DEBUG;
onMounted(() => {
window.scrollTo(0, 0);