Skip to content

Commit

Permalink
Refactor & cleanup Black & White SaveGameInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ZashIn committed Sep 27, 2023
1 parent c7f5960 commit 403558f
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions games/game_blackandwhite2.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import datetime
import os
import struct
import sys
import time
from pathlib import Path
from typing import BinaryIO

import mobase
from PyQt6.QtCore import QDateTime, QDir, QFile, QFileInfo, Qt
from PyQt6.QtGui import QPainter, QPixmap
from PyQt6.QtWidgets import QWidget

from ..basic_features.basic_save_game_info import (
BasicGameSaveGame,
BasicGameSaveGameInfo,
BasicGameSaveGameInfoWidget,
)
from ..basic_game import BasicGame

Expand Down Expand Up @@ -299,41 +296,6 @@ def _getPreview(savepath: Path):
return pixmap.copy(0, 0, width, height)


class BlackAndWhite2SaveGameInfoWidget(BasicGameSaveGameInfoWidget):
def setSave(self, save: mobase.ISaveGame):
# Resize the label to (0, 0) to hide it:
self.resize(0, 0)

# Retrieve the pixmap:
value = self._get_preview(Path(save.getFilepath()))

if value is None:
return

elif isinstance(value, QPixmap):
pixmap = value
else:
print(
"Failed to retrieve the preview, bad return type: {}.".format(
type(value)
),
file=sys.stderr,
)
return

# Scale the pixmap and show it:
# pixmap = pixmap.scaledToWidth(pixmap.width())
self._label.setPixmap(pixmap)
self.resize(pixmap.width(), pixmap.height())


class BlackAndWhite2SaveGameInfo(BasicGameSaveGameInfo):
def getSaveGameWidget(self, parent: QWidget | None = None):
if self._get_preview is not None:
return BasicGameSaveGameInfoWidget(parent, self._get_preview)
return None


PSTART_MENU = (
str(os.getenv("ProgramData")) + "\\Microsoft\\Windows\\Start Menu\\Programs"
)
Expand Down Expand Up @@ -368,7 +330,7 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
self._featureMap[mobase.LocalSavegames] = BlackAndWhite2LocalSavegames(
self.savesDirectory()
)
self._featureMap[mobase.SaveGameInfo] = BlackAndWhite2SaveGameInfo(_getPreview)
self._featureMap[mobase.SaveGameInfo] = BasicGameSaveGameInfo(_getPreview)
return True

def detectGame(self):
Expand Down

0 comments on commit 403558f

Please sign in to comment.