Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro committed Aug 14, 2024
1 parent 03b7844 commit 0038140
Show file tree
Hide file tree
Showing 42 changed files with 70 additions and 81 deletions.
Binary file removed assets/templates/item_descr/aspect_bullet_point.png
Binary file not shown.
Binary file not shown.
Binary file removed assets/templates/item_descr/empty_socket.png
Binary file not shown.
Binary file removed assets/templates/item_descr/empty_socket_medium.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

TP = concurrent.futures.ThreadPoolExecutor()

__version__ = "5.7.3"
__version__ = "5.7.4"
27 changes: 17 additions & 10 deletions src/config/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ def _transform_list_of_tuples(self, value: list[tuple[int, int]]) -> list[tuple[
return [self._transform_tuples(value=v) for v in value]

def _transform_templates(self, templates: dict[str, Template]) -> dict[str, Template]:
return {
key: Template(
name=value.name,
img_bgra=self._resize_image(src=value.img_bgra),
img_bgr=self._resize_image(src=value.img_bgr),
img_gray=self._resize_image(src=value.img_gray),
alpha_mask=self._resize_image(src=value.alpha_mask) if value.alpha_mask is not None else None,
)
for key, value in templates.items()
}
result = {}
for key, value in templates.items():
if key.endswith("_special"): # do not transform templates that end with _special
result[key] = value
else:
result[key] = Template(
name=value.name,
img_bgra=self._resize_image(src=value.img_bgra),
img_bgr=self._resize_image(src=value.img_bgr),
img_gray=self._resize_image(src=value.img_gray),
alpha_mask=self._resize_image(src=value.alpha_mask) if value.alpha_mask is not None else None,
)
return result

def _transform_tuples(self, value: tuple[int, int]) -> tuple[int, int]:
values = self._transform_array(value=np.array(value, dtype=int))
Expand Down Expand Up @@ -109,6 +112,10 @@ def offsets(self) -> UiOffsetsModel:
def pos(self) -> UiPosModel:
return self._pos

@property
def resolution(self) -> str:
return self._current_resolution

@property
def roi(self) -> UiRoiModel:
return self._roi
Expand Down
1 change: 0 additions & 1 deletion src/item/descr/find_affixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def find_affixes(
affix_height = bottom_limit - affix_top_left[1] - int(line_height * 0.75)
full_affix_region = [*affix_top_left, affix_width, affix_height]
crop_full_affix = crop(img_item_descr, full_affix_region)
# cv2.imwrite("crop_full_affix.png", crop_full_affix)
do_pre_proc = not (is_sigil or not do_pre_proc_flag)
res, line_pos = image_to_text(crop_full_affix, line_boxes=True, do_pre_proc=do_pre_proc)
affix_lines = res.text.lower().split("\n")
Expand Down
16 changes: 4 additions & 12 deletions src/item/descr/read_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from src.item.descr.find_affixes import find_affixes
from src.item.descr.find_aspect import find_aspect
from src.item.descr.item_type import read_item_type
from src.item.descr.texture import find_affix_bullets, find_aspect_bullet, find_codex_upgrade_icon, find_empty_sockets, find_seperator_short
from src.item.descr.texture import find_affix_bullets, find_aspect_bullet, find_codex_upgrade_icon, find_seperator_short
from src.item.models import Item
from src.utils.window import screenshot

Expand Down Expand Up @@ -46,15 +46,12 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray, show_warnings: bo
):
return item

# Find textures for bullets and sockets
# Find textures for bullets
# =========================
affix_bullets = find_affix_bullets(img_item_descr, sep_short_match)
futures["aspect_bullet"] = (
TP.submit(find_aspect_bullet, img_item_descr, sep_short_match)
if rarity in [ItemRarity.Legendary, ItemRarity.Unique, ItemRarity.Mythic]
else None
TP.submit(find_aspect_bullet, img_item_descr, sep_short_match) if rarity in [ItemRarity.Unique, ItemRarity.Mythic] else None
)
empty_sockets = find_empty_sockets(img_item_descr, sep_short_match)

# Split affix bullets into inherent and others
# =========================
Expand Down Expand Up @@ -112,12 +109,7 @@ def _get_inherent():
# Find normal affixes
# =========================
def _get_affixes():
if aspect_bullet is not None:
bottom_limit = aspect_bullet.center[1]
elif len(empty_sockets) > 0:
bottom_limit = empty_sockets[0].center[1]
else:
bottom_limit = img_item_descr.shape[0]
bottom_limit = affix_bullets[-1].region[1] + affix_bullets[-1].region[3] + ResManager().offsets.item_descr_line_height
i_affixes, debug_str = find_affixes(
img_item_descr=img_item_descr, affix_bullets=affix_bullets, bottom_limit=bottom_limit, is_sigil=is_sigil
)
Expand Down
19 changes: 4 additions & 15 deletions src/item/descr/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,17 @@ def find_affix_bullets(img_item_descr: np.ndarray, sep_short_match: TemplateMatc
)


def find_empty_sockets(img_item_descr: np.ndarray, sep_short_match: TemplateMatch) -> list[TemplateMatch]:
template_list = ["empty_socket"]
all_templates = [f"{x}_medium" for x in template_list] + template_list
empty_sockets = _find_bullets(
img_item_descr=img_item_descr,
sep_short_match=sep_short_match,
template_list=all_templates,
threshold=0.8,
mode="all",
)
return sorted(empty_sockets, key=lambda match: match.center[1])


def find_aspect_bullet(img_item_descr: np.ndarray, sep_short_match: TemplateMatch) -> TemplateMatch | None:
template_list = ["aspect_bullet_point", "unique_bullet_point", "mythic_bullet_point"]
template_list = ["unique_bullet_point", "mythic_bullet_point"]
all_templates = [f"{x}_medium" for x in template_list] + template_list
if ResManager().resolution == "1920x1080":
all_templates += ["mythic_bullet_point_1080p_special"]
aspect_bullets = _find_bullets(
img_item_descr=img_item_descr,
sep_short_match=sep_short_match,
template_list=all_templates,
threshold=0.8,
mode="first",
mode="best",
)
return aspect_bullets[0] if aspect_bullets else None

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
2 changes: 1 addition & 1 deletion tests/config/ui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def test_colors():


def test_templates():
assert len(ResManager().templates) == 48
assert len(ResManager().templates) == 45
2 changes: 1 addition & 1 deletion tests/item/find_descr_season5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@pytest.mark.parametrize(
("img_res", "input_img", "anchor", "expected_success", "expected_top_left", "expected_rarity"),
[
((3840, 2160), f"{BASE_PATH}/find_descr_mythic_2160p.png", (3017, 1560), True, (2230, 200), ItemRarity.Mythic),
((3840, 2160), f"{BASE_PATH}/2160p_small_find_descr_mythic_1.png", (3017, 1560), True, (2230, 200), ItemRarity.Mythic),
],
)
def test_find_descr(img_res, input_img, anchor, expected_success, expected_top_left, expected_rarity):
Expand Down
67 changes: 42 additions & 25 deletions tests/item/read_descr_season5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
items = [
(
(3840, 2160),
f"{BASE_PATH}/read_descr_1_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_1.png",
item1 := Item(
affixes=[
Affix(name="intelligence", value=101, type=AffixType.rerolled),
Expand All @@ -29,10 +29,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_1_2160p_small.png", item1),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_1.png", item1),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_2_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_2.png",
item2 := Item(
affixes=[
Affix(name="intelligence", value=87),
Expand All @@ -46,10 +46,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_2_2160p_small.png", item2),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_2.png", item2),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_3_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_3.png",
item3 := Item(
affixes=[
Affix(name="intelligence", value=90),
Expand All @@ -63,10 +63,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_3_2160p_small.png", item3),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_3.png", item3),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_4_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_4.png",
item4 := Item(
affixes=[
Affix(name="chance_for_chain_lightning_projectiles_to_cast_twice", value=20.9),
Expand All @@ -80,10 +80,10 @@
rarity=ItemRarity.Unique,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_4_2160p_small.png", item4),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_4.png", item4),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_5_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_5.png",
item5 := Item(
affixes=[
Affix(name="maximum_life", value=768),
Expand All @@ -98,10 +98,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_5_2160p_small.png", item5),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_5.png", item5),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_6_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_6.png",
item6 := Item(
affixes=[
Affix(name="intelligence", value=94),
Expand All @@ -116,10 +116,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_6_2160p_small.png", item6),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_6.png", item6),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_7_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_7.png",
item7 := Item(
affixes=[
Affix(name="intelligence", value=149, type=AffixType.greater),
Expand All @@ -134,10 +134,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_7_2160p_small.png", item7),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_7.png", item7),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_8_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_8.png",
item8 := Item(
affixes=[
Affix(name="intelligence", value=92),
Expand All @@ -155,10 +155,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_8_2160p_small.png", item8),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_8.png", item8),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_9_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_9.png",
item9 := Item(
affixes=[
Affix(name="intelligence", value=6.3),
Expand All @@ -173,10 +173,10 @@
rarity=ItemRarity.Legendary,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_9_2160p_small.png", item9),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_9.png", item9),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_10_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_10.png",
item10 := Item(
affixes=[
Affix(name="lucky_hit_chance", value=14.4, type=AffixType.greater),
Expand All @@ -194,10 +194,10 @@
rarity=ItemRarity.Unique,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_10_2160p_medium.png", item10),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_10.png", item10),
(
(3840, 2160),
f"{BASE_PATH}/read_descr_11_2160p_medium.png",
f"{BASE_PATH}/2160p_medium_read_descr_11.png",
item11 := Item(
affixes=[
Affix(name="movement_speed", value=19),
Expand All @@ -212,10 +212,10 @@
rarity=ItemRarity.Mythic,
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_11_2160p_small.png", item11),
((3840, 2160), f"{BASE_PATH}/2160p_small_read_descr_11.png", item11),
(
(2160, 1440),
f"{BASE_PATH}/read_descr_1_1440p_small.png",
f"{BASE_PATH}/1440p_small_read_descr_1.png",
Item(
affixes=[
Affix(name="all_stats", value=3),
Expand All @@ -232,7 +232,7 @@
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_1_1080p_small.png",
f"{BASE_PATH}/1080p_small_read_descr_1.png",
Item(
affixes=[
Affix(name="intelligence", value=87),
Expand All @@ -249,7 +249,24 @@
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_2_1080p_medium.png",
f"{BASE_PATH}/1080p_small_read_descr_2.png",
Item(
affixes=[
Affix(name="movement_speed", value=23.1),
Affix(name="maximum_resistance_to_all_elements", value=8.6),
Affix(name="resistance_to_all_elements", value=69),
Affix(name="damage_reduction", value=23),
],
aspect=Aspect(name="tyraels_might", value=5213),
inherent=[Affix(name="ignore_durability_loss", value=None, type=AffixType.inherent)],
item_type=ItemType.ChestArmor,
power=925,
rarity=ItemRarity.Mythic,
),
),
(
(1920, 1080),
f"{BASE_PATH}/1080p_medium_read_descr_1.png",
Item(
affixes=[
Affix(name="strength", value=77),
Expand Down
15 changes: 0 additions & 15 deletions tests/item/read_descr_unknown_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@
rarity=ItemRarity.Legendary,
),
),
(
(2560, 1440),
f"{BASE_PATH}/unknown/read_descr_legendary_1440p_2.png",
Item(
affixes=[
Affix(name="intelligence", value=178),
Affix(name="life_on_hit", value=38),
Affix(name="lucky_hit_up_to_a_chance_to_restore_primary_resource", value=19),
],
inherent=[Affix(name="life_on_kill", value=228, type=AffixType.inherent)],
item_type=ItemType.Scythe2H,
power=925,
rarity=ItemRarity.Legendary,
),
),
(
(2560, 1440),
f"{BASE_PATH}/unknown/read_descr_legendary_1440p_3.png",
Expand Down

0 comments on commit 0038140

Please sign in to comment.