Skip to content

Commit

Permalink
Support for wrongly sized images, escape for item-less item stack mod…
Browse files Browse the repository at this point in the history
…ifier outputs, support for tag item spotlight format
  • Loading branch information
eerussianguy committed Oct 4, 2024
1 parent 8ffcd81 commit 327bbb6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/crafting_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 327bbb6

Please sign in to comment.