Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke test #22

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/filter_aspects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Aspects:
# General
- [accelerating_aspect, 24]
- [aspect_of_might, 5.5]
- [aspect_of_disobedience, 1.1]
- [aspect_of_disobedience, 0.9]
- [aspect_of_inner_calm, 10]
- [aspect_of_retribution, 20]
- [aspect_of_the_expectant, 10]
Expand Down
3 changes: 2 additions & 1 deletion src/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ def window_to_abs_window(self, window_coord: np.ndarray) -> np.ndarray:

@convert_args_to_numpy
def abs_window_to_monitor(self, abs_window_coord: np.ndarray) -> np.ndarray:
return self.window_to_monitor(self.abs_window_to_window(abs_window_coord))
window_coord = self.abs_window_to_window(abs_window_coord)
return self.window_to_monitor(window_coord)
14 changes: 7 additions & 7 deletions src/loot_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def run_loot_filter():
for i in range(check_tabs):
chest.switch_to_tab(i)
check_items(chest)
elif not inv.is_open():
inv.open()
if not inv.is_open():
screenshot("inventory_not_open", img=Cam().grab())
Logger.error("Inventory did not open up")
return
check_items(inv)
check_items(inv)
else:
if not inv.open():
screenshot("inventory_not_open", img=Cam().grab())
Logger.error("Inventory did not open up")
return
check_items(inv)
mouse.move(*Cam().abs_window_to_monitor((0, 0)))
Logger().info("Loot Filter done")
9 changes: 6 additions & 3 deletions src/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
from scripts.rogue_tb import run_rogue_tb
from config import Config
from cam import Cam


class ListboxHandler(logging.Handler):
Expand Down Expand Up @@ -41,9 +42,11 @@ def __init__(self):
self.maximized_height = int(self.initial_height * 3.4)
self.maximized_width = int(self.initial_width * 5)

self.screen_off_x = Cam().window_roi["left"]
self.screen_off_y = Cam().window_roi["top"]
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}+{self.screen_height - self.initial_height}"
f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2 + self.screen_off_x}+{self.screen_height - self.initial_height + self.screen_off_y}"
)
self.canvas.pack()

Expand Down Expand Up @@ -110,12 +113,12 @@ 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}+{self.screen_height - self.initial_height}"
f"{self.initial_width}x{self.initial_height}+{self.screen_width//2 - self.initial_width//2 + self.screen_off_x}+{self.screen_height - self.initial_height + self.screen_off_y}"
)
else:
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}"
f"{self.maximized_width}x{self.maximized_height}+{self.screen_width//2 - self.maximized_width//2 + self.screen_off_x}+{self.screen_height - self.maximized_height + self.screen_off_y}"
)
self.is_minimized = not self.is_minimized
move_window_to_foreground()
Expand Down
4 changes: 2 additions & 2 deletions src/ui/inventory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo
for _, slot_roi in enumerate(grid):
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 > 53:
mean_value = np.mean(hsv_image[:, :, 2])
if mean_value > 37:
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)))
Expand Down
4 changes: 2 additions & 2 deletions src/utils/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def detect_window(window_spec: WindowSpec = D4_WINDOW):
def find_and_set_window_position(window_spec: WindowSpec = D4_WINDOW):
hwnd = get_window_spec_id(window_spec)
if hwnd is not None:
position = GetWindowRect(hwnd)
Cam().update_window_pos(*position)
pos = GetWindowRect(hwnd)
Cam().update_window_pos(pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1])
wait(0.5)


Expand Down
30 changes: 30 additions & 0 deletions test/smoke_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import cv2
import time
from item.find_descr import find_descr
from item.read_descr import read_descr
from item.filter import should_keep
from item.data.rarity import ItemRarity
from cam import Cam
from config import Config
from template_finder import stored_templates


def test_smoke():
res = (2560, 1440)
anchor = (1723, 1012)
Cam().update_window_pos(0, 0, *res)
Config().load_data()
stored_templates.cache_clear()
img = cv2.imread("test/assets/item/find_descr_legendary_2560x1440_2_inv.png")
start = time.time()
found, _, rarity, cropped_descr = find_descr(img, anchor)
print("Runtime (detect): ", time.time() - start)
assert found
if rarity == ItemRarity.Unique:
return
if rarity in [ItemRarity.Common, ItemRarity.Magic]:
return
item_descr = read_descr(rarity, cropped_descr)
assert item_descr is not None
keep = should_keep(item_descr)
print("Runtime (full): ", time.time() - start, keep)
Loading