Engine: the registry JSON carries sub headings, and --set KEY=VALUE overrides any setting for one run

This commit is contained in:
alex committed 2026-11-26 04:07:18 +00:00
1 parent 7b3c42aa6d
commit 112d163114
3 files changed
+87

No files matched your search

+24
View File
@@ -94,6 +94,29 @@ def valid_hz(value: Any) -> bool:
return isinstance(value, int) and not isinstance(value, bool) and HZ_MIN <= value <= HZ_MAX and value % 30 == 0
def parse_set(text: str) -> tuple[str, Any]:
""" "KEY=VALUE" from `run.py --set` (Summit's per-game profile): any setting of the registry by its key, with the
value as JSON (true, 90, 0.5, "fsr"; a bare word is taken as a string). Raises ValueError with the reason when the
key is unknown or the value is not one the setting accepts."""
key, sep, raw = text.partition("=")
key = key.strip()
if not sep or key not in BY_KEY:
raise ValueError(f"{text!r}: KEY=VALUE with a setting's key (python -m framegen.settings lists them)")
spec = BY_KEY[key]
try:
tries = [json.loads(raw), raw.strip()]
except ValueError:
tries = [raw.strip()]
for value in tries:
if isinstance(value, bool) != isinstance(spec.default, bool): # JSON true is not the number 1 here
continue
if isinstance(value, int) and isinstance(spec.default, float):
value = float(value)
if spec.accepts(value):
return key, value
raise ValueError(f"{key}: {raw.strip()!r} is not one of {spec.choices}")
ON_OFF = {True: "On", False: "Off"}
OPACITY = (1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3) # menu and stats opacity choices
PCT = {v: f"{round(v * 100)}%" for v in OPACITY}
@@ -564,6 +587,7 @@ def specs_json(specs: tuple[Spec, ...] = SPECS) -> dict:
"path": str(DEFAULT_PATH),
"impact_pc": IMPACT_PC,
"specs": [{"key": s.key, "label": s.label, "group": s.group, "help": s.help, "default": s.default,
"sub": s.sub,
"live": s.live, "saved": s.saved, "later": s.later, "quick": s.quick, "impact": s.impact,
"experimental": s.experimental,
"sources": list(s.sources) or None,
+9
View File
@@ -319,6 +319,9 @@ def main() -> int:
ap.add_argument("--settings", default=str(DEFAULT_PATH), metavar="JSON",
help="settings file the menu loads and saves (default %(default)s); 'none' = defaults, unsaved")
# These override the saved settings for this run (not saved); the menu can change them live.
ap.add_argument("--set", dest="set_values", action="append", default=[], metavar="KEY=VALUE",
help="any setting by its key, for this run only (repeatable): --set overlay_style=graphs. "
"Summit passes a game's own settings this way; they win over the flags above")
ap.add_argument("--vsync", action=argparse.BooleanOptionalAction, default=None,
help="vsync the window (use with G-Sync/FreeSync displays)")
ap.add_argument("--fullscreen", action=argparse.BooleanOptionalAction, default=None, help="start fullscreen")
@@ -475,6 +478,12 @@ def main() -> int:
test_model = a.model if a.model is not None and a.model not in BY_KEY["model"].choices else None
if a.model is not None and test_model is None:
settings.override("model", a.model)
for text in a.set_values: # --set KEY=VALUE: this run only; one that can't be used is said and left out
from framegen.settings import parse_set
try:
settings.override(*parse_set(text))
except ValueError as e:
print(f"[settings] --set ignored: {e}")
if test is not None: # the menu's "Simulate a 30 fps game" switches test mode live
settings.watch(lambda key: test.set_on(settings.simulate_30) if key == "simulate_30" else None)
if settings.hz > 60 and (a.out or not a.display):
+54
View File
@@ -0,0 +1,54 @@
"""The registry as the launcher reads it (python -m framegen.settings) and `run.py --set KEY=VALUE`."""
import json
import pytest
from framegen import settings as S
def test_specs_json_is_plain_json_with_what_the_launcher_draws():
reg = json.loads(json.dumps(S.specs_json()))
assert reg["path"].endswith("settings.json")
keys = [s["key"] for s in reg["specs"]]
assert keys == [s.key for s in S.SPECS] and len(set(keys)) == len(keys)
for s in reg["specs"]:
for field in ("label", "group", "sub", "help", "default", "live", "saved", "quick", "impact", "experimental",
"applies", "sources", "choices"):
assert field in s, (s["key"], field)
assert s["group"], s["key"] # every setting has a section
values = [c["value"] for c in s["choices"]]
assert s["default"] in values, s["key"]
if s["applies"]: # what it depends on is a setting, and the values are that setting's
dep = S.BY_KEY[s["applies"]["key"]]
assert all(dep.accepts(v) for v in s["applies"]["values"]), s["key"]
def test_sub_headings_follow_the_layout():
by = {s["key"]: s for s in S.specs_json()["specs"]}
assert (by["hz"]["group"], by["hz"]["sub"]) == ("Frame generation", "Basics")
assert (by["output_res"]["group"], by["output_res"]["sub"]) == ("Upscaling", "Output")
@pytest.mark.parametrize("text,want", [
("interp=false", ("interp", False)), ("hz=90", ("hz", 90)), ("hz=210", ("hz", 210)),
("scaler=vsr", ("scaler", "vsr")), ('scaler="fsr"', ("scaler", "fsr")), ("fsr_sharpness=1", ("fsr_sharpness", 1.0)),
("overlay_scale=1.25", ("overlay_scale", 1.25)), ("output_res=2560x1080", ("output_res", "2560x1080")),
("game_fps=60", ("game_fps", "60")), ('game_fps="60"', ("game_fps", "60")),
("overlay_style=graphs", ("overlay_style", "graphs")), ("replay=0", ("replay", 0)),
])
def test_parse_set_takes_json_values_and_bare_words(text, want):
assert S.parse_set(text) == want
assert type(S.parse_set(text)[1]) is type(want[1])
@pytest.mark.parametrize("text", ["nonsense=1", "hz", "hz=45", "interp=1", "vsr_quality=true", "scaler=dlss", "=1",
"fill=[1]"])
def test_parse_set_refuses_what_the_setting_does_not_accept(text):
with pytest.raises(ValueError):
S.parse_set(text)
def test_every_choice_of_every_setting_goes_through_parse_set():
for spec in S.SPECS:
for v in spec.choices:
assert S.parse_set(f"{spec.key}={json.dumps(v)}") == (spec.key, v)