From c99648d537e9a5503f6072054a46d32728d673f5 Mon Sep 17 00:00:00 2001 From: Jo Date: Wed, 15 Nov 2023 17:25:27 +0100 Subject: [PATCH] Add info string (#69) --- src/item/filter.py | 12 ++++++------ src/item/read_descr.py | 1 + src/loot_filter.py | 2 +- src/vision_mode.py | 16 ++++++++++++++-- test/item/filter_test.py | 2 +- test/smoke_test.py | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/item/filter.py b/src/item/filter.py index a88acc0e..1af03613 100644 --- a/src/item/filter.py +++ b/src/item/filter.py @@ -114,16 +114,16 @@ def load_files(self): Logger.info(info_str) - def should_keep(self, item: Item) -> tuple[bool, bool, list[str]]: + def should_keep(self, item: Item) -> tuple[bool, bool, list[str], str]: if not self.files_loaded: self.load_files() if item.rarity is ItemRarity.Unique: Logger.info(f"Matched: Unique") - return True, False, [] + return True, False, [], "" if item.type is None or item.power is None: - return False, False, [] + return False, False, [], "" for profile_str, affix_filter in self.affix_filters.items(): for filter_dict in affix_filter: @@ -162,7 +162,7 @@ def should_keep(self, item: Item) -> tuple[bool, bool, list[str]]: if filter_min_affix_count is None or len(matched_affixes) >= filter_min_affix_count: affix_debug_msg = [name for name in matched_affixes] Logger.info(f"Matched {profile_str}.{filter_name}: {affix_debug_msg}") - return True, True, matched_affixes + return True, True, matched_affixes, f"{profile_str}.{filter_name}" if item.aspect: for profile_str, aspect_filter in self.aspect_filters.items(): @@ -179,6 +179,6 @@ def should_keep(self, item: Item) -> tuple[bool, bool, list[str]]: or (condition == "smaller" and item.aspect.value <= threshold) ): Logger.info(f"Matched {profile_str}.Aspects: [{item.aspect.type}, {item.aspect.value}]") - return True, False, [] + return True, False, [], f"{profile_str}.Aspects" - return False, False, [] + return False, False, [], "" diff --git a/src/item/read_descr.py b/src/item/read_descr.py index 82cd00bc..cf3040f6 100644 --- a/src/item/read_descr.py +++ b/src/item/read_descr.py @@ -251,6 +251,7 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray, show_warnings: bo if len(affix_bullets.matches) == 0: if show_warnings: Logger.warning(f"Found affix bullet points, but removed them based on itemtype: {item.type}") + screenshot("failed_affix_bullet_remove", img=img_item_descr) return None empty_sockets = search("empty_socket", img_item_descr, 0.87, roi_bullets, True, mode="all") empty_sockets.matches = sorted(empty_sockets.matches, key=lambda match: match.center[1]) diff --git a/src/loot_filter.py b/src/loot_filter.py index 91f6e298..96ce932e 100644 --- a/src/loot_filter.py +++ b/src/loot_filter.py @@ -79,7 +79,7 @@ def check_items(inv: InventoryBase): # Check if we want to keep the item start_filter = time.time() - keeping, did_match_affixes, _ = Filter().should_keep(item_descr) + keeping, did_match_affixes, _, _ = Filter().should_keep(item_descr) Logger.debug(f" Runtime (Filter): {time.time() - start_filter:.2f}s") if not keeping: keyboard.send("space") diff --git a/src/vision_mode.py b/src/vision_mode.py index 9f9097dd..18b62989 100644 --- a/src/vision_mode.py +++ b/src/vision_mode.py @@ -12,9 +12,10 @@ from item.data.item_type import ItemType from item.filter import Filter import tkinter as tk +from config import Config -def draw_rect(canvas, bullet_width, obj, off, color): +def draw_rect(canvas: tk.Canvas, bullet_width, obj, off, color): offset_loc = np.array(obj.loc) + off x1 = int(offset_loc[0] - bullet_width / 2) y1 = int(offset_loc[1] - bullet_width / 2) @@ -117,14 +118,25 @@ def vision_mode(): elif rarity in [ItemRarity.Magic, ItemRarity.Common]: match = False + matched_str = "" if item_descr is not None: - keep, did_match_affixes, matched_affixes = Filter().should_keep(item_descr) + keep, did_match_affixes, matched_affixes, matched_str = Filter().should_keep(item_descr) if not keep: match = False # Adapt colors based on config if match: canvas.config(highlightbackground="#23fc5d") + font_size = 12 + window_height = Config().ui_pos["window_dimensions"][1] + if window_height == 1440: + font_size = 13 + elif window_height == 2160: + font_size = 14 + if len(matched_str) > 13: + matched_str = matched_str[:13] + matched_str += "..." + canvas.create_text(off * 3, h - off, text=matched_str, font=("Courier New", font_size), fill="#23fc5d") # Show matched bullets if item_descr is not None: bullet_width = thick * 3 diff --git a/test/item/filter_test.py b/test/item/filter_test.py index 4997695a..772c4f6f 100644 --- a/test/item/filter_test.py +++ b/test/item/filter_test.py @@ -20,5 +20,5 @@ def test_should_keep(): ], ) filter = Filter() - keep, _, _ = filter.should_keep(item) + keep, _, _, _ = filter.should_keep(item) print(keep) diff --git a/test/smoke_test.py b/test/smoke_test.py index aeb7bdae..19e4148f 100644 --- a/test/smoke_test.py +++ b/test/smoke_test.py @@ -27,5 +27,5 @@ def test_smoke(): item_descr = read_descr(rarity, cropped_descr) assert item_descr is not None filter = Filter() - keep, _, _ = filter.should_keep(item_descr) + keep, _, _, _ = filter.should_keep(item_descr) print("Runtime (full): ", time.time() - start, keep)