|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from PyQt6.QtCore import QDir |
| 5 | + |
| 6 | +import mobase |
| 7 | + |
| 8 | +from ..basic_features import BasicLocalSavegames, BasicModDataChecker, GlobPatterns |
| 9 | +from ..basic_features.basic_save_game_info import ( |
| 10 | + BasicGameSaveGame, |
| 11 | + BasicGameSaveGameInfo, |
| 12 | +) |
| 13 | +from ..basic_game import BasicGame |
| 14 | + |
| 15 | + |
| 16 | +def parse_schedule1_save_metadata(save_path: Path, save: mobase.ISaveGame): |
| 17 | + metadata_file = save_path / "Game.json" |
| 18 | + try: |
| 19 | + with open(metadata_file) as file: |
| 20 | + meta_data = json.load(file) |
| 21 | + name = meta_data["OrganisationName"] |
| 22 | + if name != (save_name := save.getName()): |
| 23 | + name = f"{save_name} ({name})" |
| 24 | + return { |
| 25 | + "Name": name, |
| 26 | + "Game version": meta_data["GameVersion"], |
| 27 | + } |
| 28 | + except (FileNotFoundError, json.JSONDecodeError): |
| 29 | + return None |
| 30 | + |
| 31 | + |
| 32 | +class Schedule1SaveGame(BasicGameSaveGame): |
| 33 | + def getName(self) -> str: |
| 34 | + metadata_file = self._filepath / "Game.json" |
| 35 | + try: |
| 36 | + with open(metadata_file) as file: |
| 37 | + meta_data = json.load(file) |
| 38 | + return meta_data["OrganisationName"] |
| 39 | + except (FileNotFoundError, json.JSONDecodeError): |
| 40 | + return ( |
| 41 | + f"[{self.getSaveGroupIdentifier().rstrip('s')}] {self._filepath.stem}" |
| 42 | + ) |
| 43 | + |
| 44 | + def getSaveGroupIdentifier(self) -> str: |
| 45 | + return self._filepath.parent.name |
| 46 | + |
| 47 | + |
| 48 | +class Schedule1Game(BasicGame): |
| 49 | + Name = "Schedule I Support Plugin" |
| 50 | + Author = "shellbj" |
| 51 | + Version = "1.0.0" |
| 52 | + |
| 53 | + GameName = "Schedule I" |
| 54 | + GameShortName = "scheduleI" |
| 55 | + GameNexusName = "schedule1" |
| 56 | + GameNexusId = 7381 |
| 57 | + GameSteamId = 3164500 |
| 58 | + |
| 59 | + GameBinary = "Schedule I.exe" |
| 60 | + GameValidShortNames = ["schedule1", "scheduleI"] |
| 61 | + GameDataPath = "" |
| 62 | + GameSavesDirectory = r"%USERPROFILE%/AppData/LocalLow/TVGS/Schedule I/Saves" |
| 63 | + GameSupportURL = ( |
| 64 | + r"https://github.com/ModOrganizer2/modorganizer-basic_games/wiki/" |
| 65 | + "Game:-Schedule-I" |
| 66 | + ) |
| 67 | + |
| 68 | + def init(self, organizer: mobase.IOrganizer) -> bool: |
| 69 | + super().init(organizer) |
| 70 | + self._register_feature( |
| 71 | + BasicModDataChecker( |
| 72 | + GlobPatterns( |
| 73 | + unfold=[ |
| 74 | + # Fixes bad packaging for select mods |
| 75 | + "ModManager&PhoneApp", |
| 76 | + "AutoClearCompletedDeals", |
| 77 | + ], |
| 78 | + valid=[ |
| 79 | + "meta.ini", # Included in installed mod folder. |
| 80 | + "Mods", |
| 81 | + "Plugins", |
| 82 | + "UserData", # might not be needed |
| 83 | + ], |
| 84 | + delete=[ |
| 85 | + "*.md", |
| 86 | + "icon.png", |
| 87 | + "fomod", # not sure this is needed either |
| 88 | + ], |
| 89 | + move={ |
| 90 | + "*.dll": "Mods/", |
| 91 | + # If these even exisit outside of mod packs |
| 92 | + "*.ini": "UserData/", |
| 93 | + "*.cfg": "UserData/", |
| 94 | + "*.json": "UserData/", |
| 95 | + }, |
| 96 | + ) |
| 97 | + ) |
| 98 | + ) |
| 99 | + self._register_feature(BasicLocalSavegames(self.savesDirectory())) |
| 100 | + self._register_feature( |
| 101 | + BasicGameSaveGameInfo( |
| 102 | + None, # no snapshot to add to the widget |
| 103 | + parse_schedule1_save_metadata, |
| 104 | + ) |
| 105 | + ) |
| 106 | + return True |
| 107 | + |
| 108 | + def listSaves(self, folder: QDir) -> list[mobase.ISaveGame]: |
| 109 | + return [ |
| 110 | + Schedule1SaveGame(path) |
| 111 | + for path in Path(folder.absolutePath()).glob("*/SaveGame_[1-5]") |
| 112 | + ] |
0 commit comments