diff --git a/build.py b/build.py index 9da8079d..cf3a0cd4 100644 --- a/build.py +++ b/build.py @@ -58,4 +58,5 @@ def clean_up(): shutil.copy("config/filter_aspects.yaml", f"{release_dir}/config/") shutil.copy("README.md", f"{release_dir}/") shutil.copytree("assets", f"{release_dir}/assets") + os.rename(f"{release_dir}/main.exe", f"{release_dir}/d4lf.exe") clean_up() diff --git a/config/filter_affixes.yaml b/config/filter_affixes.yaml index 4d5b2db7..5988fee8 100644 --- a/config/filter_affixes.yaml +++ b/config/filter_affixes.yaml @@ -6,7 +6,7 @@ # itemType must be any of: # helm, armor, pants, gloves, boots, ring, amulet, axe, tow-handed axe, # sword, two-handed sword, mace, two-handed mace, scythe, two-handed scythe, -# bow, bracers, crossbow, dagger, polarm, shield, stff, wand, offhand +# bow, bracers, crossbow, dagger, polarm, shield, stff, wand, offhand, totem Filters: @@ -48,7 +48,7 @@ Filters: # Example take all boots and rings - TakeAll: - itemType: [boots, ring] + itemType: [boots] minPower: 0 affixPool: minAffixCount: 0 diff --git a/config/params.ini b/config/params.ini index b511efdd..396b4b20 100644 --- a/config/params.ini +++ b/config/params.ini @@ -1,6 +1,6 @@ [general] ; How many tabs should be checked for items in chest. Note: All 5 Tabs must be unlocked! -check_chest_tabs=3 +check_chest_tabs=2 [char] ; Hotkey to open inventory diff --git a/src/item/data/item_type.py b/src/item/data/item_type.py index 1d892c1d..f56acf58 100644 --- a/src/item/data/item_type.py +++ b/src/item/data/item_type.py @@ -29,3 +29,4 @@ class ItemType(Enum): Staff = "staff" Wand = "wand" Offhand = "offhand" + Totem = "totem" diff --git a/src/item/filter.py b/src/item/filter.py index b49b01c2..ea26e0b5 100644 --- a/src/item/filter.py +++ b/src/item/filter.py @@ -105,25 +105,25 @@ def should_keep(item: Item): if matching_affix_count >= filter_min_affix_count: affix_debug_msg = [affix.type for affix in item.affixes] - Logger.info(f"Matched with affix filter: {filter_name}: {affix_debug_msg}") + Logger.info(f"Matched {filter_name}: {affix_debug_msg}") return True - if item.aspect: - for filter_data in filter_aspects: - filter_aspect_pool = [filter_data] if isinstance(filter_data, str) else filter_data - for aspect in filter_aspect_pool: - aspect_name, *rest = aspect if isinstance(aspect, list) else [aspect] - threshold = rest[0] if rest else None - condition = rest[1] if len(rest) > 1 else "larger" - - if item.aspect.type == aspect_name: - if ( - threshold is None - or item.aspect.value is None - or (condition == "larger" and item.aspect.value >= threshold) - or (condition == "smaller" and item.aspect.value <= threshold) - ): - Logger.info(f"Matched with aspect filter: {filter_name}: {item.aspect.type}") - return True + if item.aspect: + for filter_data in filter_aspects: + filter_aspect_pool = [filter_data] if isinstance(filter_data, str) else filter_data + for aspect in filter_aspect_pool: + aspect_name, *rest = aspect if isinstance(aspect, list) else [aspect] + threshold = rest[0] if rest else None + condition = rest[1] if len(rest) > 1 else "larger" + + if item.aspect.type == aspect_name: + if ( + threshold is None + or item.aspect.value is None + or (condition == "larger" and item.aspect.value >= threshold) + or (condition == "smaller" and item.aspect.value <= threshold) + ): + Logger.info(f"Matched: [{item.aspect.type}, {item.aspect.value}]") + return True return False diff --git a/src/item/read_descr.py b/src/item/read_descr.py index 20fe4465..efc7c67c 100644 --- a/src/item/read_descr.py +++ b/src/item/read_descr.py @@ -36,11 +36,12 @@ def _closest_to(value, choices): return min(choices, key=lambda x: abs(x - value)) -def _find_number(s): +def _find_number(s, idx: int = 0): matches = re.findall(r"[+-]?(\d+\.\d+|\.\d+|\d+\.?|\d+)\%?", s) if "Up to a 5%" in s: number = matches[1] if len(matches) > 1 else None - number = matches[0] if matches else None + else: + number = matches[idx] if matches and len(matches) > idx else None if number is not None: return float(number.replace("+", "").replace("%", "")) return None @@ -103,8 +104,11 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item: crop_top = crop(img_item_descr, roi_top) concatenated_str = image_to_text(crop_top).text.lower().replace("\n", " ") idx = None + # TODO: Handle common mistakes nicer if "item power" in concatenated_str: idx = concatenated_str.index("item power") + elif "ttem power" in concatenated_str: + idx = concatenated_str.index("ttem power") elif "item" in concatenated_str: idx = concatenated_str.index("item") if idx is not None: @@ -218,7 +222,8 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item: cleaned_str = _clean_str(concatenated_str) found_key = _closest_match(cleaned_str, aspect_dict, min_score=77) - found_value = _find_number(concatenated_str) + idx = 1 if found_key in ["frostbitten_aspect"] else 0 + found_value = _find_number(concatenated_str, idx) if found_key is not None: item.aspect = Aspect(found_key, concatenated_str, found_value) diff --git a/src/loot_filter.py b/src/loot_filter.py index 9bc1b7a6..6fff988c 100644 --- a/src/loot_filter.py +++ b/src/loot_filter.py @@ -50,7 +50,7 @@ def check_items(inv: InventoryBase): Logger.debug(f" Runtime (DetectItem): {time.time() - start_time:.2f}s") # Hardcoded rarity filters if rarity == ItemRarity.Unique: - Logger.info("Matched unique.") + Logger.info("Matched: unique") continue if rarity in [ItemRarity.Common, ItemRarity.Magic]: Logger.info(f"Discard item of rarity: {rarity}") @@ -61,7 +61,7 @@ def check_items(inv: InventoryBase): # Detect contents of item descr item_descr = read_descr(rarity, croped_descr) if item_descr is None: - Logger.warning("Failed to read properties. Keeping it.") + Logger.warning("Failed to read properties. Keeping it") continue Logger.debug(f" Runtime (ReadItem): {time.time() - start_time_read:.2f}s") diff --git a/src/overlay.py b/src/overlay.py index 2f8a0193..fc12181d 100644 --- a/src/overlay.py +++ b/src/overlay.py @@ -26,26 +26,43 @@ def __init__(self): self.is_minimized = True self.root = tk.Tk() self.root.title("LootFilter Overlay") - self.root.attributes("-alpha", 0.8) + self.root.attributes("-alpha", 0.89) self.root.overrideredirect(True) # self.root.wm_attributes("-transparentcolor", "white") self.root.wm_attributes("-topmost", True) self.screen_width = self.root.winfo_screenwidth() self.screen_height = self.root.winfo_screenheight() - self.initial_height = int(30) - self.initial_width = int(self.screen_width * 0.18) - self.maximized_height = int(160) + self.initial_height = int(self.root.winfo_screenheight() * 0.027) + self.initial_width = int(self.screen_width * 0.05) + self.maximized_height = int(self.initial_height * 3.85) + self.maximized_width = int(self.initial_width * 6) self.canvas = tk.Canvas(self.root, bg="black", height=self.initial_height, width=self.initial_width, highlightthickness=0) - self.root.geometry(f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+0") + self.root.geometry( + f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}" + ) self.canvas.pack() - self.toggle_button = tk.Button(self.root, text="toggle", bg="#222222", fg="#555555", borderwidth=0, command=self.toggle_size) - self.canvas.create_window(28, 15, window=self.toggle_button) + self.toggle_button = tk.Button( + self.root, + text="toggle", + bg="#222222", + fg="#555555", + borderwidth=0, + command=self.toggle_size, + ) + self.canvas.create_window(int(self.initial_width * 0.3), self.initial_height // 2, window=self.toggle_button) - self.filter_button = tk.Button(self.root, text="filter", bg="#222222", fg="#555555", borderwidth=0, command=self.filter_items) - self.canvas.create_window(70, 15, window=self.filter_button) + self.filter_button = tk.Button( + self.root, + text="filter", + bg="#222222", + fg="#555555", + borderwidth=0, + command=self.filter_items, + ) + self.canvas.create_window(int(self.initial_width * 0.73), self.initial_height // 2, window=self.filter_button) self.terminal_listbox = tk.Listbox( self.canvas, @@ -58,7 +75,13 @@ def __init__(self): borderwidth=0, font=("Courier New", 9), ) - self.terminal_listbox.place(relx=0, rely=0, relwidth=1, relheight=1, y=30) + self.terminal_listbox.place( + relx=0, + rely=0, + relwidth=1, + relheight=1 - (self.initial_height / self.maximized_height), + y=self.initial_height, + ) # Setup the listbox logger handler listbox_handler = ListboxHandler(self.terminal_listbox) @@ -68,10 +91,14 @@ def __init__(self): def toggle_size(self): if not self.is_minimized: self.canvas.config(height=self.initial_height, width=self.initial_width) - self.root.geometry(f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+0") + self.root.geometry( + f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2}+{self.screen_height - self.initial_height}" + ) else: - self.canvas.config(height=self.maximized_height, width=self.initial_width) - self.root.geometry(f"{self.initial_width}x{self.maximized_height}+{self.screen_width//2 - self.initial_width//2}+0") + self.canvas.config(height=self.maximized_height, width=self.maximized_width) + self.root.geometry( + f"{self.maximized_width}x{self.maximized_height}+{self.screen_width//2 - self.maximized_width//2}+{self.screen_height - self.maximized_height}" + ) self.is_minimized = not self.is_minimized move_window_to_foreground() diff --git a/src/ui/inventory_base.py b/src/ui/inventory_base.py index 78baa5cf..841bfe8f 100644 --- a/src/ui/inventory_base.py +++ b/src/ui/inventory_base.py @@ -48,7 +48,7 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo slot_img = crop(img, slot_roi) hsv_image = cv2.cvtColor(slot_img, cv2.COLOR_BGR2HSV) mean_value_of_high = np.mean(hsv_image[:, :, 2]) - if mean_value_of_high > 40: + if mean_value_of_high > 53: occupied_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi))) else: empty_slots.append(ItemSlot(bounding_box=slot_roi, center=get_center(slot_roi))) diff --git a/src/version.py b/src/version.py index 5becc17c..6849410a 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -__version__ = "1.0.0" +__version__ = "1.1.0"