From 327bbb6cd9691663b2cf4790a37dc77547b35ef4 Mon Sep 17 00:00:00 2001 From: eerussianguy Date: Fri, 4 Oct 2024 12:18:08 -0400 Subject: [PATCH] Support for wrongly sized images, escape for item-less item stack modifier outputs, support for tag item spotlight format --- src/components/crafting_recipe.py | 6 +++++- src/context.py | 4 ++++ src/main.py | 13 ++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/crafting_recipe.py b/src/components/crafting_recipe.py index 96de5c8da9..143672d071 100644 --- a/src/components/crafting_recipe.py +++ b/src/components/crafting_recipe.py @@ -104,7 +104,11 @@ def format_ingredient(context: Context, data: Any) -> Tuple[str, str]: def format_item_stack(context: Context, data: Any) -> Tuple[str, str, int]: if 'modifiers' in data and 'stack' in data: return format_item_stack(context, data['stack']) # Discard modifiers - path, name = item_loader.get_item_image(context, data['item']) + if 'item' in data: + path, name = item_loader.get_item_image(context, data['item']) + else: + path = '../../_images/placeholder_64.png' + name = None count = 1 if 'count' not in data else data['count'] return path, name, count diff --git a/src/context.py b/src/context.py index 1d954d96da..1c0542144e 100644 --- a/src/context.py +++ b/src/context.py @@ -165,6 +165,10 @@ def convert_image(self, image: str) -> str: img = self.loader.load_explicit_texture(image) width, height = img.size + assert width == height + if width % 256 != 0: + util.error('Image size is not a multiple of 256. Automatically resizing, but there may be losses. (%s x %s): %s' % (width, height, image)) + img = img.resize((400, 400), Image.NEAREST) assert width == height and width % 256 == 0 size = width * 200 // 256 img = img.crop((0, 0, size, size)) diff --git a/src/main.py b/src/main.py index 310640236c..598e803c6e 100644 --- a/src/main.py +++ b/src/main.py @@ -280,9 +280,16 @@ def parse_page(context: Context, entry_id: str, buffer: List[str], data: Any): elif page_type == 'patchouli:spotlight': # Item Images try: - item_src, item_name = item_loader.get_item_image(context, data['item'], False) - context.format_title_with_icon(buffer, item_src, item_name, data) - context.items_passed += 1 + if isinstance(data['item'], str): + item_src, item_name = item_loader.get_item_image(context, data['item'], False) + context.format_title_with_icon(buffer, item_src, item_name, data) + context.items_passed += 1 + elif 'tag' in data['item']: + item_src, item_name = item_loader.get_item_image(context, '#' + data['item']['tag'], False) + context.format_title_with_icon(buffer, item_src, item_name, data) + context.items_passed += 1 + else: + util.error('Spotlight page did not have an item or tag key: %s' % data) except InternalError as e: e.warning()