mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 13:39:58 -04:00
Custom is the last scheme in Customize Launcher. Its Background Color and Button Color rows open a picker in the description box's place: a square of the hue's colours (saturation across, brightness up and down) with a hue bar under it to click or drag on, Hue, Saturation and Brightness rows for the arrows and the gamepad, and a Hex Code row to type a code into. Each picked colour takes the place of one colour of the first scheme, the backdrop's middle tint or the buttons' wood, and the rest of its group follows it, lighter and darker as in the first scheme; light buttons get dark text. The colours are kept as custom_background and custom_buttons in launcher.json. The background picture used to fill the whole window, so its top was hidden under the title band. It now fills the window from where the band ends, cut to that shape around its middle and scaled evenly. A copy an older launcher kept for the whole window is cut, never squeezed, and made again from the picture file while it is there. Add to Steam's description and result are now one plain sentence each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.7 KiB
Python
66 lines
3.7 KiB
Python
"""data/launcher.json: the player's choices and what the launcher remembers between runs."""
|
|
import json
|
|
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
DEFAULTS = {
|
|
'game_dir': '', # the built game; empty until the first install picks one
|
|
'dump': '', # the .nup (or the folder with exefs/ and romfs/) the game was built from
|
|
'auto_check': True, # look for a new version when the launcher opens, and every hour while it runs
|
|
'auto_install': True, # install a downloaded update by itself whenever the game is not running
|
|
'channel': 'stable', # 'stable' or 'preview' (GitHub pre-releases)
|
|
'hide_while_playing': True, # hide the window while the game runs, show it again when it exits
|
|
'keep_cache': True, # keep build-cache/ (the lift and objects) so an update recompiles only changes
|
|
'desktop_shortcut': True,
|
|
'save_export_dir': '', # where Saves > Export Save writes its zip; empty: the Downloads folder
|
|
'export_with_log': True, # Export Save adds the game's latest log and nx2navi.ini (for a bug report)
|
|
'theme': 'forest', # the colour scheme (launcher/ui/art.py THEMES)
|
|
'custom_background': '', # the Custom scheme's backdrop colour, #rrggbb; empty: the first scheme's
|
|
'custom_buttons': '', # the Custom scheme's colour of the buttons, panels and title band
|
|
'background': '', # the picture the player chose as the background; its fitted copy is data/background.npy
|
|
'background_dim': 40, # how much that picture is darkened, in percent
|
|
'animations': True, # the cursor glides, screens slide in, sparks drift, Navi bobs
|
|
'sounds': 'low', # the game's select and back sounds: off, low (sound.py DEFAULT_LEVEL), medium, high
|
|
'feed_repo': '', # owner/name overriding feed.json, for testing a fork's releases
|
|
'github_token': '', # only for a private release repository; stored as plain text
|
|
'last_check': 0.0,
|
|
'last_seen': '', # the newest version the player was told about
|
|
'rolled_back': '', # the last version that failed to start; it is never downloaded or installed by itself
|
|
}
|
|
|
|
|
|
class Settings(dict):
|
|
def __init__(self, path):
|
|
super().__init__(DEFAULTS)
|
|
self.path = Path(path)
|
|
self.unreadable = False # the file is there but is no JSON; a copy of it is kept as launcher.json.bad
|
|
try:
|
|
# utf-8-sig: the docs ask players to edit the file by hand, and an editor may save it with a BOM
|
|
data = json.loads(self.path.read_text(encoding='utf-8-sig'))
|
|
if isinstance(data, dict):
|
|
self.update({k: v for k, v in data.items() if k in DEFAULTS and type(v) is type(DEFAULTS[k])})
|
|
except OSError:
|
|
pass
|
|
except ValueError:
|
|
# a typo made by hand: keep what the player wrote before the next save() replaces it with the defaults
|
|
self.unreadable = True
|
|
try:
|
|
shutil.copyfile(self.path, self.path.with_name(self.path.name + '.bad'))
|
|
except OSError:
|
|
pass
|
|
|
|
def save(self):
|
|
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
tmp = self.path.with_name(self.path.name + '.tmp')
|
|
tmp.write_text(json.dumps(dict(self), indent=1), encoding='utf-8')
|
|
os.replace(tmp, self.path)
|
|
|
|
def reset(self):
|
|
"""Default Settings: the choices go back to their defaults; the game folder, dump and history stay."""
|
|
keep = {k: self[k] for k in ('game_dir', 'dump', 'last_check', 'last_seen', 'feed_repo', 'github_token',
|
|
'rolled_back')}
|
|
self.clear()
|
|
self.update(DEFAULTS)
|
|
self.update(keep)
|