mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:58:37 +00:00
d3d12: a typed switch wins over the F1 menu, not a value that changed (D3D12-MENU-LAST-CHOICE-WINS)
Review of the first version: a value that differs from the last start's command line was taken for the user's new choice. That lost an explicit flag on the first start after an upgrade, never let the same flag typed again win, and dropped a menu value the command line never mentioned when leonida-launch.txt lacked the key. The menu file was also rewritten before the history, so a failed history write had already lost a saved choice. Now the rule follows what the user typed: - A switch typed for this start wins over the menu's saved value of each setting it makes. The menu file drops that value, so F1 shows the command line's. scripts\play-d3d12.ps1 passes the switches typed there as -Typed, so its Series X default and -Lowest 1080 leave the menu's choice standing. A start by hand counts its own switches, and -More wins like a typed switch. - Every other setting keeps the menu's value. - The menu's SAVE AND RESTART adds -MenuRestart to the switches it replays (LEONIDA_MENU_ARGS), so there the menu's values, saved after those switches, win. leonida-launch.txt is gone. The menu file is written to a temporary file and moved over the old one, and only when a value leaves it. If that fails, the start runs with the command line's values and the file stays whole. Tests: 10 cases, among them the same switch typed again, an untyped default, a setting no switch makes, the restart, a start by hand, -More and a menu file that cannot be written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1
d3d12/.gitignore
vendored
1
d3d12/.gitignore
vendored
@ -82,4 +82,3 @@ Thumbs.db
|
||||
/nvidia-sdk/
|
||||
# What the F1 menu saved
|
||||
/leonida-settings.txt
|
||||
/leonida-launch.txt
|
||||
|
||||
@ -331,10 +331,13 @@ still reaches.
|
||||
speed switches. Lines marked LIVE change at once; the others are saved to
|
||||
`leonida-settings.txt` and apply at the next start, which "SAVE AND RESTART
|
||||
NOW" does for you. F3 shows the numbers panel. The last choice wins, one
|
||||
setting at a time: a setting you change on the command line after saving it
|
||||
in the menu takes the command line's value, the menu file drops its own, and
|
||||
the menu shows the new one; settings the command line leaves as they were
|
||||
keep the menu's. Each start says which came from the menu.
|
||||
setting at a time: a switch you type (`-Resolution`, `-SeriesS`,
|
||||
`-Fullscreen` ...) wins over what the menu saved for the same setting, the
|
||||
menu file drops that value, and the menu shows the command line's; every
|
||||
setting you did not type keeps the menu's. "SAVE AND RESTART NOW" keeps the
|
||||
menu's values, since they were chosen after the switches it starts with
|
||||
again. Each start says which values came from the menu and which the command
|
||||
line replaced.
|
||||
- **DLSS frame generation** (NVIDIA Streamline), 2x to 6x, from the menu. The
|
||||
amount changes while playing. Frames are only generated while the game's
|
||||
window has the focus.
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
# nvidia-sdk\. Without them the game runs with its picture stretched to the screen instead.
|
||||
# The layer is built here if it is not built yet, and built again with DLSS once those files are there.
|
||||
# In the game: F1 = settings (arrows pick and change, Enter saves; kept in leonida-settings.txt next to this
|
||||
# folder), F3 = the numbers panel. The last choice wins, one setting at a time: a setting this command line changes
|
||||
# since the last start wins over the menu's saved one (leonida-launch.txt keeps the last start's), the others keep it.
|
||||
# folder), F3 = the numbers panel. The last choice wins, one setting at a time: a switch typed for a start wins over
|
||||
# the menu's saved value of what it sets (and the menu file drops that value); every other setting keeps the menu's.
|
||||
# -NoSmoothMotion run target\<build>\leonida.exe itself. By default a copy named leonida_sm.exe is started instead,
|
||||
# so a Smooth Motion profile set for that exe in the NVIDIA App applies every time.
|
||||
# -NoDlss no DLSS: the picture is stretched (fast, softer)
|
||||
@ -90,7 +90,12 @@ param(
|
||||
[hashtable]$More = @{},
|
||||
[string]$PcGlyphs,
|
||||
[uint32]$WindowsBarMB,
|
||||
[switch]$DryRun
|
||||
[switch]$DryRun,
|
||||
# The switches the user typed, by this script's names, when another script starts this one with switches of its
|
||||
# own (scripts\play-d3d12.ps1's Series X default): they win over the F1 menu's saved values. Unset: this start's.
|
||||
[string[]]$Typed,
|
||||
# Set by the F1 menu's SAVE AND RESTART: the switches are the last start's again, so the menu's values win.
|
||||
[switch]$MenuRestart
|
||||
)
|
||||
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
if (-not (Test-Path $Exe)) { Write-Host "No $Exe."; return }
|
||||
@ -508,12 +513,13 @@ if ($PSBoundParameters.ContainsKey('WindowsBarMB')) {
|
||||
}
|
||||
}
|
||||
|
||||
# What the F1 menu saved (leonida-settings.txt, git-ignored) and the settings above: the user's last choice wins, one
|
||||
# setting at a time. leonida-launch.txt (git-ignored, beside it) keeps what the last start's command line made. A
|
||||
# setting this command line makes otherwise than that start's did was chosen now: it wins, and the menu file drops its
|
||||
# value, so F1 shows and saves this one. A setting the command line makes as before keeps the menu's value, the newer
|
||||
# choice. With no leonida-launch.txt yet (the first start with this launcher) the menu's values win, as before. An
|
||||
# empty value unsets a setting. -More still wins over both.
|
||||
# What the F1 menu saved (leonida-settings.txt, git-ignored) and the command line: the user's last choice wins, one
|
||||
# setting at a time. A setting a switch typed for this start makes (-Resolution, -SeriesS, -Fullscreen ...: $Typed,
|
||||
# which scripts\play-d3d12.ps1 passes, else this start's own switches) was chosen now: it wins over the menu's, and
|
||||
# the menu file drops that value, so F1 shows and saves the command line's. Every other setting keeps the menu's, which
|
||||
# was chosen after the defaults. A start that the menu's SAVE AND RESTART made (-MenuRestart) replays the switches of
|
||||
# the start before, so there the menu's values win: they were chosen after them. An empty value unsets a setting.
|
||||
# -More wins over the menu like a typed switch.
|
||||
function Read-SettingsFile([string]$path) {
|
||||
$read = [ordered]@{}
|
||||
if (Test-Path $path) {
|
||||
@ -523,25 +529,47 @@ function Read-SettingsFile([string]$path) {
|
||||
}
|
||||
$read
|
||||
}
|
||||
function Write-SettingsFile([string]$path, [string]$header, $values) {
|
||||
# CRLF, as the menu writes the file (host/menu.rs).
|
||||
$text = "# $header`r`n" + (($values.Keys | ForEach-Object { "$_=$($values[$_])`r`n" }) -join '')
|
||||
[IO.File]::WriteAllText($path, $text, [Text.UTF8Encoding]::new($false))
|
||||
# The settings each switch makes; a switch not listed makes none the menu holds.
|
||||
$switchSettings = @{
|
||||
SeriesX = 'LEONIDA_MENU_CONSOLE'
|
||||
NoSmoothMotion = 'LEONIDA_MENU_SMOOTH_MOTION'
|
||||
Resolution = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_UPSCALE', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT'
|
||||
Lowest = 'LEONIDA_RENDER_SCALE', 'LEONIDA_RENDER_SCALE_MIN', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_UPSCALE', 'LEONIDA_FSR_UPSCALER', 'LEONIDA_OUTPUT'
|
||||
Dlss = 'LEONIDA_RENDER_SCALE', 'LEONIDA_UPSCALE', 'LEONIDA_OWN_UPSCALER', 'LEONIDA_FSR_UPSCALER'
|
||||
NoDlss = 'LEONIDA_UPSCALE'
|
||||
FrameGen = 'LEONIDA_FRAME_GEN'
|
||||
NoFrameGen = 'LEONIDA_FRAME_GEN'
|
||||
FsrFrameGen = 'LEONIDA_FSR_FRAMEGEN'
|
||||
Fullscreen = 'LEONIDA_FULLSCREEN'
|
||||
Aspect = 'LEONIDA_ASPECT'
|
||||
PresentScale = 'LEONIDA_PRESENT_SCALE'
|
||||
Adapter = 'LEONIDA_ADAPTER'
|
||||
RayTracing = 'LEONIDA_BVH_BUILDER', 'LEONIDA_AMBIENT'
|
||||
Quality = 'LEONIDA_RELAY', 'LEONIDA_CARD_STEPS'
|
||||
}
|
||||
$typedNames = if ($PSBoundParameters.ContainsKey('Typed')) { @($Typed) } else { @($PSBoundParameters.Keys) }
|
||||
$chosenNow = @{}
|
||||
if (-not $MenuRestart) {
|
||||
foreach ($name in $typedNames) {
|
||||
# -SeriesS reaches this script as the console's switch, SeriesX.
|
||||
$said = if ($name -eq 'SeriesX') { '-SeriesS/-SeriesX' } else { "-$name" }
|
||||
foreach ($k in @($switchSettings[$name])) { if ($k) { $chosenNow[$k] = $said } }
|
||||
}
|
||||
foreach ($k in $More.Keys) { $chosenNow[$k] = '-More' }
|
||||
}
|
||||
$menuFile = Join-Path $root 'leonida-settings.txt'
|
||||
$lastFile = Join-Path $root 'leonida-launch.txt'
|
||||
$smooth = -not $NoSmoothMotion
|
||||
# The menu's console and Smooth Motion lines stand for $console and $smooth here.
|
||||
$fromLine = @{} + $settings
|
||||
$fromLine.LEONIDA_MENU_CONSOLE = $console
|
||||
$fromLine.LEONIDA_MENU_SMOOTH_MOTION = if ($smooth) { '1' } else { '0' }
|
||||
$menu = Read-SettingsFile $menuFile
|
||||
$last = if (Test-Path $lastFile) { Read-SettingsFile $lastFile } else { $null }
|
||||
$fromMenu = @(); $replaced = @()
|
||||
foreach ($k in @($menu.Keys)) {
|
||||
$v = $menu[$k]; $now = "$($fromLine[$k])"
|
||||
if ($null -ne $last -and "$($last[$k])" -ne $now) {
|
||||
$replaced += "$k $(if ($v) { $v } else { '(unset)' }) -> $(if ($now) { $now } else { '(unset)' })"
|
||||
$v = $menu[$k]
|
||||
if ($chosenNow.ContainsKey($k)) {
|
||||
$now = "$($fromLine[$k])"
|
||||
if ($now -ne $v) { $replaced += "$k $(if ($v) { $v } else { '(unset)' }) -> $(if ($now) { $now } else { '(unset)' }) ($($chosenNow[$k]))" }
|
||||
$menu.Remove($k)
|
||||
continue
|
||||
}
|
||||
@ -550,13 +578,22 @@ foreach ($k in @($menu.Keys)) {
|
||||
if ($k -eq 'LEONIDA_MENU_CONSOLE') { if ($v) { $console = $v }; continue }
|
||||
if ($v) { $settings[$k] = $v } else { $settings.Remove($k) }
|
||||
}
|
||||
if ($fromMenu) { Write-Host "F1 menu settings (leonida-settings.txt, newer than the command line): $($fromMenu -join ', ')" }
|
||||
if ($replaced) { Write-Host "Command line over the F1 menu's (changed since the last start): $($replaced -join ', ')" }
|
||||
if (-not $DryRun) {
|
||||
if ($replaced) { Write-SettingsFile $menuFile 'Saved by the F1 menu; play.ps1 applies these after its own settings (an empty value: unset).' $menu }
|
||||
$lines = [ordered]@{}
|
||||
foreach ($k in $fromLine.Keys | Sort-Object) { $lines[$k] = $fromLine[$k] }
|
||||
Write-SettingsFile $lastFile 'What the last start''s command line made (play-nvidia.ps1): a setting it makes otherwise next time wins over the F1 menu''s.' $lines
|
||||
if ($fromMenu) { Write-Host "F1 menu settings (leonida-settings.txt, for what the command line did not set): $($fromMenu -join ', ')" }
|
||||
if ($replaced) { Write-Host "Command line over the F1 menu's saved values: $($replaced -join ', ')" }
|
||||
# The menu file keeps the rest as it was; a value the command line set leaves it. If the file cannot be written, this
|
||||
# start still runs with the command line's values and the file stays whole, so nothing saved is lost.
|
||||
if (-not $DryRun -and $menu.Count -ne (Read-SettingsFile $menuFile).Count) {
|
||||
try {
|
||||
# CRLF, as the menu writes the file (host/menu.rs).
|
||||
$text = "# Saved by the F1 menu; play.ps1 applies these after its own settings (an empty value: unset).`r`n" +
|
||||
(($menu.Keys | ForEach-Object { "$_=$($menu[$_])`r`n" }) -join '')
|
||||
$tmp = "$menuFile.tmp"
|
||||
[IO.File]::WriteAllText($tmp, $text, [Text.UTF8Encoding]::new($false))
|
||||
Move-Item -LiteralPath $tmp -Destination $menuFile -Force -ErrorAction Stop
|
||||
} catch {
|
||||
Remove-Item -LiteralPath "$menuFile.tmp" -ErrorAction SilentlyContinue
|
||||
Write-Host "The F1 menu file was not updated ($($_.Exception.Message)): this start runs with the command line's values, and the file keeps the menu's."
|
||||
}
|
||||
}
|
||||
# Leonida: the runs write down the pipelines the title creates (pipeline/known.rs), for the precompile below.
|
||||
if (-not $NoPrecompile) { $settings.LEONIDA_PIPELINE_BOOK = '1' }
|
||||
@ -637,6 +674,10 @@ foreach ($s in 'Resolution', 'Lowest', 'Dlss', 'FrameGen', 'Aspect', 'PresentSca
|
||||
if ($PSBoundParameters[$s]) { $again += "-$s '$($PSBoundParameters[$s] -replace "'", "''")'" }
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('WindowsBarMB')) { $again += "-WindowsBarMB $WindowsBarMB" }
|
||||
# The menu's SAVE AND RESTART starts this script again with these switches, the ones this start was given (not the
|
||||
# settings they made), and -MenuRestart: the menu's values, saved after these switches were typed, win over them there
|
||||
# (see "What the F1 menu saved" above). Without it a typed -Resolution would undo the scale the menu had just saved.
|
||||
$again += '-MenuRestart'
|
||||
$settings.LEONIDA_MENU_ARGS = $again -join ' '
|
||||
|
||||
$scaled = if ($settings.LEONIDA_RENDER_SCALE) { " from render scale $($settings.LEONIDA_RENDER_SCALE)" } else { '' }
|
||||
|
||||
@ -119,9 +119,10 @@ The cap, the sharpness, the panel and the recorder are the renderer's own settin
|
||||
(`knobs::Owned`). The first three are in the F1 menu too: the two menus change the same thing, and each shows what
|
||||
the other set (the F1 menu reads its live settings again when it opens; the trainer looks twice a second while
|
||||
open). The F1 menu saves to `leonida-settings.txt`; what the trainer changes lasts for the run unless the F1 menu
|
||||
is opened afterwards and saves it. At the next start the launcher applies the saved settings, except one the command
|
||||
line changed since the start before (`leonida-launch.txt` keeps what that start's command line made): that one takes
|
||||
the command line's value and leaves the menu file, so the last choice wins either way.
|
||||
is opened afterwards and saves it. At the next start the launcher applies the saved settings, except those a switch
|
||||
typed for that start sets (`-Resolution`, `-SeriesS` ...): those take the command line's value and leave the menu
|
||||
file, so the last choice wins either way. The menu's SAVE AND RESTART passes `-MenuRestart` with the switches it
|
||||
replays, and there the menu's values win.
|
||||
|
||||
Game speed is experimental and not verified in game: the runtime serves the title's `QueryPerformanceCounter`
|
||||
import (from `api-ms-win-core-profile-l1-1-0.dll`) and scales it continuously, so the title's time never jumps.
|
||||
|
||||
@ -112,4 +112,9 @@ if ($Resolution) { $launch.Resolution = $Resolution }
|
||||
if ($Lowest) { $launch.Lowest = $Lowest }
|
||||
if ($Adapter) { $launch.Adapter = $Adapter }
|
||||
if ($PcGlyphs) { $launch.PcGlyphs = (Resolve-Path $PcGlyphs).Path }
|
||||
# The switches typed here, by play-nvidia.ps1's names: those win over the F1 menu's saved values, while the Series X
|
||||
# default and its -Lowest 1080 above, which nobody typed, leave the menu's choice standing.
|
||||
$launch.Typed = @($PSBoundParameters.Keys | ForEach-Object {
|
||||
switch ($_) { 'SeriesS' { 'SeriesX' } 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
|
||||
})
|
||||
& (Join-Path $runtime "scripts\play-nvidia.ps1") @launch
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
"""d3d12/scripts/play-nvidia.ps1: the F1 menu's saved settings and the command line, the user's last choice winning
|
||||
one setting at a time (D3D12-MENU-LAST-CHOICE-WINS). The launcher's block is run alone in Windows PowerShell with
|
||||
the settings a command line made, against a menu file and a last-start file in a temporary folder."""
|
||||
one setting at a time (D3D12-MENU-LAST-CHOICE-WINS): a typed switch wins over the menu's value of what it sets, the
|
||||
menu file drops that value, every other setting keeps the menu's, and the menu's SAVE AND RESTART (-MenuRestart)
|
||||
keeps the menu's. The launcher's block is run alone in Windows PowerShell with the settings a command line made,
|
||||
against a menu file in a temporary folder."""
|
||||
|
||||
import json
|
||||
import os
|
||||
@ -25,19 +27,23 @@ class MenuChoiceTests(unittest.TestCase):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self.tmp.name)
|
||||
self.menu = self.root / "leonida-settings.txt"
|
||||
self.last = self.root / "leonida-launch.txt"
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def start(self, line: dict, console: str = "series-s", dry: bool = False) -> dict:
|
||||
"""One start: `line` is what the command line made; returns what the start runs with."""
|
||||
pairs = "; ".join(f"'{k}' = '{v}'" for k, v in line.items())
|
||||
def start(self, made: dict, typed=None, console="series-s", more=None, restart=False, dry=False,
|
||||
direct=None) -> dict:
|
||||
"""One start: `made` is what the command line made, `typed` the switches typed (play-d3d12.ps1's -Typed),
|
||||
`direct` the switches given when play-nvidia.ps1 is started by hand (no -Typed)."""
|
||||
pairs = "; ".join(f"'{k}' = '{v}'" for k, v in made.items())
|
||||
more_pairs = "; ".join(f"'{k}' = '{v}'" for k, v in (more or {}).items())
|
||||
driver = self.root / "driver.ps1"
|
||||
driver.write_text(
|
||||
"param([string[]]$Typed, [switch]$MenuRestart, [string]$Resolution, [switch]$Fullscreen)\n"
|
||||
"$ErrorActionPreference = 'Stop'\n"
|
||||
f"$root = '{self.root}'\n"
|
||||
f"$settings = @{{ {pairs} }}\n"
|
||||
f"$More = @{{ {more_pairs} }}\n"
|
||||
f"$console = '{console}'\n"
|
||||
"$NoSmoothMotion = $true\n"
|
||||
f"$DryRun = ${'true' if dry else 'false'}\n"
|
||||
@ -45,8 +51,15 @@ class MenuChoiceTests(unittest.TestCase):
|
||||
+ "\n[pscustomobject]@{ settings = $settings; console = $console; smooth = $smooth } | ConvertTo-Json -Compress\n",
|
||||
encoding="utf-8-sig",
|
||||
)
|
||||
args = []
|
||||
if typed is not None:
|
||||
args += ["-Typed", ",".join(typed) if typed else "''"]
|
||||
if restart:
|
||||
args.append("-MenuRestart")
|
||||
args += direct or []
|
||||
command = f"& '{driver}' {' '.join(args)}"
|
||||
res = subprocess.run(
|
||||
["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(driver)],
|
||||
["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", command],
|
||||
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60,
|
||||
)
|
||||
self.assertEqual(res.returncode, 0, res.stderr)
|
||||
@ -55,69 +68,84 @@ class MenuChoiceTests(unittest.TestCase):
|
||||
ran["said"] = "\n".join(out[:-1])
|
||||
return ran
|
||||
|
||||
def saved(self, path: Path) -> dict:
|
||||
lines = path.read_text(encoding="utf-8").splitlines() if path.exists() else []
|
||||
def saved(self) -> dict:
|
||||
lines = self.menu.read_text(encoding="utf-8").splitlines() if self.menu.exists() else []
|
||||
return dict(l.split("=", 1) for l in lines if l.startswith("LEONIDA_"))
|
||||
|
||||
def test_the_first_start_keeps_the_menu_values_and_notes_the_command_line(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1"})
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6")
|
||||
self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1")
|
||||
self.assertIn("F1 menu settings", ran["said"])
|
||||
|
||||
def test_a_menu_choice_after_the_same_command_line_wins(self):
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1"})
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1"})
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6")
|
||||
self.assertEqual(self.saved(self.menu), {"LEONIDA_RENDER_SCALE": "0.6"})
|
||||
|
||||
def test_a_command_line_changed_after_the_menu_wins_and_the_menu_file_follows(self):
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1"})
|
||||
def test_a_typed_switch_wins_over_the_menu_and_the_menu_file_follows(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FPS_LINE=0\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"})
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5")
|
||||
self.assertEqual(ran["settings"]["LEONIDA_FPS_LINE"], "0", "a setting the command line left alone keeps F1's")
|
||||
self.assertEqual(self.saved(self.menu), {"LEONIDA_FPS_LINE": "0"})
|
||||
self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> 0.5", ran["said"])
|
||||
# And the start after it, with the same command line, has nothing left to replace.
|
||||
again = self.start({"LEONIDA_RENDER_SCALE": "0.5"})
|
||||
self.assertEqual(again["settings"]["LEONIDA_RENDER_SCALE"], "0.5")
|
||||
self.assertNotIn("Command line over", again["said"])
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_OWN_UPSCALER": "1"}, typed=["Resolution"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1")
|
||||
self.assertEqual(ran["settings"]["LEONIDA_FPS_LINE"], "0", "a setting no switch made keeps F1's")
|
||||
self.assertEqual(self.saved(), {"LEONIDA_FPS_LINE": "0"})
|
||||
self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> 1 (-Resolution)", ran["said"])
|
||||
|
||||
def test_a_setting_the_command_line_drops_wins_over_the_menu_value(self):
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_OWN_UPSCALER": "1"})
|
||||
def test_the_same_switch_typed_again_after_a_menu_save_wins_again(self):
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"])
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_UPSCALE": "dlss"})
|
||||
self.assertNotIn("LEONIDA_RENDER_SCALE", ran["settings"])
|
||||
self.assertIn("LEONIDA_RENDER_SCALE 0.6 -> (unset)", ran["said"])
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1")
|
||||
self.assertEqual(self.saved(), {})
|
||||
|
||||
def test_the_console_follows_the_last_choice(self):
|
||||
self.start({}, console="series-s")
|
||||
def test_a_default_nobody_typed_keeps_the_menu_value(self):
|
||||
# play-d3d12.ps1's Series X default with its -Lowest 1080: nothing typed.
|
||||
self.menu.write_text("LEONIDA_MENU_CONSOLE=series-s\r\nLEONIDA_RENDER_SCALE_MIN=0.6667\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE_MIN": "0.75"}, typed=[], console="series-x")
|
||||
self.assertEqual(ran["console"], "series-s")
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE_MIN"], "0.6667")
|
||||
self.assertIn("F1 menu settings", ran["said"])
|
||||
# -SeriesS typed (passed on as SeriesX, the console's switch) wins over a menu's Series X.
|
||||
self.menu.write_text("LEONIDA_MENU_CONSOLE=series-x\r\n", encoding="utf-8")
|
||||
self.assertEqual(self.start({}, console="series-s")["console"], "series-x", "F1 chose after that command line")
|
||||
ran = self.start({}, console="series-x")
|
||||
self.assertEqual(ran["console"], "series-x")
|
||||
ran = self.start({}, console="series-s")
|
||||
self.assertEqual(ran["console"], "series-s", "-SeriesS given after F1's choice")
|
||||
self.assertNotIn("LEONIDA_MENU_CONSOLE", self.saved(self.menu))
|
||||
self.assertEqual(self.start({}, typed=["SeriesX"], console="series-s")["console"], "series-s")
|
||||
self.assertEqual(self.saved(), {})
|
||||
|
||||
def test_a_setting_no_switch_makes_is_never_taken_from_the_menu(self):
|
||||
self.menu.write_text("LEONIDA_CARD_AWAKE=1\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_CARD_AWAKE": "0", "LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution", "Log"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_CARD_AWAKE"], "1")
|
||||
self.assertEqual(self.saved(), {"LEONIDA_CARD_AWAKE": "1"})
|
||||
self.assertNotIn("Command line over", ran["said"])
|
||||
|
||||
def test_the_menus_restart_keeps_the_values_it_saved(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8")
|
||||
before = self.menu.read_bytes()
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, restart=True, direct=["-Resolution", "1080"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.6")
|
||||
self.assertEqual(self.menu.read_bytes(), before)
|
||||
|
||||
def test_a_start_by_hand_counts_its_own_switches(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\nLEONIDA_FULLSCREEN=\r\n", encoding="utf-8")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1", "LEONIDA_FULLSCREEN": "1"},
|
||||
direct=["-Resolution", "1080", "-Fullscreen"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1")
|
||||
self.assertEqual(ran["settings"]["LEONIDA_FULLSCREEN"], "1")
|
||||
self.assertEqual(self.saved(), {})
|
||||
|
||||
def test_more_wins_over_the_menu_like_a_typed_switch(self):
|
||||
self.menu.write_text("LEONIDA_PROMPTS=playstation\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8")
|
||||
ran = self.start({}, typed=["More"], more={"LEONIDA_PROMPTS": "xbox"})
|
||||
self.assertEqual(self.saved(), {"LEONIDA_PANEL": "1"})
|
||||
self.assertIn("(-More)", ran["said"])
|
||||
|
||||
def test_an_empty_menu_value_still_unsets(self):
|
||||
self.start({"LEONIDA_PANEL": "1"})
|
||||
self.menu.write_text("LEONIDA_PANEL=\r\n", encoding="utf-8")
|
||||
self.assertNotIn("LEONIDA_PANEL", self.start({"LEONIDA_PANEL": "1"})["settings"])
|
||||
self.assertNotIn("LEONIDA_PANEL", self.start({"LEONIDA_PANEL": "1"}, typed=[])["settings"])
|
||||
|
||||
def test_a_dry_run_writes_neither_file(self):
|
||||
def test_a_dry_run_writes_nothing(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE=0.6\r\n", encoding="utf-8")
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1"}, dry=True)
|
||||
self.assertFalse(self.last.exists())
|
||||
self.start({"LEONIDA_RENDER_SCALE": "1"})
|
||||
before = self.menu.read_bytes()
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "0.5"}, dry=True)
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "0.5")
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE": "1"}, typed=["Resolution"], dry=True)
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE"], "1")
|
||||
self.assertEqual(self.menu.read_bytes(), before)
|
||||
self.assertEqual(self.saved(self.last)["LEONIDA_RENDER_SCALE"], "1")
|
||||
|
||||
def test_a_menu_file_that_cannot_be_written_keeps_every_saved_value(self):
|
||||
self.menu.write_text("LEONIDA_RENDER_SCALE_MIN=0.6667\r\nLEONIDA_PANEL=1\r\n", encoding="utf-8")
|
||||
before = self.menu.read_bytes()
|
||||
(self.root / "leonida-settings.txt.tmp").mkdir() # the new file cannot be written beside it
|
||||
ran = self.start({"LEONIDA_RENDER_SCALE_MIN": "0.5"}, typed=["Lowest"])
|
||||
self.assertEqual(ran["settings"]["LEONIDA_RENDER_SCALE_MIN"], "0.5", "the start still runs with the switch")
|
||||
self.assertEqual(self.menu.read_bytes(), before)
|
||||
self.assertIn("was not updated", ran["said"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user