|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from PyQt6.QtCore import QDir |
| 4 | + |
| 5 | +import mobase |
| 6 | + |
| 7 | +from ..basic_features import BasicLocalSavegames, BasicModDataChecker, GlobPatterns |
| 8 | +from ..basic_features.basic_save_game_info import BasicGameSaveGame |
| 9 | +from ..basic_game import BasicGame |
| 10 | +from ..steam_utils import find_steam_path |
| 11 | + |
| 12 | + |
| 13 | +class DispatchModDataChecker(BasicModDataChecker): |
| 14 | + def __init__(self): |
| 15 | + super().__init__( |
| 16 | + GlobPatterns( |
| 17 | + move={ |
| 18 | + "*.fliarchive": "Mods/", |
| 19 | + "*.pak": "Paks/~mods/", |
| 20 | + "*.ucas": "Paks/~mods/", |
| 21 | + "*.utoc": "Paks/~mods/", |
| 22 | + }, |
| 23 | + valid=["L10N", "sound", "Mods", "Paks"], |
| 24 | + ) |
| 25 | + ) |
| 26 | + |
| 27 | + |
| 28 | +class Dispatch(BasicGame, mobase.IPluginFileMapper): |
| 29 | + Name = "Dispatch Support Plugin" |
| 30 | + Author = "Syer10" |
| 31 | + Version = "0.1.0" |
| 32 | + |
| 33 | + GameName = "Dispatch" |
| 34 | + GameShortName = "dispatch" |
| 35 | + GameNexusName = "dispatch" |
| 36 | + GameValidShortNames = [] |
| 37 | + |
| 38 | + GameDataPath = "Dispatch/Content/" |
| 39 | + GameBinary = "Dispatch/Binaries/Win64/Dispatch-Win64-Shipping.exe" |
| 40 | + GameSteamId = 2592160 |
| 41 | + |
| 42 | + GameSupportURL = ( |
| 43 | + r"https://github.com/ModOrganizer2/modorganizer-basic_games/wiki/" |
| 44 | + "Game:-Dispatch" |
| 45 | + ) |
| 46 | + |
| 47 | + def __init__(self): |
| 48 | + BasicGame.__init__(self) |
| 49 | + mobase.IPluginFileMapper.__init__(self) |
| 50 | + |
| 51 | + def init(self, organizer: mobase.IOrganizer) -> bool: |
| 52 | + super().init(organizer) |
| 53 | + self._register_feature(DispatchModDataChecker()) |
| 54 | + self._register_feature(BasicLocalSavegames(self.savesDirectory())) |
| 55 | + return True |
| 56 | + |
| 57 | + def executables(self): |
| 58 | + return [ |
| 59 | + mobase.ExecutableInfo("Dispatch", self.GameBinary), |
| 60 | + ] |
| 61 | + |
| 62 | + ## SAVE |
| 63 | + # credit to game.darkestdungeon.py |
| 64 | + @staticmethod |
| 65 | + def getCloudSaveDirectory() -> str | None: |
| 66 | + steamPath = find_steam_path() |
| 67 | + if steamPath is None: |
| 68 | + return None |
| 69 | + |
| 70 | + userData = steamPath.joinpath("userdata") |
| 71 | + for child in userData.iterdir(): |
| 72 | + name = child.name |
| 73 | + try: |
| 74 | + int(name) |
| 75 | + except ValueError: |
| 76 | + continue |
| 77 | + |
| 78 | + cloudSaves = child.joinpath("2592160/remote") |
| 79 | + if cloudSaves.exists() and cloudSaves.is_dir(): |
| 80 | + return str(cloudSaves) |
| 81 | + return None |
| 82 | + |
| 83 | + def savesDirectory(self) -> QDir: |
| 84 | + return QDir(self.getCloudSaveDirectory()) |
| 85 | + |
| 86 | + def listSaves(self, folder: QDir) -> list[mobase.ISaveGame]: |
| 87 | + saves: list[Path] = [] |
| 88 | + for path in Path(folder.absolutePath()).glob("*.bin"): |
| 89 | + saves.append(path) |
| 90 | + |
| 91 | + ##TODO: need a proper implementation |
| 92 | + return [BasicGameSaveGame(path) for path in saves] |
| 93 | + |
| 94 | + ## MAPPING |
| 95 | + |
| 96 | + def exeDirectory(self) -> QDir: |
| 97 | + return QDir(QDir(self.gameDirectory()).filePath("Dispatch/Binaries/Win64")) |
| 98 | + |
| 99 | + def mappings(self) -> list[mobase.Mapping]: |
| 100 | + return [ |
| 101 | + mobase.Mapping("*.dll", self.exeDirectory().absolutePath(), False, True), |
| 102 | + ] |
0 commit comments