Skip to content

Commit

Permalink
Merge branch 'feat/savegameinfo-metadata' into cyberpunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ZashIn committed Jul 15, 2023
2 parents 987da7d + bc3128d commit b65a6be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 17 additions & 10 deletions basic_features/basic_save_game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ class BasicGameSaveGameInfoWidget(mobase.ISaveGameInfoWidget):
def __init__(
self,
parent: QWidget,
get_preview: Callable[[Path], Path | None] | None = None,
get_metadata: Callable[[Path, mobase.ISaveGame], Mapping[str, str] | None]
| None = None,
get_preview: Callable[
[Path], Path | str | QPixmap | QImage | None
] = lambda p: None,
get_metadata: Callable[
[Path, mobase.ISaveGame], Mapping[str, str] | None
] = lambda p, s: None,
):
"""
Args:
Expand Down Expand Up @@ -104,11 +107,11 @@ def setSave(self, save: mobase.ISaveGame):
w.deleteLater()

# Retrieve the pixmap and metadata:
preview = self._get_preview and self._get_preview(save_path)
preview = self._get_preview(save_path)
pixmap = None

# Set the preview pixmap if the preview file exits
if preview is not None and preview.exists():
if preview:
if isinstance(preview, Path):
pixmap = QPixmap(str(preview))
elif isinstance(preview, str):
Expand All @@ -124,16 +127,17 @@ def setSave(self, save: mobase.ISaveGame):
),
file=sys.stderr,
)
if pixmap:
if pixmap and not pixmap.isNull():
# Scale the pixmap and show it:
pixmap = pixmap.scaledToWidth(self._preview_width)
self._label.setPixmap(pixmap)
self._label.show()
else:
self._label.hide()
pixmap = None

# Add metadata, file date by default.
metadata = self._get_metadata and self._get_metadata(save_path, save)
metadata = self._get_metadata(save_path, save)
if metadata is None:
metadata = {"File Date:": format_date(save.getCreationTime())}
if metadata:
Expand Down Expand Up @@ -165,9 +169,12 @@ def _new_form_row(self, label="", field=""):
class BasicGameSaveGameInfo(mobase.SaveGameInfo):
def __init__(
self,
get_preview: Callable[[Path], Path | None] | None = None,
get_metadata: Callable[[Path, mobase.ISaveGame], Mapping[str, str] | None]
| None = None,
get_preview: Callable[
[Path], Path | str | QPixmap | QImage | None
] = lambda p: None,
get_metadata: Callable[
[Path, mobase.ISaveGame], Mapping[str, str] | None
] = lambda p, s: None,
):
"""Args from: `BasicGameSaveGameInfoWidget`."""
super().__init__()
Expand Down
6 changes: 5 additions & 1 deletion basic_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

import mobase

from .basic_features.basic_save_game_info import BasicGameSaveGame
from .basic_features.basic_save_game_info import (
BasicGameSaveGame,
BasicGameSaveGameInfo,
)


def replace_variables(value: str, game: "BasicGame") -> str:
Expand Down Expand Up @@ -412,6 +415,7 @@ def is_eadesktop(self) -> bool:

def init(self, organizer: mobase.IOrganizer) -> bool:
self._organizer = organizer
self._featureMap[mobase.SaveGameInfo] = BasicGameSaveGameInfo()
if self._mappings.originWatcherExecutables.get():
from .origin_utils import OriginWatcher

Expand Down

0 comments on commit b65a6be

Please sign in to comment.