linux-mod-manager/lmm/games/pdmm.py

94 lines
2.6 KiB
Python
Raw Normal View History

2023-12-02 16:45:16 +00:00
from pathlib import Path
from typing import Any
from lmm.games.game import ProtonGame
from lmm.profile import Profile
from lmm.overlayfs import OverlayFSMount
from lmm.const import LMM_GAMES_PATH
from lmm.runners.base import runner_from_config
GAME_NAME = "ProjectDivaMegaMix"
2023-12-02 16:46:48 +00:00
2023-12-02 16:45:16 +00:00
class ProjectDivaMegaMixProfile(Profile):
# The names of the directories the the mods directory.
mods: list[str]
def __init__(self, name: str, mods: list[str], **kwargs):
super().__init__(GAME_NAME, name, **kwargs)
self.mods = mods
def get_mod_names(self) -> list[str]:
return self.mods
2023-12-02 16:46:48 +00:00
2023-12-02 16:45:16 +00:00
class ProjectDivaMegaMixGame(ProtonGame):
def __init__(self, profiles: list[ProjectDivaMegaMixProfile], **kwargs):
super().__init__(GAME_NAME, "1761390", profiles, **kwargs)
@property
def installation_path(self) -> Path:
2023-12-02 16:46:48 +00:00
return (
self.steam_library
/ "steamapps/common/Hatsune Miku Project DIVA Mega Mix Plus"
)
2023-12-02 16:45:16 +00:00
@property
def game_executable(self) -> Path:
return self.installation_path / "DivaMegaMix.exe"
2023-12-02 16:46:48 +00:00
def prepare_overlays(
self, profile: ProjectDivaMegaMixProfile
) -> list[OverlayFSMount]:
2023-12-02 16:45:16 +00:00
return [
OverlayFSMount(
upper=self.installation_path,
lower=profile.mods,
mount=self.installation_path,
cd=LMM_GAMES_PATH / self.name,
),
]
def to_dict(self) -> dict[str, Any]:
return {
"profiles": [
{
"name": profile.name,
"mods": [
{
"name": mod,
2023-12-02 16:46:48 +00:00
}
for mod in profile.mods
],
}
for profile in self.profiles
2023-12-02 16:45:16 +00:00
]
}
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "ProjectDivaMegaMixGame":
profiles = []
for profile in data["profiles"]:
2023-12-02 16:46:48 +00:00
mods = [mod["name"] for mod in profile["mods"]]
2023-12-02 16:45:16 +00:00
if "runner" in profile:
runner = runner_from_config(profile["runner"])
else:
runner = None
profiles.append(
ProjectDivaMegaMixProfile(
profile["name"],
mods,
runner=runner,
),
)
if "default_runner" in data:
default_runner = runner_from_config(data["default_runner"])
else:
default_runner = None
2023-12-02 16:46:48 +00:00
return ProjectDivaMegaMixGame(profiles, default_runner=default_runner)