Skip to content

Commit

Permalink
Pass Preferences object directly to BaseCardType and ImageMaker
Browse files Browse the repository at this point in the history
Should not rely on global preferences object, #311 will pass the Preferences directly into the BaseCardType.__init__()
  • Loading branch information
CollinHeist committed Mar 21, 2023
1 parent ff95d4f commit b9c8b8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions modules/BaseCardType.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def USES_SEASON_TITLE(self) -> bool:


@abstractmethod
def __init__(self, blur: bool = False, grayscale: bool = False) -> None:
def __init__(self, blur: bool = False, grayscale: bool = False, *,
preferences: 'Preferences' = None) -> None:
"""
Construct a new CardType. Must call super().__init__() to
initialize the parent ImageMaker class (for PreferenceParser and
Expand All @@ -111,7 +112,7 @@ def __init__(self, blur: bool = False, grayscale: bool = False) -> None:
"""

# Initialize parent ImageMaker
super().__init__()
super().__init__(preferences=preferences)

# Object starts as valid
self.valid = True
Expand Down
8 changes: 6 additions & 2 deletions modules/ImageMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ class ImageMaker(ABC):


@abstractmethod
def __init__(self) -> None:
def __init__(self, *, preferences: 'Preferences' = None) -> None:
"""
Initializes a new instance. This gives all subclasses access to
an ImageMagickInterface via the image_magick attribute.
"""

if preferences is None:
self.preferences = global_objects.pp
else:
self.preferences = preferences

# All ImageMakers have an instance of an ImageMagickInterface
self.preferences = global_objects.pp
self.image_magick = ImageMagickInterface(
self.preferences.imagemagick_container,
self.preferences.use_magick_prefix,
Expand Down

0 comments on commit b9c8b8f

Please sign in to comment.