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

More screen detection improvements #357

Merged
merged 1 commit into from
Aug 13, 2024
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
11 changes: 9 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
# - id: check-added-large-files # Disabled because git-lfs in GH costs?!
- id: check-ast
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
rev: v0.5.7
hooks:
- id: ruff
args: [--fix]
Expand Down
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
Expand Down
374 changes: 153 additions & 221 deletions assets/lang/enUS/uniques.json

Large diffs are not rendered by default.

Binary file modified assets/templates/item_descr/item_mythic_top_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.2"
__version__ = "5.7.3"
12 changes: 3 additions & 9 deletions src/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
LOGGER = logging.getLogger("d4lf")

COLORS = ColorsModel(
aspect_number=HSVRangeModel(h_s_v_min=np.array([90, 60, 200]), h_s_v_max=np.array([150, 100, 255])),
cold_imbued=HSVRangeModel(h_s_v_min=np.array([88, 0, 0]), h_s_v_max=np.array([112, 255, 255])),
legendary_orange=HSVRangeModel(h_s_v_min=np.array([4, 190, 190]), h_s_v_max=np.array([26, 255, 255])),
material_color=HSVRangeModel(h_s_v_min=np.array([86, 110, 190]), h_s_v_max=np.array([114, 220, 255])),
poison_imbued=HSVRangeModel(h_s_v_min=np.array([55, 0, 0]), h_s_v_max=np.array([65, 255, 255])),
shadow_imbued=HSVRangeModel(h_s_v_min=np.array([120, 0, 0]), h_s_v_max=np.array([140, 255, 255])),
skill_cd=HSVRangeModel(h_s_v_min=np.array([5, 61, 38]), h_s_v_max=np.array([16, 191, 90])),
unique_gold=HSVRangeModel(h_s_v_min=np.array([4, 45, 125]), h_s_v_max=np.array([26, 155, 250])),
unusable_red=HSVRangeModel(h_s_v_min=np.array([0, 210, 110]), h_s_v_max=np.array([10, 255, 210])),
)

POSITIONS = (
(3840, 2160),
UiOffsetsModel(
find_bullet_points_width=78,
find_bullet_points_width=150,
find_seperator_short_offset_top=500,
item_descr_line_height=50,
item_descr_off_bottom_edge=104,
item_descr_pad=30,
item_descr_width=774,
item_descr_width=780,
vendor_center_item_x=1232,
),
UiPosModel(
Expand All @@ -56,7 +50,7 @@
window_dimensions=(3840, 2160),
),
UiRoiModel(
rel_descr_search_left=np.array([-910, 0, 120, 1760]),
rel_descr_search_left=np.array([-900, 0, 150, 1760]),
rel_descr_search_right=np.array([60, 0, 120, 1760]),
rel_fav_flag=np.array([8, 6, 16, 20]),
slots_3x11=np.array([2536, 1444, 1214, 486]),
Expand Down
6 changes: 0 additions & 6 deletions src/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,7 @@ def key_must_exist(cls, k: str) -> str:


class ColorsModel(_IniBaseModel):
aspect_number: "HSVRangeModel"
cold_imbued: "HSVRangeModel"
legendary_orange: "HSVRangeModel"
material_color: "HSVRangeModel"
poison_imbued: "HSVRangeModel"
shadow_imbued: "HSVRangeModel"
skill_cd: "HSVRangeModel"
unique_gold: "HSVRangeModel"
unusable_red: "HSVRangeModel"

Expand Down
2 changes: 1 addition & 1 deletion src/item/data/affix.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Affix:
type: AffixType = AffixType.normal
loc: tuple[int, int] = None
text: str = ""
value: float = None
value: float | None = None

def __eq__(self, other: "Affix") -> bool:
if not isinstance(other, Affix):
Expand Down
1 change: 0 additions & 1 deletion src/item/descr/find_aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def find_aspect(img_item_descr: np.ndarray, aspect_bullet: TemplateMatch, do_pre

roi_aspect = find_aspect_search_area(img_item_descr, aspect_bullet)
img_full_aspect = crop(img_item_descr, roi_aspect)
# cv2.imwrite("img_full_aspect.png", img_full_aspect)
concatenated_str = image_to_text(img_full_aspect, do_pre_proc=do_pre_proc).text.lower().replace("\n", " ")
cleaned_str = clean_str(concatenated_str)

Expand Down
2 changes: 2 additions & 0 deletions src/item/descr/item_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def read_item_type(
elif any(
substring in concatenated_str.lower()
for substring in [
"consumable",
"grand cache",
"reputation cache",
"treasure goblin cache",
"whispering key",
]
):
item.item_type = ItemType.Material
Expand Down
11 changes: 4 additions & 7 deletions src/item/descr/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ def _filter_outliers(template_matches: list[TemplateMatch]) -> list[TemplateMatc
return [tm for tm in template_matches if abs(tm.center[0] - target_center_x) < 1.2 * tm.region[2]]


def _gen_roi_bullets(sep_short_match: TemplateMatch, img_height: int):
return [0, sep_short_match.center[1], ResManager().offsets.find_bullet_points_width + 20, img_height]


def _find_bullets(
img_item_descr: np.ndarray, sep_short_match: TemplateMatch, template_list: list[str], threshold: float, mode: str
) -> list[TemplateMatch]:
img_height = img_item_descr.shape[0]
roi_bullets = _gen_roi_bullets(sep_short_match, img_height)
roi_bullets = [0, sep_short_match.center[1], ResManager().offsets.find_bullet_points_width, img_height]
all_bullets = search(
ref=template_list,
inp_img=img_item_descr,
Expand Down Expand Up @@ -65,9 +61,10 @@ def _find_bullets(


def find_affix_bullets(img_item_descr: np.ndarray, sep_short_match: TemplateMatch) -> list[TemplateMatch]:
tempered_icons = [f"tempered_affix_bullet_point_{x}" for x in range(1, 7)]
affix_icons = [f"affix_bullet_point_{x}" for x in range(1, 3)]
template_list = ["greater_affix_bullet_point_1", "rerolled_bullet_point"] + tempered_icons + affix_icons
rerolled_icons = [f"rerolled_bullet_point_{x}" for x in range(1, 3)]
tempered_icons = [f"tempered_affix_bullet_point_{x}" for x in range(1, 7)]
template_list = ["greater_affix_bullet_point_1"] + affix_icons + rerolled_icons + tempered_icons
all_templates = [f"{x}_medium" for x in template_list] + template_list
return _find_bullets(
img_item_descr=img_item_descr,
Expand Down
6 changes: 3 additions & 3 deletions src/item/find_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def find_descr(img: np.ndarray, anchor: tuple[int, int]) -> tuple[bool, ItemRari
roi = [match.region[0] - delta_x, roi_y, item_descr_width + 2 * delta_x, search_height]

refs = ["item_seperator_short_rare", "item_seperator_short_legendary", "item_seperator_short_mythic"]
sep_short = search(refs, img, 0.62, roi, True, mode="first", do_multi_process=False)
sep_short = search(refs, img, 0.8, roi, True, mode="first", do_multi_process=False)

if sep_short.success:
off_bottom_of_descr = ResManager().offsets.item_descr_off_bottom_edge
Expand All @@ -73,7 +73,7 @@ def find_descr(img: np.ndarray, anchor: tuple[int, int]) -> tuple[bool, ItemRari
item_descr_width - 2 * item_descr_pad,
roi_height,
]
croped_descr = crop(img, crop_roi)
return True, rarity, croped_descr, crop_roi
cropped_descr = crop(img, crop_roi)
return True, rarity, cropped_descr, crop_roi

return False, None, None, None
54 changes: 37 additions & 17 deletions src/tools/data/custom_uniques_enUS.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
{
"azurewrath": {
"desc": "lucky hit your skills have up to a chance to freeze enemies for seconds and deal cold damage to them.",
"full": "",
"num_idx": [
1
],
"snoId": 0
"num_idx": [1]
},
"crown_of_lucion": {
"desc": "each time you use a skill with a resource Cost, gain increased damage and resource cost is increased by for seconds, stacking up to times.",
"full": "Each time you use a Skill with a Resource Cost, gain {c_number}[Affix.\"Static Value 0\"]{/c}%[x] increased damage and Resource Cost is increased by 30%[+] for 4 seconds, stacking up to 5 times.",
"num_idx": [
0
],
"snoId": 1944475
},
"num_idx": [0]
},
"endurant_faith": {
"desc": "when you would be damaged for at least of your maximum life at once it is instead",
"num_idx": [2]
},
"eyes_in_the_dark": {
"desc": "death trap deals increased damage and will re-arm itself a second time.",
"full": "{c_important}Death Trap{/c} deals {c_random}[Affix_Value_1|%x|]{/c} increased damage and will re-arm itself a second time.",
"num_idx": [
0
],
"snoId": 942977
}
"num_idx": [0]
},
"locrans_talisman": {
"desc": "your skills gain a critical strike chance bonus",
"num_idx": [0]
},
"rakanoths_wake": {
"desc": "when you cast a skill with a cooldown you explode dealing fire damage",
"num_idx": [0]
},
"shard_of_verathiel": {
"desc": "basic skills deal increased damage but additionally cost primary resource",
"num_idx": [0]
},
"the_basilisk": {
"desc": "when you first hit an enemy with an earth skill petrify them for seconds",
"num_idx": [1]
},
"the_mortacrux": {
"desc": "when consuming a corpse there is a chance to also create a decaying",
"num_idx": [0]
},
"the_third_blade": {
"desc": "your weapon mastery skills are now also core skills that have no cooldowns but",
"num_idx": [0]
},
"vox_omnium": {
"desc": "casting a core skill additionally fire instances of fire bolt frost bolt or spark",
"num_idx": [2]
}
}
3 changes: 1 addition & 2 deletions src/tools/gen_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def main(d4data_dir: Path, companion_app_dir: Path):
for json_file in json_files:
with open(json_file, encoding="utf-8") as file:
data = json.load(file)
snoId = data["__snoID__"]
name_item = [item for item in data["arStrings"] if item["szLabel"] == "Name"]
if not name_item:
continue
Expand All @@ -95,7 +94,7 @@ def main(d4data_dir: Path, companion_app_dir: Path):
desc = data["arStrings"][0]["szText"]
desc_clean = remove_content_in_braces(desc.lower().replace("’", ""))
num_idx = get_random_number_idx(desc)
unique_dict[name_clean] = {"desc": desc_clean, "snoId": snoId, "full": desc, "num_idx": num_idx}
unique_dict[name_clean] = {"desc": desc_clean, "full": desc, "num_idx": num_idx}
# add custom uniques that seem to be missing
with open(D4LF_BASE_DIR / f"src/tools/data/custom_uniques_{language}.json", encoding="utf-8") as json_file:
data = json.load(json_file)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/assets/item/unknown/find_descr_magic_2160p.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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) == 46
assert len(ResManager().templates) == 48
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
@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, (2164, 109), ItemRarity.Mythic),
((3840, 2160), f"{BASE_PATH}/find_descr_mythic_2160p.png", (3017, 1560), True, (2230, 200), ItemRarity.Mythic),
],
)
def test_find_descr(img_res, input_img, anchor, expected_success, expected_top_left, expected_rarity):
Cam().update_window_pos(0, 0, *img_res)
img = cv2.imread(input_img)
success, item_rarity, cropped_img, roi = find_descr(img, anchor)
top_left_corner = None if not success else roi[:2]
if False:
cv2.imwrite("item_descr.png", cropped_img)
assert success == expected_success
tolerance = 0.01 * img_res[0]
assert abs(top_left_corner[0] - expected_top_left[0]) <= tolerance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
((1920, 1080), f"{BASE_PATH}/find_descr_common_1080p.png", (75, 320), True, (127, 157), ItemRarity.Common),
((1920, 1080), f"{BASE_PATH}/find_descr_legendary_1080p.png", (1515, 761), True, (1088, 78), ItemRarity.Legendary),
((2560, 1440), f"{BASE_PATH}/find_descr_legendary_1440p.png", (1723, 1012), True, (1156, 296), ItemRarity.Legendary),
((3840, 2160), f"{BASE_PATH}/find_descr_magic_2160p.png", (3258, 1523), True, (2396, 743), ItemRarity.Magic),
],
)
def test_find_descr(img_res, input_img, anchor, expected_success, expected_top_left, expected_rarity):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
Affix(name="lucky_hit_up_to_a_chance_to_stun_for_seconds", value=17.2, type=AffixType.tempered),
Affix(name="to_warmth", value=1, type=AffixType.tempered),
],
inherent=[],
item_type=ItemType.Helm,
power=914,
rarity=ItemRarity.Legendary,
Expand All @@ -42,7 +41,6 @@
Affix(name="lucky_hit_up_to_a_chance_to_stun_for_seconds", value=15.5, type=AffixType.tempered),
Affix(name="to_warmth", value=2, type=AffixType.tempered),
],
inherent=[],
item_type=ItemType.ChestArmor,
power=925,
rarity=ItemRarity.Legendary,
Expand All @@ -60,7 +58,6 @@
Affix(name="lucky_hit_up_to_a_chance_to_stun_for_seconds", value=20.1, type=AffixType.tempered),
Affix(name="shock_critical_strike_damage", value=97.8, type=AffixType.tempered),
],
inherent=[],
item_type=ItemType.Gloves,
power=854,
rarity=ItemRarity.Legendary,
Expand All @@ -78,7 +75,6 @@
Affix(name="to_chain_lightning", value=4),
],
aspect=Aspect(name="axial_conduit", value=0),
inherent=[],
item_type=ItemType.Legs,
power=914,
rarity=ItemRarity.Unique,
Expand Down Expand Up @@ -217,6 +213,54 @@
),
),
((3840, 2160), f"{BASE_PATH}/read_descr_11_2160p_small.png", item11),
(
(2160, 1440),
f"{BASE_PATH}/read_descr_1_1440p_small.png",
Item(
affixes=[
Affix(name="all_stats", value=3),
Affix(name="maximum_resource", value=11),
Affix(name="critical_strike_damage", value=94),
Affix(name="resistance_to_all_elements", value=9),
],
aspect=Aspect(name="locrans_talisman", value=0.19),
inherent=[Affix(name="resistance_to_all_elements", value=25, type=AffixType.inherent)],
item_type=ItemType.Amulet,
power=925,
rarity=ItemRarity.Unique,
),
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_1_1080p_small.png",
Item(
affixes=[
Affix(name="intelligence", value=87),
Affix(name="essence_per_second", value=3, type=AffixType.rerolled),
Affix(name="movement_speed", value=14.5),
Affix(name="lucky_hit_up_to_a_chance_to_freeze_for_seconds", value=13, type=AffixType.tempered),
Affix(name="movement_speed", value=9.5, type=AffixType.tempered),
],
inherent=[Affix(name="attacks_reduce_evades_cooldown_by_seconds", value=1.5, type=AffixType.inherent)],
item_type=ItemType.Boots,
power=925,
rarity=ItemRarity.Legendary,
),
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_2_1080p_medium.png",
Item(
affixes=[
Affix(name="strength", value=77),
Affix(name="armor", value=1290, type=AffixType.rerolled),
Affix(name="critical_strike_chance", value=8),
],
item_type=ItemType.Gloves,
power=794,
rarity=ItemRarity.Legendary,
),
),
]


Expand Down
Loading