Skip to content

Commit

Permalink
stop string early on empty socket detection (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 authored Feb 5, 2024
1 parent a6721d9 commit 235a43c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion assets/lang/enUS/corrections.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"compare",
" cts ",
"dearest will",
"when equipped"
"when equipped",
"empty socket"
]
}
7 changes: 4 additions & 3 deletions src/item/descr/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ def find_number(s: str, idx: int = 0) -> float:


def remove_text_after_first_keyword(text: str, keywords: list[str]) -> str:
start_pos = None
for keyword in keywords:
match = re.search(re.escape(keyword), text)
start_pos = None
if match and (start_pos is None or start_pos > match.start()):
start_pos = match.start()
if start_pos is not None:
return text[:start_pos]
start_pos = match.start() if start_pos is None or start_pos > match.start() else start_pos
if start_pos is not None:
return text[:start_pos]
return text


Expand Down
Binary file added test/assets/item/read_descr_unique_1080p_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/item/read_descr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@
],
),
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_unique_1080p_3.png",
Item(
ItemRarity.Unique,
ItemType.ChestArmor,
804,
Aspect("razorplate", 11197),
[],
),
),
],
)
def test_read_descr(img_res: tuple[int, int], input_img: str, expected_item: Item):
Expand Down

0 comments on commit 235a43c

Please sign in to comment.