Skip to content

Commit

Permalink
Fixed sigils & added new materials (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro authored Oct 13, 2024
1 parent 6de0b14 commit 7806332
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/actions/setup_env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ runs:
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"

- name: Install dependencies
shell: powershell
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/enUS/sigils.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
},
"positive": {
"": " after attacking an enemy, your thorns are increased by for seconds, up to at max stacks.",
"ancestors_favor": "ancestors favor extra lunar shrines and more glyph experience earned at the end of this dungeon.",
"ancestors_favor": "ancestors favor you earn more experience while within this dungeon",
"ancestral_awakening": "ancestral awakening you earn more glyph experience at the end of this dungeon.",
"battle_hardened": "battle hardened gain damage reduction for every health you are missing.",
"control_impaired_explosions": "control impaired explosions being hit by control impairing effects creates an explosion around you.",
Expand Down
3 changes: 1 addition & 2 deletions assets/lang/enUS/tooltips.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"ItemPower": "item power",
"ItemTier": "tier"
"ItemPower": "item power"
}
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.8.3"
__version__ = "5.8.4"
25 changes: 7 additions & 18 deletions src/item/descr/item_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ def read_item_type_and_rarity(
if found_rarity:
item.rarity = found_rarity

if "sigil" in concatenated_str and Dataloader().tooltips["ItemTier"] in concatenated_str:
if "sigil" in concatenated_str:
item.item_type = ItemType.Sigil
elif any(
substring in concatenated_str.lower()
for substring in [
"consumable",
"grand cache",
"reputation cache",
"rune of",
"treasure goblin cache",
"tribute of",
"whispering key",
]
):
Expand All @@ -47,9 +49,7 @@ def read_item_type_and_rarity(
if item.rarity == ItemRarity.Common:
return item, concatenated_str

if item.item_type == ItemType.Sigil:
item.power = _find_sigil_tier(concatenated_str)
else:
if item.item_type != ItemType.Sigil:
item = _find_item_power_and_type(item, concatenated_str)
if item.item_type is None:
masked_red, _ = color_filter(crop_top, COLORS.unusable_red, False)
Expand All @@ -58,7 +58,9 @@ def read_item_type_and_rarity(
item = _find_item_power_and_type(item, concatenated_str)

non_magic_or_sigil = item.rarity != ItemRarity.Magic or item.item_type == ItemType.Sigil
power_or_type_bad = (item.power is None and item.item_type not in [ItemType.Elixir, ItemType.TemperManual]) or item.item_type is None
power_or_type_bad = (
item.power is None and item.item_type not in [ItemType.Elixir, ItemType.Sigil, ItemType.TemperManual]
) or item.item_type is None
if non_magic_or_sigil and power_or_type_bad:
return None, concatenated_str

Expand Down Expand Up @@ -102,19 +104,6 @@ def _find_item_power_and_type(item: Item, concatenated_str: str) -> Item:
return item


def _find_sigil_tier(concatenated_str: str) -> int | None:
for error, correction in Dataloader().error_map.items():
concatenated_str = concatenated_str.replace(error, correction)
if Dataloader().tooltips["ItemTier"] in concatenated_str:
idx = concatenated_str.index(Dataloader().tooltips["ItemTier"])
split_words = concatenated_str[idx:].split()
if len(split_words) == 2:
following_word = split_words[1]
if following_word.isdigit():
return int(following_word)
return None


def _find_item_rarity(concatenated_str: str) -> ItemRarity | None:
for rarity in ItemRarity:
if rarity.value in concatenated_str:
Expand Down
3 changes: 3 additions & 0 deletions src/tools/data/custom_sigils_enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
},
"major": {
"the_beast_in_ice": "the beast in ice imprisoned no longer, face the beast in ice in its frozen cave."
},
"positive": {
"ancestors_favor": "ancestors favor you earn more experience while within this dungeon"
}
}
2 changes: 0 additions & 2 deletions src/tools/gen_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ def main(d4data_dir: Path, companion_app_dir: Path):
for arString in data["arStrings"]:
if arString["szLabel"] == "ItemPower":
tooltip_dict["ItemPower"] = remove_content_in_braces(check_ms(arString["szText"].lower()))
if arString["szLabel"] == "ItemTier":
tooltip_dict["ItemTier"] = remove_content_in_braces(check_ms(arString["szText"].lower()))
with open(D4LF_BASE_DIR / f"assets/lang/{language}/tooltips.json", "w", encoding="utf-8") as json_file:
json.dump(tooltip_dict, json_file, indent=4, ensure_ascii=False, sort_keys=True)
json_file.write("\n")
Expand Down
Binary file removed tests/assets/item/season5/1440p_small_sigil_1.png
Binary file not shown.
Binary file removed tests/assets/item/season5/1440p_small_sigil_2.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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 0 additions & 30 deletions tests/item/read_descr_season5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,31 +377,6 @@
),
]

sigil = [
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_sigil_1.png",
Item(
affixes=[Affix(name="quick_killer"), Affix(name="empowered_elites_poison_enchanted")],
inherent=[Affix(name="sanguine_chapel", type=AffixType.inherent)],
item_type=ItemType.Sigil,
power=41,
rarity=ItemRarity.Common,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_sigil_2.png",
Item(
affixes=[Affix(name="extra_shrines"), Affix(name="stormbanes_wrath")],
inherent=[Affix(name="buried_halls", type=AffixType.inherent)],
item_type=ItemType.Sigil,
power=23,
rarity=ItemRarity.Common,
),
),
]


def _run_test_helper(img_res: tuple[int, int], input_img: str, expected_item: Item):
Cam().update_window_pos(0, 0, *img_res)
Expand All @@ -413,8 +388,3 @@ def _run_test_helper(img_res: tuple[int, int], input_img: str, expected_item: It
@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), items)
def test_item(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)


@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), sigil)
def test_sigil(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)
110 changes: 110 additions & 0 deletions tests/item/read_descr_season6_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import cv2
import pytest

from src.cam import Cam
from src.config import BASE_DIR
from src.item.data.affix import Affix, AffixType
from src.item.data.item_type import ItemType
from src.item.data.rarity import ItemRarity
from src.item.descr.read_descr import read_descr
from src.item.models import Item

BASE_PATH = BASE_DIR / "tests/assets/item/season6"

items = []

materials = [
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_compass_1.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Common,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_rune_magic_1.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Magic,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_rune_magic_2.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Magic,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_rune_rare_1.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Rare,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_rune_rare_2.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Rare,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_tribute_magic_1.png",
Item(
item_type=ItemType.Material,
rarity=ItemRarity.Magic,
),
),
]

sigils = [
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_sigil_1.png",
Item(
affixes=[Affix(name="ancestors_favor"), Affix(name="monster_barrier")],
inherent=[Affix(name="carrion_fields", type=AffixType.inherent)],
item_type=ItemType.Sigil,
rarity=ItemRarity.Common,
),
),
(
(2560, 1440),
f"{BASE_PATH}/1440p_small_sigil_2.png",
Item(
affixes=[Affix(name="ancestors_favor"), Affix(name="monster_barrier")],
inherent=[Affix(name="whispering_pines", type=AffixType.inherent)],
item_type=ItemType.Sigil,
rarity=ItemRarity.Common,
),
),
]


def _run_test_helper(img_res: tuple[int, int], input_img: str, expected_item: Item):
Cam().update_window_pos(0, 0, *img_res)
img = cv2.imread(input_img)
item = read_descr(expected_item.rarity, img)
assert item == expected_item


@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), items)
def test_item(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)


@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), materials)
def test_materials(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)


@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), sigils)
def test_sigils(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)

0 comments on commit 7806332

Please sign in to comment.