Files
dcalc/backend/api/utils/skill_tree.py
T
2026-06-28 00:09:17 +08:00

59 lines
2.1 KiB
Python

import json
from functools import cache
from pathlib import Path
from api.utils.openapi_data import openapi_locale_path
from database.connect import BACKEND_DIR
SKILL_TREE_WITH_DESC_SPECIAL_VERSION = 'skillTreeWithDescSpecial:v1'
SKILL_TREE_NAME_MAP_VERSION = 'skillTreeNameMap:v1'
@cache
def load_skill_tree_name_map(job_id: str, job_grow_id: str) -> dict[str, str]:
skill_tree_path = openapi_locale_path('cn', job_id, job_grow_id, 'skill_tree.json')
with skill_tree_path.open(encoding='utf-8') as file:
skills_data = json.load(file)
return {
str(skill['id']): skill['name']
for skill in skills_data
if skill.get('id') is not None and skill.get('name') is not None
}
def load_skill_tree_with_desc_special(job_id: str, job_grow_id: str) -> list[dict]:
skill_tree_path = openapi_locale_path('cn', job_id, job_grow_id, 'skill_tree.json')
detail_dir = skill_tree_path.parent / 'skillDetail'
with skill_tree_path.open(encoding='utf-8') as file:
skills_data = json.load(file)
for skill in skills_data:
skill_id = skill.get('skillId')
desc_special = None
if skill_id:
detail_path = detail_dir / f'{skill_id}.json'
if detail_path.exists():
with detail_path.open(encoding='utf-8') as file:
skill_data = json.load(file)
desc_special = skill_data.get('descSpecial')
optionDesc = skill_data.get('levelInfo', {}).get('optionDesc','')
if optionDesc and '压制力' in optionDesc and not any(desc in (desc_special or []) for desc in ['压制', '压制力']):
desc_special = (desc_special or []) + ['压制']
skill['descSpecial'] = desc_special
return skills_data
def filter_skill_tree_by_desc_special(skills_data: list[dict], desc_special: str) -> list[dict]:
if not desc_special:
return skills_data
return [
skill
for skill in skills_data
if any(desc_special in item for item in (skill.get('descSpecial') or []))
]