Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro committed Aug 13, 2024
1 parent 65b7399 commit 8b24f70
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 332 deletions.
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
- 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
369 changes: 150 additions & 219 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.
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
6 changes: 1 addition & 5 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
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
48 changes: 32 additions & 16 deletions src/tools/data/custom_uniques_enUS.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
{
"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]
}
}
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.
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.
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 @@ -217,6 +217,23 @@
),
),
((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,
),
),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
BASE_PATH = BASE_DIR / "tests/assets/item"

legendary = [
(
(1920, 1080),
f"{BASE_PATH}/unknown/read_descr_codex_upgrade_1080p.png",
Item(
affixes=[Affix(name="intelligence", value=46), Affix(name="maximum_life", value=25), Affix(name="essence_on_kill", value=2)],
codex_upgrade=True,
inherent=[Affix(name="critical_strike_damage", value=9, type=AffixType.inherent)],
item_type=ItemType.Sword2H,
power=254,
rarity=ItemRarity.Legendary,
),
),
(
(2560, 1440),
f"{BASE_PATH}/unknown/read_descr_codex_upgrade_1440p.png",
Expand Down Expand Up @@ -93,22 +81,6 @@
rarity=ItemRarity.Legendary,
),
),
(
(1920, 1080),
f"{BASE_PATH}/unknown/read_descr_legendary_1080p_3.png",
Item(
affixes=[
Affix(name="willpower", value=82),
Affix(name="critical_strike_damage", value=25),
Affix(name="overpower_damage", value=87),
Affix(name="damage_to_close_enemies", value=26),
],
inherent=[Affix(name="overpower_damage", value=75, type=AffixType.inherent)],
item_type=ItemType.Mace2H,
power=704,
rarity=ItemRarity.Legendary,
),
),
(
(1920, 1080),
f"{BASE_PATH}/unknown/read_descr_legendary_1080p_4.png",
Expand All @@ -120,21 +92,6 @@
rarity=ItemRarity.Legendary,
),
),
(
(1920, 1080),
f"{BASE_PATH}/unknown/read_descr_legendary_1080p_5.png",
Item(
affixes=[
Affix(name="maximum_life", value=666),
Affix(name="damage", value=45, type=AffixType.greater),
Affix(name="vulnerable_damage", value=31),
],
inherent=[Affix(name="lucky_hit_chance", value=10.0, type=AffixType.inherent)],
item_type=ItemType.Wand,
power=925,
rarity=ItemRarity.Legendary,
),
),
(
(1920, 1080),
f"{BASE_PATH}/unknown/read_descr_legendary_1080p_7.png",
Expand Down Expand Up @@ -251,23 +208,6 @@
]

sigil = [
(
(2560, 1440),
f"{BASE_PATH}/unknown/read_descr_sigil_1440p.png",
Item(
affixes=[
Affix(name="lightning_damage", value=15),
Affix(name="blood_blister"),
Affix(name="monster_poison_damage", value=30),
Affix(name="monster_critical_resist", value=3),
Affix(name="potion_breakers", value=0.75),
],
inherent=[Affix(name="wretched_delve", type=AffixType.inherent)],
item_type=ItemType.Sigil,
power=89,
rarity=ItemRarity.Common,
),
),
(
(2560, 1440),
f"{BASE_PATH}/unknown/read_descr_sigil_1440p_2.png",
Expand Down

0 comments on commit 8b24f70

Please sign in to comment.