StarRailCopilot/module/config/server.py

60 lines
1.6 KiB
Python
Raw Normal View History

2023-05-14 07:48:34 +00:00
"""
This file stores server, such as 'cn', 'en'.
Use 'import module.config.server as server' to import, don't use 'from xxx import xxx'.
"""
2023-09-08 14:23:57 +00:00
lang = 'cn' # Setting default to cn, will avoid errors when using dev_tools
2023-05-14 07:48:34 +00:00
2023-09-08 14:23:57 +00:00
VALID_LANG = ['cn', 'en']
2023-05-14 07:48:34 +00:00
VALID_PACKAGE = {
'com.miHoYo.hkrpg': 'cn',
'com.HoYoverse.hkrpgoversea': 'oversea'
}
VALID_CHANNEL_PACKAGE = {
'com.miHoYo.hkrpg.bilibili': ('cn', 'Bilibili'),
}
2023-09-08 14:23:57 +00:00
def set_lang(lang_: str):
2023-05-14 07:48:34 +00:00
"""
2023-09-08 14:23:57 +00:00
Change language and this will affect globally,
including assets and language specific methods.
2023-05-14 07:48:34 +00:00
Args:
2023-09-08 14:23:57 +00:00
lang_: package name or server.
2023-05-14 07:48:34 +00:00
"""
2023-09-08 14:23:57 +00:00
global lang
lang = lang_
2023-05-14 07:48:34 +00:00
from module.base.resource import release_resources
release_resources()
def to_server(package_or_server: str) -> str:
"""
Convert package/server to server.
To unknown packages, consider they are a CN channel servers.
"""
if package_or_server in VALID_SERVER:
return package_or_server
elif package_or_server in VALID_PACKAGE:
return VALID_PACKAGE[package_or_server]
elif package_or_server in VALID_CHANNEL_PACKAGE:
return VALID_CHANNEL_PACKAGE[package_or_server][0]
else:
return 'cn'
def to_package(package_or_server: str) -> str:
"""
Convert package/server to package.
"""
package_or_server = package_or_server.lower()
if package_or_server in VALID_PACKAGE:
return package_or_server
for key, value in VALID_PACKAGE.items():
if value == package_or_server:
return key
raise ValueError(f'Server invalid: {package_or_server}')