Skip to content

Commit caa4beb

Browse files
committed
Add default RootBuilder settings
Applied once (setting "configure_RootBuilder") on UI init or RB enabled
1 parent ce79a5b commit caa4beb

1 file changed

Lines changed: 54 additions & 4 deletions

File tree

games/game_cyberpunk2077.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import re
33
import shutil
44
from collections import Counter
5-
from collections.abc import Iterable
5+
from collections.abc import Iterable, Mapping
66
from dataclasses import dataclass
77
from pathlib import Path
8-
from typing import Literal, TypeVar
8+
from typing import Any, Literal, TypeVar
99

1010
import mobase
1111
from PyQt6.QtCore import QDateTime, QDir, qInfo
@@ -294,10 +294,27 @@ def active_mod_paths(self) -> Iterable[Path]:
294294
yield mods_path / mod
295295

296296

297+
@dataclass
298+
class PluginDefaultSettings:
299+
organizer: mobase.IOrganizer
300+
plugin_name: str
301+
settings: Mapping[str, mobase.MoVariant]
302+
303+
def is_plugin_enabled(self):
304+
return self.organizer.isPluginEnabled(self.plugin_name)
305+
306+
def apply(self) -> bool:
307+
if not self.is_plugin_enabled():
308+
return False
309+
for setting, value in self.settings.items():
310+
self.organizer.setPluginSetting(self.plugin_name, setting, value)
311+
return True
312+
313+
297314
class Cyberpunk2077Game(BasicGame):
298315
Name = "Cyberpunk 2077 Support Plugin"
299316
Author = "6788, Zash"
300-
Version = "2.1.0"
317+
Version = "2.2.0"
301318

302319
GameName = "Cyberpunk 2077"
303320
GameShortName = "cyberpunk2077"
@@ -341,7 +358,32 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
341358
"mods/*/",
342359
),
343360
)
361+
self._rootbuilder_settings = PluginDefaultSettings(
362+
organizer,
363+
"RootBuilder",
364+
{
365+
"usvfsmode": False,
366+
"linkmode": False,
367+
"linkonlymode": True, # RootBuilder v4.5
368+
"backup": True,
369+
"cache": True,
370+
"autobuild": True,
371+
"redirect": False,
372+
"installer": False,
373+
"exclusions": "archive,setup_redlauncher.exe,tools",
374+
"linkextensions": "dll,exe",
375+
},
376+
)
377+
378+
def apply_rootbuilder_settings_once(*args: Any):
379+
if not self.isActive() or not self._get_setting("configure_RootBuilder"):
380+
return
381+
if self._rootbuilder_settings.apply():
382+
qInfo(f"RootBuilder configured for {self.gameName()}")
383+
self._set_setting("configure_RootBuilder", False)
344384

385+
organizer.onUserInterfaceInitialized(apply_rootbuilder_settings_once)
386+
organizer.onPluginEnabled("RootBuilder", apply_rootbuilder_settings_once)
345387
organizer.onAboutToRun(self._onAboutToRun)
346388
return True
347389

@@ -380,11 +422,19 @@ def settings(self) -> list[mobase.PluginSetting]:
380422
"Deploy redmod before game launch if necessary",
381423
True,
382424
),
425+
mobase.PluginSetting(
426+
"configure_RootBuilder",
427+
"Configures RootBuilder for Cyberpunk if installed and enabled",
428+
True,
429+
),
383430
]
384431

385432
def _get_setting(self, key: str) -> mobase.MoVariant:
386433
return self._organizer.pluginSetting(self.name(), key)
387434

435+
def _set_setting(self, key: str, value: mobase.MoVariant):
436+
self._organizer.setPluginSetting(self.name(), key, value)
437+
388438
def executables(self) -> list[mobase.ExecutableInfo]:
389439
game_name = self.gameName()
390440
game_dir = self.gameDirectory()
@@ -439,7 +489,7 @@ def _onAboutToRun(self, app_path_str: str, wd: QDir, args: str) -> bool:
439489
and "-modded" in args
440490
and not self._deploy_redmod()
441491
):
442-
return False
492+
return False # Auto deploy failed
443493
self._map_cache_files()
444494
if self._get_setting("enforce_archive_load_order"):
445495
self._modlist_files.update_modlist("archive")

0 commit comments

Comments
 (0)