Investigamer/Proxyshop

[BUG] - "Lieutenant" ability not being italicized due to regex

Closed this issue · 1 comments

Describe the bug
We use this regex to handle identifying an italics ability such as the "Lieutenant —" ability, it works with other situations I've tested but not this one, due to the carriage return that precedes the ability. This code is a slightly refactored version of what's on main branch right now (but the current version produces the same bug)

# Find and add ability words
reg = re.compile(r"([\s\w\-]*?) — ")
for match in reg.findall(card_text):
    # Cover boast cards and choose cards that aren't weird AFR cases
    match = str(match)
    if (
        any(s in match for s in ("• ", "Boast"))
        and card_text[0:12] != "Choose one —"
    ): continue

    # Fix bullet points and carriage return
    if "• " in match:
        match = match.replace("• ", "")
    if "\r" in match:
        match = match.replace("\r", "")
    italic_text.append(match)

To Reproduce
Steps to reproduce the behavior:
Try to render "Tyrant's Familiar" for example:
Tyrant's Familiar (Todd Lockwood)

Your system:

  • Python version: 3.10.5
  • Windows version: Win10 (Updated)
  • Photoshop version: 2022 (23.4.X)

Screenshots
See Tyrant's familiar render above

Will be looking into this soon, but if a good regexer wants to beat me to the punch, we basically just need to modify that regex to exclude a leading carriage return (\r)

I managed to fix this issue with the following snippet:

# Find and add ability words
for match in re.findall(r"(?:\A|\r+|• +)([A-Za-z0-9 ]+) — ", card_text):
    # Control for Boast ability which isn't italicized
    if "Boast" not in match:
        italic_text.append(match)

Will be pushing changes to main soon