Skip to content

Commit

Permalink
Add info string (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 authored Nov 15, 2023
1 parent 3129c72 commit c99648d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/item/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand All @@ -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, [], ""
1 change: 1 addition & 0 deletions src/item/read_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/loot_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 14 additions & 2 deletions src/vision_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/item/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def test_should_keep():
],
)
filter = Filter()
keep, _, _ = filter.should_keep(item)
keep, _, _, _ = filter.should_keep(item)
print(keep)
2 changes: 1 addition & 1 deletion test/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c99648d

Please sign in to comment.