Skip to content

Commit

Permalink
First TTS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro committed Jan 20, 2025
1 parent 9d7e626 commit ad525f8
Show file tree
Hide file tree
Showing 42 changed files with 1,499 additions and 655 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 140
IndentWidth: 4
TabWidth: 4
UseTab: Never
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
id: check_beta
shell: powershell
run: |
if ("${{ env.VERSION }}".Contains("beta")) {
if ($env:VERSION -like "*beta*" -or $env:VERSION -like "*alpha*") {
echo "IS_BETA=true" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
} else {
echo "IS_BETA=false" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
.pytest_cache/
.venv
.vs/
/tts/saapi
/tts/x64
__pycache__/
build/
config/bnip/*
Expand Down
16 changes: 15 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
default_install_hook_types: [pre-push]
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
files: \.(cpp|h)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand All @@ -16,10 +22,18 @@ repos:
args: [--autofix, --indent=4, --no-ensure-ascii]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.21
hooks:
- id: mdformat
- repo: https://github.com/google/yamlfmt
rev: v0.15.0
hooks:
- id: yamlfmt
args: [-conf, .yamlfmt.yaml]
70 changes: 0 additions & 70 deletions .vscode/launch.json

This file was deleted.

12 changes: 0 additions & 12 deletions .vscode/settings.json

This file was deleted.

5 changes: 5 additions & 0 deletions .yamlfmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
formatter:
type: basic
eof_newline: true
max_line_length: 120
retain_line_breaks_single: true
133 changes: 83 additions & 50 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def clean_up():

def copy_additional_resources(release_dir: Path):
shutil.copy("README.md", release_dir)
shutil.copy("tts/saapi64.dll", release_dir)
shutil.copytree("assets", release_dir / "assets")


Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
./dependencies/tesserocr-2.7.1-cp313-cp313-win_amd64.whl
beautifultable
colorama
coverage
cryptography
httpx
keyboard
lxml
Expand Down
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.11"
__version__ = "6.0.0alpha2"
2 changes: 2 additions & 0 deletions src/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ def get_base_dir(bundled: bool = False) -> Path:
return Path(__file__).parent.parent.parent


AFFIX_COMPARISON_CHARS = 60

BASE_DIR = get_base_dir(False)
53 changes: 26 additions & 27 deletions src/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
IS_HOTKEY_KEY = "is_hotkey"

DEPRECATED_INI_KEYS = [
"hidden_transparency",
"import_build",
"local_prefs_path",
"move_item_type",
Expand All @@ -29,17 +30,21 @@ class AspectFilterType(enum.StrEnum):
upgrade = enum.auto()


class ComparisonType(enum.StrEnum):
larger = enum.auto()
smaller = enum.auto()


class HandleRaresType(enum.StrEnum):
filter = enum.auto()
ignore = enum.auto()
junk = enum.auto()


class MoveItemsType(enum.StrEnum):
everything = enum.auto()
favorites = enum.auto()
junk = enum.auto()
unmarked = enum.auto()
class ItemRefreshType(enum.StrEnum):
force_with_filter = enum.auto()
force_without_filter = enum.auto()
no_refresh = enum.auto()


class LogLevels(enum.StrEnum):
Expand All @@ -50,21 +55,23 @@ class LogLevels(enum.StrEnum):
critical = enum.auto()


class MoveItemsType(enum.StrEnum):
everything = enum.auto()
favorites = enum.auto()
junk = enum.auto()
unmarked = enum.auto()


class UnfilteredUniquesType(enum.StrEnum):
favorite = enum.auto()
ignore = enum.auto()
junk = enum.auto()


class ComparisonType(enum.StrEnum):
larger = enum.auto()
smaller = enum.auto()


class ItemRefreshType(enum.StrEnum):
force_with_filter = enum.auto()
force_without_filter = enum.auto()
no_refresh = enum.auto()
class UseTTSType(enum.StrEnum):
full = enum.auto()
mixed = enum.auto()
off = enum.auto()


class _IniBaseModel(BaseModel):
Expand Down Expand Up @@ -247,15 +254,16 @@ class GeneralModel(_IniBaseModel):
default=UnfilteredUniquesType.favorite,
description="What should be done with uniques that do not match any profile. Mythics are always favorited. If mark_as_favorite is unchecked then uniques that match a profile will not be favorited.",
)
hidden_transparency: float = Field(
default=0.35, description="Transparency of the overlay when not hovering it (has a 3 second delay after hovering)"
)
keep_aspects: AspectFilterType = Field(
default=AspectFilterType.upgrade, description="Whether to keep aspects that didn't match a filter"
)
language: str = Field(
default="enUS", description="Do not change. Only English is supported at this time", json_schema_extra={HIDE_FROM_GUI_KEY: "True"}
)
mark_as_favorite: bool = Field(
default=True,
description="Whether to favorite matched items or not",
)
minimum_overlay_font_size: int = Field(
default=12,
description="The minimum font size for the vision overlay, specifically the green text that shows which filter(s) are matching.",
Expand All @@ -268,17 +276,14 @@ class GeneralModel(_IniBaseModel):
default=[MoveItemsType.everything],
description="When doing stash/inventory transfer, what types of items should be moved",
)
mark_as_favorite: bool = Field(
default=True,
description="Whether to favorite matched items or not",
)
profiles: list[str] = Field(
default=[],
description='Which filter profiles should be run. All .yaml files with "Aspects" and '
'"Affixes" sections will be used from '
"C:/Users/USERNAME/.d4lf/profiles/*.yaml",
)
run_vision_mode_on_startup: bool = Field(default=True, description="Whether to run vision mode on startup or not")
use_tts: UseTTSType = Field(default=UseTTSType.off, description="Whether to use tts or not")

@field_validator("check_chest_tabs", mode="before")
def check_chest_tabs_index(cls, v: str) -> list[int]:
Expand All @@ -302,12 +307,6 @@ def language_must_exist(cls, v: str) -> str:
raise ValueError("language not supported")
return v

@field_validator("hidden_transparency")
def transparency_in_range(cls, v: float) -> float:
if not 0 <= v <= 1:
raise ValueError("must be in [0, 1]")
return v

@field_validator("minimum_overlay_font_size")
def font_size_in_range(cls, v: int) -> int:
if not 10 <= v <= 20:
Expand Down
4 changes: 2 additions & 2 deletions src/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import threading

from src.config import BASE_DIR
from src.config import AFFIX_COMPARISON_CHARS, BASE_DIR
from src.config.loader import IniConfigLoader
from src.item.data.item_type import ItemType

Expand Down Expand Up @@ -67,5 +67,5 @@ def load_data(self):
with open(BASE_DIR / f"assets/lang/{IniConfigLoader().general.language}/uniques.json", encoding="utf-8") as f:
data = json.load(f)
for key, d in data.items():
self.aspect_unique_dict[key] = d["desc"][:60]
self.aspect_unique_dict[key] = d["desc"][:AFFIX_COMPARISON_CHARS]
self.aspect_unique_num_idx[key] = d["num_idx"]
10 changes: 5 additions & 5 deletions src/gui/importer/maxroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def import_maxroll(url: str):
for item_id in active_profile["items"].values():
item_filter = ItemFilterModel()
resolved_item = items[str(item_id)]
if (item_type := _find_item_type(mapping_data=mapping_data["items"], value=resolved_item["id"])) is None:
LOGGER.error("Couldn't find item type")
return
item_filter.itemType = [item_type]
# magic/rare = 0, legendary = 1, unique = 2, mythic = 4
if resolved_item["id"] in mapping_data["items"] and mapping_data["items"][resolved_item["id"]]["magicType"] in [2, 4]:
unique_model = UniqueModel()
Expand All @@ -69,10 +73,6 @@ def import_maxroll(url: str):
except Exception:
LOGGER.exception(f"Unexpected error importing unique {unique_name}, please report a bug.")
continue
if (item_type := _find_item_type(mapping_data=mapping_data["items"], value=resolved_item["id"])) is None:
LOGGER.error("Couldn't find item type")
return
item_filter.itemType = [item_type]
item_filter.affixPool = [
AffixFilterCountModel(
count=[
Expand Down Expand Up @@ -154,7 +154,7 @@ def _find_item_affixes(mapping_data: dict, item_affixes: dict) -> list[Affix]:
else:
if affix["attributes"][0]["param"] == -1460542966 and affix["attributes"][0]["id"] == 1033:
attr_desc = "to core skills"
elif affix["attributes"][0]["param"] == -755407686 and affix["attributes"][0]["id"] == 1034:
elif affix["attributes"][0]["param"] == -755407686 and affix["attributes"][0]["id"] in [1034, 1091]:
attr_desc = "to defensive skills"
elif affix["attributes"][0]["param"] == 746476422 and affix["attributes"][0]["id"] == 1034:
attr_desc = "to mastery skills"
Expand Down
14 changes: 11 additions & 3 deletions src/item/data/affix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ class AffixType(enum.Enum):

@dataclass
class Affix:
name: str
type: AffixType = AffixType.normal
loc: tuple[int, int] = None
max_value: float | None = None
min_value: float | None = None
name: str = ""
text: str = ""
type: AffixType = AffixType.normal
value: float | None = None

def __eq__(self, other: "Affix") -> bool:
if not isinstance(other, Affix):
return False
return self.name == other.name and self.value == other.value and self.type == other.type
return (
self.max_value == other.max_value
and self.min_value == other.min_value
and self.name == other.name
and self.value == other.value
and self.type == other.type
)
Loading

0 comments on commit ad525f8

Please sign in to comment.