国服特色数据修正
This commit is contained in:
@@ -8,7 +8,13 @@ import redis
|
||||
|
||||
from api.core.Gzip import gzip_zip
|
||||
from api.utils.skill_detail import SKILL_DETAIL_NORMALIZE_VERSION, normalize_skill_detail
|
||||
from api.utils.skill_tree import SKILL_TREE_WITH_DESC_SPECIAL_VERSION, load_skill_tree_with_desc_special
|
||||
from api.utils.openapi_data import logical_skill_detail_prefix
|
||||
from api.utils.skill_tree import (
|
||||
SKILL_TREE_NAME_MAP_VERSION,
|
||||
SKILL_TREE_WITH_DESC_SPECIAL_VERSION,
|
||||
load_skill_tree_name_map,
|
||||
load_skill_tree_with_desc_special,
|
||||
)
|
||||
from core.basic.character import createCharacter
|
||||
from core.basic.equipment import get_equipment
|
||||
from core.character.adventure import adv, get_adv_list
|
||||
@@ -19,7 +25,6 @@ PreheatLoader = Callable[[], object]
|
||||
PreheatTask = tuple[str, PreheatLoader]
|
||||
PREHEAT_LOCK_KEY = 'dcalc_sys:preheat:lock'
|
||||
PREHEAT_LOCK_EXPIRE_SECONDS = 15 * 60
|
||||
SKILL_DETAIL_PARTS = ('cn', 'skillDetail')
|
||||
|
||||
|
||||
def _load_skills():
|
||||
@@ -56,12 +61,11 @@ def _build_character_preheat_tasks(equ_version: str = '0') -> list[PreheatTask]:
|
||||
|
||||
def _iter_skill_detail_files() -> list[Path]:
|
||||
data_dir = BACKEND_DIR / 'openapi' / 'data'
|
||||
return sorted(data_dir.glob('*/' + '*/' + '/'.join(SKILL_DETAIL_PARTS) + '/*.json'))
|
||||
return sorted(data_dir.glob('cn/*/*/skillDetail/*.json'))
|
||||
|
||||
|
||||
def _skill_prefix_from_path(path: Path) -> str:
|
||||
relative = path.relative_to(BACKEND_DIR / 'openapi' / 'data').with_suffix('')
|
||||
return relative.as_posix()
|
||||
return logical_skill_detail_prefix(path)
|
||||
|
||||
|
||||
def _openapi_skill_detail_key(prefix: str) -> str:
|
||||
@@ -141,16 +145,22 @@ def _build_skill_data_preheat_tasks(custom_cn: list[dict]) -> list[PreheatTask]:
|
||||
def _build_skill_tree_preheat_tasks() -> list[PreheatTask]:
|
||||
tasks: list[PreheatTask] = []
|
||||
data_dir = BACKEND_DIR / 'openapi' / 'data'
|
||||
for path in sorted(data_dir.glob('*/' + '*/cn/skill_tree.json')):
|
||||
for path in sorted(data_dir.glob('cn/*/*/skill_tree.json')):
|
||||
relative = path.relative_to(data_dir)
|
||||
job_id = relative.parts[0]
|
||||
job_grow_id = relative.parts[1]
|
||||
job_id = relative.parts[1]
|
||||
job_grow_id = relative.parts[2]
|
||||
tasks.append(
|
||||
(
|
||||
f'openapi:{SKILL_TREE_WITH_DESC_SPECIAL_VERSION}:{job_id}:{job_grow_id}:skills',
|
||||
lambda job_id=job_id, job_grow_id=job_grow_id: load_skill_tree_with_desc_special(job_id, job_grow_id),
|
||||
)
|
||||
)
|
||||
tasks.append(
|
||||
(
|
||||
f'openapi:{SKILL_TREE_NAME_MAP_VERSION}:{job_id}:{job_grow_id}:nameMap',
|
||||
lambda job_id=job_id, job_grow_id=job_grow_id: load_skill_tree_name_map(job_id, job_grow_id),
|
||||
)
|
||||
)
|
||||
return tasks
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from core.open.helper import get_user_info_by_id, get_user_info_by_role_id, get_
|
||||
from core.open.skillTree import get_skill_tree_info
|
||||
from api.core.exception import ResponseException
|
||||
from api.utils.skill_detail import SKILL_DETAIL_NORMALIZE_VERSION, normalize_skill_detail, skill_detail_for_level
|
||||
from api.utils.openapi_data import openapi_locale_path
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -80,7 +81,7 @@ async def get_skill_info(state: AltersDep, skillId: str, level: int, redis: Redi
|
||||
def get_skill_info():
|
||||
# This function should retrieve the skill info based on job and jobGrow
|
||||
# For now, we return a placeholder dictionary
|
||||
with open(f'./openapi/data/{jobId}/{jobGrowId}/cn/skillDetail/{skillId}.json', encoding='utf-8') as f:
|
||||
with open(openapi_locale_path('cn', jobId, jobGrowId, 'skillDetail', f'{skillId}.json'), encoding='utf-8') as f:
|
||||
skill_data = json.load(f)
|
||||
return normalize_skill_detail(skill_data)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from api.core.Response import response
|
||||
from api.core.Redis import get_redis_info
|
||||
from api.dp import RedisDep
|
||||
from api.utils.skill_detail import SKILL_DETAIL_NORMALIZE_VERSION, normalize_skill_detail, skill_detail_for_level
|
||||
from api.utils.openapi_data import openapi_locale_path
|
||||
from api.utils.skill_tree import (
|
||||
SKILL_TREE_WITH_DESC_SPECIAL_VERSION,
|
||||
filter_skill_tree_by_desc_special,
|
||||
@@ -145,7 +146,7 @@ async def get_cn_skill_info(
|
||||
# This function should retrieve the skill info based on job and jobGrow
|
||||
# For now, we return a placeholder dictionary
|
||||
with open(
|
||||
f'./openapi/data/{jobId}/{jobGrowId}/cn/skillDetail/{skillId}.json',
|
||||
openapi_locale_path('cn', jobId, jobGrowId, 'skillDetail', f'{skillId}.json'),
|
||||
encoding='utf-8',
|
||||
) as f:
|
||||
skill_data = json.load(f)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
|
||||
from database.connect import BACKEND_DIR
|
||||
|
||||
|
||||
OPENAPI_DATA_DIR = BACKEND_DIR / 'openapi' / 'data'
|
||||
LOCALES = {'cn', 'kr'}
|
||||
|
||||
|
||||
def openapi_locale_path(locale: str, job_id: str, job_grow_id: str, *parts: str) -> Path:
|
||||
return OPENAPI_DATA_DIR / locale / job_id / job_grow_id / Path(*parts)
|
||||
|
||||
|
||||
def logical_skill_detail_path(prefix: str) -> Path:
|
||||
parts = prefix.split('/')
|
||||
if len(parts) < 5 or parts[2] not in LOCALES:
|
||||
return OPENAPI_DATA_DIR / f'{prefix}.json'
|
||||
|
||||
job_id, job_grow_id, locale = parts[:3]
|
||||
return openapi_locale_path(locale, job_id, job_grow_id, *parts[3:]).with_suffix('.json')
|
||||
|
||||
|
||||
def logical_skill_detail_prefix(path: Path) -> str:
|
||||
relative = path.relative_to(OPENAPI_DATA_DIR).with_suffix('')
|
||||
parts = relative.parts
|
||||
if len(parts) >= 5 and parts[0] in LOCALES:
|
||||
locale, job_id, job_grow_id = parts[:3]
|
||||
return '/'.join((job_id, job_grow_id, locale, *parts[3:]))
|
||||
|
||||
return relative.as_posix()
|
||||
@@ -1,14 +1,30 @@
|
||||
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 = BACKEND_DIR / 'openapi' / 'data' / job_id / job_grow_id / 'cn' / 'skill_tree.json'
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user