Skip to content

Commit

Permalink
Support loading rune images
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Henderson <[email protected]>
  • Loading branch information
zbee committed Oct 13, 2023
1 parent b53050d commit 19698d9
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions hinter/ui/functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from PIL import ImageOps

from cassiopeia.core.staticdata.common import Image as CassiopeiaImage
from cassiopeia.core.staticdata.rune import RuneImage as CassiopeiaRuneImage
from cassiopeia.core.staticdata.rune import RunePath as CassiopeiaRunePathImage
from cassiopeia.core.staticdata.profileicon import ProfileIcon as CassiopeiaProfileIcon

import hinter
Expand Down Expand Up @@ -113,7 +115,14 @@ def filler_image(self):
def load_image(self,
image_name: str,
image_type: str = None,
image: Union[str, Image.Image, CassiopeiaImage, CassiopeiaProfileIcon] = None,
image: Union[
str,
Image.Image,
CassiopeiaImage,
CassiopeiaRuneImage,
CassiopeiaRunePathImage,
CassiopeiaProfileIcon,
] = None,
crop: tuple[int, int, int, int] = None,
size: tuple[int, int] = None,
force_fresh: bool = False) -> str:
Expand Down Expand Up @@ -150,6 +159,7 @@ def load_image(self,
self.ui.imgui.add_image(texture_tag=img)
"""
img: Image
image_name = image_name.replace(' ', '_').replace(':', '').lower()
image_path = f'{hinter.data.constants.PATH_IMAGES}{image_name}.png'
tag = f'CACHED_IMAGE-{image_name}'
cached = False
Expand All @@ -173,9 +183,12 @@ def load_image(self,
if image_type == hinter.data.constants.IMAGE_TYPE_PIL:
img = image
# With this, we can pass in cassiopeia images, without making a call if they are cached
if type(img) is CassiopeiaImage:
img = img.image
if type(img) is CassiopeiaProfileIcon:
if (
type(img) is CassiopeiaImage or
type(img) is CassiopeiaRuneImage or
type(img) is CassiopeiaRunePathImage or
type(img) is CassiopeiaProfileIcon
):
img = img.image
elif image_type == hinter.data.constants.IMAGE_TYPE_FILE:
img = Image.open(image)
Expand All @@ -189,14 +202,14 @@ def load_image(self,
if crop is not None and not cached:
img = img.crop(crop)

# Cache the image
if not cached:
img.save(image_path)

# Resize if desired
if size is not None:
img = img.resize(size)

# Cache the image
if not cached:
img.save(image_path)

# Create the texture from the image
texture = img.convert('RGBA')
height_, width_, __ = np.shape(img)
Expand Down Expand Up @@ -232,7 +245,14 @@ def check_image_cache(self, image_name: str) -> bool:
def load_and_round_image(self,
image_name: str,
image_type: str = None,
image: Union[str, Image.Image, CassiopeiaImage, CassiopeiaProfileIcon] = None,
image: Union[
str,
Image.Image,
CassiopeiaImage,
CassiopeiaRuneImage,
CassiopeiaRunePathImage,
CassiopeiaProfileIcon,
] = None,
crop: tuple[int, int, int, int] = None,
size: tuple[int, int] = None,
force_fresh: bool = False) -> str:
Expand Down

0 comments on commit 19698d9

Please sign in to comment.