Skip to content

Commit

Permalink
🍱 使用本地资源进行面板更新 (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Nov 21, 2024
1 parent eeba069 commit 17c0250
Show file tree
Hide file tree
Showing 9 changed files with 5,750 additions and 1,031 deletions.
12 changes: 8 additions & 4 deletions GenshinUID/genshinuid_enka/to_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from typing import Dict, List, Union, Literal, Optional

import aiofiles
from httpx import ReadTimeout, ConnectTimeout
from httpx import ReadTimeout
from gsuid_core.utils.error_reply import UID_HINT
from gsuid_core.utils.api.enka.models import EnkaData
from gsuid_core.utils.api.enka.request import get_enka_info
from gsuid_core.utils.api.minigg.request import get_weapon_info

from .mono.Character import Character
from ..utils.api.cv.request import _CvApi
Expand All @@ -31,6 +30,9 @@
avatarName2Element,
)

# from gsuid_core.utils.api.minigg.request import get_weapon_info


PROP_ATTR_MAP = {
'Anemo': '44',
'Cryo': '46',
Expand Down Expand Up @@ -316,10 +318,12 @@ async def enka_to_dict(
weapon_info['weaponStats'].append(weapon_prop_temp)

# 武器特效,须请求API
'''
try:
effect_raw = await get_weapon_info(weapon_info['weaponName'])
except ConnectTimeout:
effect_raw = await convert_ambr_to_weapon(weapon_info['itemId'])
except: # noqa
'''
effect_raw = await convert_ambr_to_weapon(weapon_info['itemId'])

if (
not isinstance(effect_raw, List)
Expand Down
46 changes: 44 additions & 2 deletions GenshinUID/tools/data_to_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@
)

from ..version import Genshin_version # noqa: E402
from ..utils.ambr_to_minigg import convert_ambr_to_minigg # noqa: E402
from ..utils.ambr_to_minigg import ( # noqa: E402
get_ambr_char_data,
get_ambr_weapon_data,
convert_ambr_to_minigg,
)

R_PATH = Path(__file__).parents[0]
MAP_PATH = Path(__file__).parents[1] / 'utils' / 'map' / 'data'
DATA_PATH = R_PATH / 'gs_data'
CHAR_PATH = DATA_PATH / 'char'
WEAPON_PATH = DATA_PATH / 'weapon'
WEAPON_TYPE = {
'WEAPON_POLE': '长柄武器',
'WEAPON_BOW': '弓',
Expand All @@ -54,14 +60,17 @@

version = Genshin_version
raw_data = {}

weaponList = {}

BETA_CHAR = {
'10000100': '卡齐娜',
'10000101': '基尼奇',
'10000102': '玛拉妮',
}

CHAR_PATH.mkdir(exist_ok=True)
WEAPON_PATH.mkdir(exist_ok=True)


async def weaponId2Name():
result = {}
Expand Down Expand Up @@ -318,6 +327,7 @@ async def avatarName2ElementJson() -> None:
data = await convert_ambr_to_minigg(_id)
except json.decoder.JSONDecodeError:
data = await convert_ambr_to_minigg(_id)

if data is not None and 'code' not in data:
temp[name] = elementMap[data['elementText']]
try:
Expand Down Expand Up @@ -492,6 +502,7 @@ async def artifact2attrJson() -> None:


async def restore_hakush_data():
global weaponList
data = await get_hakush_char_list()
data2 = await get_hakush_weapon_list()

Expand All @@ -501,6 +512,8 @@ async def restore_hakush_data():
with open(MAP_PATH / weaponList_fileName, 'w', encoding='UTF-8') as f:
json.dump(data2, f, ensure_ascii=False)

weaponList = data2


async def restore_mysData():
base_url = 'https://api-takumi.mihoyo.com'
Expand All @@ -509,7 +522,33 @@ async def restore_mysData():
json.dump(resp.json(), f, ensure_ascii=False)


async def save_all_weapon_data():
global weaponList
if not weaponList:
with open(MAP_PATH / weaponList_fileName, 'r', encoding='UTF-8') as f:
weaponList = json.load(f)

for i in weaponList:
print(i)
data = await get_ambr_weapon_data(i)
if data:
with open(WEAPON_PATH / f'{i}.json', 'w', encoding='UTF-8') as f:
json.dump(data, f, ensure_ascii=False)


async def save_all_char_data():
with open(MAP_PATH / charList_fileName, 'r', encoding='UTF-8') as f:
charList = json.load(f)

for i in charList:
print(i)
rdata = await get_ambr_char_data(i)
with open(CHAR_PATH / f'{i}.json', 'w', encoding='UTF-8') as f:
json.dump(rdata, f, ensure_ascii=False)


async def main():
'''
await download_new_file()
await restore_mysData()
await restore_hakush_data()
Expand All @@ -529,6 +568,9 @@ async def main():
await artifact2attrJson()
await weaponId2Name()
await avatarId2SkillGroupList()
'''
await save_all_weapon_data()
await save_all_char_data()


asyncio.run(main())
109 changes: 68 additions & 41 deletions GenshinUID/utils/ambr_to_minigg.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import re
import json
from typing import List, Union, Optional, TypedDict, cast

import aiofiles
from gsuid_core.utils.api.minigg.models import CharacterTalents
from gsuid_core.utils.api.ambr.request import (
get_ambr_char_data,
get_ambr_weapon_data,
)

from .map.grow_curve import GROW_CURVE_LIST, WEAPON_GROW_CURVE
from ..utils.resource.RESOURCE_PATH import CHAR_DATA_PATH, WEAPON_DATA_PATH

PROP_MAP = {
'FIGHT_PROP_BASE_HP': '基础生命值',
Expand Down Expand Up @@ -111,12 +114,73 @@ class ConvertCharacter(TypedDict):
defense: float


async def convert_exist_data_to_char(
char_id: Union[str, int]
) -> ConvertCharacter:
path = CHAR_DATA_PATH / f'{char_id}.json'
if path.exists():
async with aiofiles.open(path, 'r', encoding='utf-8') as f:
raw_data = json.loads(await f.read())
else:
raw_data = await get_ambr_char_data(char_id)
if raw_data is None:
raise Exception('[AmbrData] 未找到该角色/数据无法下载!')
# 保存
async with aiofiles.open(path, 'w', encoding='utf-8') as f:
await f.write(json.dumps(raw_data))

result = {
'name': raw_data['name'],
'title': raw_data['fetter']['title'],
'rarity': raw_data['rank'],
'weapontype': WEAPON_TYPE[raw_data['weaponType']],
'elementText': ELEMENT_MAP[raw_data['element']],
'element': ELEMENT_MAP[raw_data['element']],
'images': {'namesideicon': raw_data['icon']}, # 暂时适配
'substatText': PROP_MAP[
list(raw_data['upgrade']['promote'][-1]['addProps'].keys())[-1]
],
'hp': raw_data['upgrade']['prop'][0]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][0]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps']['FIGHT_PROP_BASE_HP'],
'attack': raw_data['upgrade']['prop'][1]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][1]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps'][
'FIGHT_PROP_BASE_ATTACK'
],
'defense': raw_data['upgrade']['prop'][2]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][2]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps'][
'FIGHT_PROP_BASE_DEFENSE'
],
'specialized': raw_data['upgrade']['promote'][-1]['addProps'][
list(raw_data['upgrade']['promote'][-1]['addProps'].keys())[-1]
],
}
return cast(ConvertCharacter, result)


async def convert_ambr_to_weapon(
weapon_id: Union[int, str]
) -> Optional[ConvertWeapon]:
raw_data = await get_ambr_weapon_data(weapon_id)
if raw_data is None:
return None
path = WEAPON_DATA_PATH / f'{weapon_id}.json'
if path.exists():
async with aiofiles.open(path, 'r', encoding='utf-8') as f:
raw_data = json.loads(await f.read())
else:
raw_data = await get_ambr_weapon_data(weapon_id)
if raw_data is None:
raise Exception('[AmbrData] 未找到该武器/数据无法下载!')
# 保存
async with aiofiles.open(path, 'w', encoding='utf-8') as f:
await f.write(json.dumps(raw_data))

if raw_data['affix'] is None:
effect = {
'name': '无特效',
Expand Down Expand Up @@ -176,44 +240,7 @@ async def convert_ambr_to_weapon(
async def convert_ambr_to_minigg(
char_id: Union[str, int]
) -> Optional[ConvertCharacter]:
raw_data = await get_ambr_char_data(char_id)
if raw_data is None:
return
result = {
'name': raw_data['name'],
'title': raw_data['fetter']['title'],
'rarity': raw_data['rank'],
'weapontype': WEAPON_TYPE[raw_data['weaponType']],
'elementText': ELEMENT_MAP[raw_data['element']],
'element': ELEMENT_MAP[raw_data['element']],
'images': {'namesideicon': raw_data['icon']}, # 暂时适配
'substatText': PROP_MAP[
list(raw_data['upgrade']['promote'][-1]['addProps'].keys())[-1]
],
'hp': raw_data['upgrade']['prop'][0]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][0]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps']['FIGHT_PROP_BASE_HP'],
'attack': raw_data['upgrade']['prop'][1]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][1]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps'][
'FIGHT_PROP_BASE_ATTACK'
],
'defense': raw_data['upgrade']['prop'][2]['initValue']
* GROW_CURVE_LIST[89]['curveInfos'][
TYPE_TO_INT[raw_data['upgrade']['prop'][2]['type']]
]['value']
+ raw_data['upgrade']['promote'][-1]['addProps'][
'FIGHT_PROP_BASE_DEFENSE'
],
'specialized': raw_data['upgrade']['promote'][-1]['addProps'][
list(raw_data['upgrade']['promote'][-1]['addProps'].keys())[-1]
],
}
return cast(ConvertCharacter, result)
return await convert_exist_data_to_char(char_id)


async def convert_ambr_to_talent(
Expand Down
2 changes: 1 addition & 1 deletion GenshinUID/utils/map/data/charList_5.2.0.json

Large diffs are not rendered by default.

Loading

0 comments on commit 17c0250

Please sign in to comment.