Add black

This commit is contained in:
2023-12-02 17:46:48 +01:00
parent d352e70956
commit b0d801f8a1
16 changed files with 199 additions and 88 deletions

View File

@@ -12,6 +12,7 @@ from lmm.runners.base import runner_from_config
GAME_NAME = "BaldursGate3"
class BaldursGate3ModType(Enum):
# Override the game files
ROOT = 1
@@ -19,6 +20,7 @@ class BaldursGate3ModType(Enum):
# Override the Paks in the compatdata prefix
PAK = 2
@dataclass
class BaldursGate3Mod:
# The directory name
@@ -36,12 +38,14 @@ class BaldursGate3Profile(Profile):
super().__init__(GAME_NAME, name, **kwargs)
self.mods = mods
def get_mods(self, type: BaldursGate3ModType) -> Generator[BaldursGate3Mod, None, None]:
def get_mods(
self, type: BaldursGate3ModType
) -> Generator[BaldursGate3Mod, None, None]:
"""Yields all mods of type @type"""
for mod in self.mods:
if not mod.type == type:
continue
yield mod
def has_mods_of_type(self, type: BaldursGate3ModType) -> bool:
@@ -51,6 +55,7 @@ class BaldursGate3Profile(Profile):
def get_mod_names(self) -> list[str]:
return [mod.name for mod in self.mods]
class BaldursGate3Game(ProtonGame):
def __init__(self, profiles: list[BaldursGate3Profile], **kwargs):
super().__init__(GAME_NAME, "1086940", profiles, **kwargs)
@@ -65,7 +70,18 @@ class BaldursGate3Game(ProtonGame):
@property
def user_mods_path(self) -> Path:
return self.compat_path / "pfx" / "drive_c" / "users" / "steamuser" / "AppData" / "Local" / "Larian Studios" / "Baldur's Gate 3" / "Mods"
return (
self.compat_path
/ "pfx"
/ "drive_c"
/ "users"
/ "steamuser"
/ "AppData"
/ "Local"
/ "Larian Studios"
/ "Baldur's Gate 3"
/ "Mods"
)
def can_start(self) -> bool:
return self.user_mods_path.exists() and self.installation_path.exists()
@@ -87,9 +103,7 @@ class BaldursGate3Game(ProtonGame):
if profile.has_mods_of_type(BaldursGate3ModType.ROOT):
mods = list(profile.get_mods(BaldursGate3ModType.ROOT))
mod_paths = [
LMM_GAMES_PATH / GAME_NAME / mod.name for mod in mods
]
mod_paths = [LMM_GAMES_PATH / GAME_NAME / mod.name for mod in mods]
overlays.append(
OverlayFSMount(
self.installation_path,
@@ -102,9 +116,7 @@ class BaldursGate3Game(ProtonGame):
print(f"Loaded root mods: {mod_names}")
if profile.has_mods_of_type(BaldursGate3ModType.PAK):
mods = list(profile.get_mods(BaldursGate3ModType.PAK))
mod_paths = [
os.path.join("./", mod.name) for mod in mods
]
mod_paths = [os.path.join("./", mod.name) for mod in mods]
# Merge all mods
overlays.append(
@@ -134,9 +146,11 @@ class BaldursGate3Game(ProtonGame):
{
"name": mod.name,
"type": mod.type.value,
} for mod in profile.mods
]
} for profile in self.profiles
}
for mod in profile.mods
],
}
for profile in self.profiles
]
}
@@ -149,7 +163,9 @@ class BaldursGate3Game(ProtonGame):
mods.append(
BaldursGate3Mod(
mod["name"],
BaldursGate3ModType.ROOT if mod["type"] == 1 else BaldursGate3ModType.PAK,
BaldursGate3ModType.ROOT
if mod["type"] == 1
else BaldursGate3ModType.PAK,
),
)
@@ -165,10 +181,10 @@ class BaldursGate3Game(ProtonGame):
runner=runner,
),
)
if "default_runner" in data:
default_runner = runner_from_config(data["default_runner"])
else:
default_runner = None
return BaldursGate3Game(profiles, default_runner=default_runner)
return BaldursGate3Game(profiles, default_runner=default_runner)

View File

@@ -47,4 +47,4 @@ def load_game_configs() -> list[Game]:
)
except Exception as ex:
print(f"Failed to load game {item}: {ex}")
return games
return games

View File

@@ -9,9 +9,11 @@ from lmm.overlayfs import OverlayFSMount
from lmm.profile import Profile
from lmm.steam import find_library_folder_for_game
class CannotStartReason:
pass
@dataclass
class PathNotExistingReason(CannotStartReason):
# The path that is not existing
@@ -20,6 +22,7 @@ class PathNotExistingReason(CannotStartReason):
def __str__(self) -> str:
return f"Path {self.path} does not exist"
class Game(abc.ABC):
# The name of the game.
name: str
@@ -30,7 +33,9 @@ class Game(abc.ABC):
# The default runner to use when launching the game.
default_runner: Optional["Runner"]
def __init__(self, name: str, profiles: list[Profile], default_runner: Optional["Runner"]):
def __init__(
self, name: str, profiles: list[Profile], default_runner: Optional["Runner"]
):
self.name = name
self.profiles = profiles
self.default_runner = default_runner
@@ -63,6 +68,7 @@ class Game(abc.ABC):
def wait(self):
return None
class ProtonGame(Game, abc.ABC):
# The appid of the game in Steam.
appid: str
@@ -70,7 +76,13 @@ class ProtonGame(Game, abc.ABC):
# The PID of the game.
_pid: Optional[str]
def __init__(self, name: str, appid: str, profiles: list[Profile], default_runner: Optional["Runner"]):
def __init__(
self,
name: str,
appid: str,
profiles: list[Profile],
default_runner: Optional["Runner"],
):
super().__init__(name, profiles, default_runner)
self._pid = None
self.appid = appid
@@ -106,7 +118,9 @@ class ProtonGame(Game, abc.ABC):
# Workaround for games like Baldur's Gate 3 that have a relative path in the cmdline.
# Note that the cmdline contains null bytes that we have to remove.
abs_cmdline = os.path.abspath(cmdline).replace("\x00", "")
if cmdline.startswith(wine_exe_path) or abs_cmdline == str(self.game_executable):
if cmdline.startswith(wine_exe_path) or abs_cmdline == str(
self.game_executable
):
self._pid = dir
break
except:

View File

@@ -9,6 +9,7 @@ from lmm.runners.base import runner_from_config
GAME_NAME = "ProjectDivaMegaMix"
class ProjectDivaMegaMixProfile(Profile):
# The names of the directories the the mods directory.
mods: list[str]
@@ -21,19 +22,25 @@ class ProjectDivaMegaMixProfile(Profile):
def get_mod_names(self) -> list[str]:
return self.mods
class ProjectDivaMegaMixGame(ProtonGame):
def __init__(self, profiles: list[ProjectDivaMegaMixProfile], **kwargs):
super().__init__(GAME_NAME, "1761390", profiles, **kwargs)
@property
def installation_path(self) -> Path:
return self.steam_library / "steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus"
return (
self.steam_library
/ "steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus"
)
@property
def game_executable(self) -> Path:
return self.installation_path / "DivaMegaMix.exe"
def prepare_overlays(self, profile: ProjectDivaMegaMixProfile) -> list[OverlayFSMount]:
def prepare_overlays(
self, profile: ProjectDivaMegaMixProfile
) -> list[OverlayFSMount]:
return [
OverlayFSMount(
upper=self.installation_path,
@@ -51,9 +58,11 @@ class ProjectDivaMegaMixGame(ProtonGame):
"mods": [
{
"name": mod,
} for mod in profile.mods
]
} for profile in self.profiles
}
for mod in profile.mods
],
}
for profile in self.profiles
]
}
@@ -61,9 +70,7 @@ class ProjectDivaMegaMixGame(ProtonGame):
def from_dict(cls, data: dict[str, Any]) -> "ProjectDivaMegaMixGame":
profiles = []
for profile in data["profiles"]:
mods = [
mod["name"] for mod in profile["mods"]
]
mods = [mod["name"] for mod in profile["mods"]]
if "runner" in profile:
runner = runner_from_config(profile["runner"])
@@ -83,4 +90,4 @@ class ProjectDivaMegaMixGame(ProtonGame):
else:
default_runner = None
return ProjectDivaMegaMixGame(profiles, default_runner=default_runner)
return ProjectDivaMegaMixGame(profiles, default_runner=default_runner)

View File

@@ -7,6 +7,7 @@ from lmm.games.game import ProtonGame
GAME_NAME = "ReadyOrNot"
class ReadyOrNotProfile(Profile):
# Names of directories inside the game's mods directory.
mods: list[str]
@@ -18,6 +19,7 @@ class ReadyOrNotProfile(Profile):
def get_mod_names(self) -> list[str]:
return self.mods
class ReadyOrNotGame(ProtonGame):
def __init__(self, profiles: list[ReadyOrNotProfile], **kwargs):
super().__init__(GAME_NAME, "1144200", profiles, **kwargs)
@@ -55,9 +57,11 @@ class ReadyOrNotGame(ProtonGame):
"mods": [
{
"name": mod,
} for mod in profile.mods
]
} for profile in self.profiles
}
for mod in profile.mods
],
}
for profile in self.profiles
]
}
@@ -65,9 +69,7 @@ class ReadyOrNotGame(ProtonGame):
def from_dict(cls, data: dict[str, Any]) -> "ReadyOrNotGame":
profiles = []
for profile in data["profiles"]:
mods = [
mod["name"] for mod in profile["mods"]
]
mods = [mod["name"] for mod in profile["mods"]]
if "runner" in profile:
runner = runner_from_config(profile["runner"])
@@ -87,4 +89,4 @@ class ReadyOrNotGame(ProtonGame):
else:
default_runner = None
return ReadyOrNotGame(profiles, default_runner=default_runner)
return ReadyOrNotGame(profiles, default_runner=default_runner)