Skip to content

Commit

Permalink
Additional fixes and cleanup for python updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Silarn committed Sep 16, 2023
1 parent 1b142d0 commit d282c2e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions basic_features/basic_save_game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from pathlib import Path
from typing import Callable
from typing import Callable, Optional

from PyQt6.QtCore import QDateTime, Qt
from PyQt6.QtGui import QImage, QPixmap
Expand Down Expand Up @@ -33,7 +33,7 @@ def allFiles(self) -> list[str]:


class BasicGameSaveGameInfoWidget(mobase.ISaveGameInfoWidget):
def __init__(self, parent: QWidget, get_preview: Callable[[Path], Path | None]):
def __init__(self, parent: QWidget, get_preview: Optional[Callable[[Path], Optional[QPixmap | Path | str]]]):
super().__init__(parent)

self._get_preview = get_preview
Expand Down Expand Up @@ -89,9 +89,9 @@ def setSave(self, save: mobase.ISaveGame):


class BasicGameSaveGameInfo(mobase.SaveGameInfo):
def __init__(self, get_preview: Callable[[Path], Path | None] | None = None):
def __init__(self, get_preview: Optional[Callable[[Path], Optional[QPixmap | Path | str]]] = None):
super().__init__()
self._get_preview = get_preview
self._get_preview: Optional[Callable[[Path], Optional[QPixmap | Path | str]]] = get_preview

def getMissingAssets(self, save: mobase.ISaveGame):
return {}
Expand Down
6 changes: 3 additions & 3 deletions basic_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,13 @@ def CCPlugins(self):
return []

def loadOrderMechanism(self):
return mobase.LoadOrderMechanism.PluginsTxt
return mobase.LoadOrderMechanism.PLUGINS_TXT

def sortMechanism(self):
return mobase.SortMechanism.NONE

def looksValid(self, aQDir: QDir):
return aQDir.exists(self.binaryName())
def looksValid(self, directory: QDir):
return directory.exists(self.binaryName())

def isInstalled(self) -> bool:
return bool(self._gamePath)
Expand Down
12 changes: 6 additions & 6 deletions games/game_blackandwhite2.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ def getPreview(save):
save = BlackAndWhite2SaveGame(save)
lines = [
[
("Name : " + save.getName(), Qt.AlignLeft),
("| Profile : " + save.getSaveGroupIdentifier()[1:], Qt.AlignLeft),
("Name : " + save.getName(), Qt.AlignmentFlag.AlignLeft),
("| Profile : " + save.getSaveGroupIdentifier()[1:], Qt.AlignmentFlag.AlignLeft),
],
[("Land number : " + save.getLand(), Qt.AlignLeft)],
[("Saved at : " + save.getCreationTime().toString(), Qt.AlignLeft)],
[("Elapsed time : " + save.getElapsed(), Qt.AlignLeft)],
[("Land number : " + save.getLand(), Qt.AlignmentFlag.AlignLeft)],
[("Saved at : " + save.getCreationTime().toString(), Qt.AlignmentFlag.AlignLeft)],
[("Elapsed time : " + save.getElapsed(), Qt.AlignmentFlag.AlignLeft)],
]

pixmap = QPixmap(320, 320)
Expand All @@ -277,7 +277,7 @@ def getPreview(save):
bRect = fm.boundingRect(toPrint)
cHeight = bRect.height() * (ln + 1)
bRect.moveTop(cHeight - bRect.height())
if align != Qt.AlignLeft:
if align != Qt.AlignmentFlag.AlignLeft:
continue
else:
bRect.moveLeft(cWidth + margin)
Expand Down
2 changes: 1 addition & 1 deletion games/game_da2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DA2Game(BasicGame):

def version(self):
# Don't forget to import mobase!
return mobase.VersionInfo(1, 0, 1, mobase.ReleaseType.final)
return mobase.VersionInfo(1, 0, 1, mobase.ReleaseType.FINAL)

def init(self, organizer: mobase.IOrganizer):
super().init(organizer)
Expand Down
2 changes: 1 addition & 1 deletion games/game_darkmessiahofmightandmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _read_save_tga(self, filename):
_, _, w, h, bpp, _ = struct.unpack("<HHHHBB", data[8:18])
if bpp != 24:
return None
return QImage(data[18:], w, h, QImage.Format_RGB888)
return QImage(data[18:], w, h, QImage.Format.Format_RGB888)

def init(self, organizer: mobase.IOrganizer):
super().init(organizer)
Expand Down
7 changes: 3 additions & 4 deletions games/game_kerbalspaceprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

class KerbalSpaceProgramSaveGame(BasicGameSaveGame):
def allFiles(self):
group = path.parent
banner = group.joinpath("banners").joinpath(f"${self.getName()}.png")
files = [self.filename]
files = [super().getFilepath()]
banner = self._filepath.joinpath("banners").joinpath(f"${self.getName()}.png")
if banner.exists():
files.append(banner)
return files
Expand All @@ -21,7 +20,7 @@ def getName(self):
return self._filepath.stem

def getSaveGroupIdentifier(self):
return path.parent.name
return self._filepath.parent.name


class KerbalSpaceProgramGame(BasicGame):
Expand Down
2 changes: 1 addition & 1 deletion games/game_sims4.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class TS4Game(BasicGame):

def version(self):
# Don't forget to import mobase!
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.final)
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.FINAL)
2 changes: 1 addition & 1 deletion games/game_trainsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RailworksGame(BasicGame):

def version(self):
# Don't forget to import mobase!
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.final)
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.FINAL)

def executables(self):
return [
Expand Down
8 changes: 4 additions & 4 deletions games/game_valheim.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class OverwriteSync:
partial_match: PartialMatch = PartialMatch(exclude={"valheim", "mod"})
content_match: Optional[ContentMatch] = ContentMatch(
file_glob_patterns=["*.cfg"],
content_regex=re.compile(r"\A.*plugin (?P<mod>.+) v[\d\.]+?$", re.I | re.M),
content_regex=re.compile(r"\A.*plugin (?P<mod>.+) v[\d.]+?$", re.I | re.M),
match_group="mod",
)

Expand Down Expand Up @@ -202,7 +202,7 @@ def _find_mod_for_overwrite_file(
"""Find the mod (name) matching a file in Overwrite (using the mods dll name).
Args:
file_name: The name of the file.
file_path: The name of the file.
mod_dll_map: Mods names and their dll files `{mod_name: ["ModName.dll"]}`.
Returns:
Expand Down Expand Up @@ -236,8 +236,8 @@ def _get_matching_mods(
"""Find matching mods for the given `search_str`.
Args:
search_name: A string to find a mod match for. mod_dll_map: Mods names and
their dll files `{mod_name: ["ModName.dll"]}`.
search_str: A string to find a mod match for.
mod_dll_map: Mods names and their dll files `{mod_name: ["ModName.dll"]}`.
Returns:
Mods with partial matches, sorted descending by their metric
Expand Down
2 changes: 1 addition & 1 deletion games/game_vampirebloodlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def initializeProfile(self, path: QDir, settings: mobase.ProfileSetting):

def version(self):
# Don't forget to import mobase!
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.final)
return mobase.VersionInfo(1, 0, 0, mobase.ReleaseType.FINAL)

def iniFiles(self):
return ["autoexec.cfg", "user.cfg"]
Expand Down
2 changes: 1 addition & 1 deletion games/game_witcher3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Witcher3SaveGame(BasicGameSaveGame):
def allFiles(self):
return [self._filename, self._filename.replace(".sav", ".png")]
return [self._filepath.name, self._filepath.name.replace(".sav", ".png")]


class Witcher3Game(BasicGame):
Expand Down

0 comments on commit d282c2e

Please sign in to comment.