mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-25 18:05:26 +00:00
Refactor: Game server configuration and timezones
This commit is contained in:
parent
cb5aa5c949
commit
194e4df4fe
@ -11,9 +11,12 @@
|
||||
"value": "auto",
|
||||
"option": [
|
||||
"auto",
|
||||
"com.miHoYo.hkrpg",
|
||||
"com.HoYoverse.hkrpgoversea",
|
||||
"com.miHoYo.hkrpg.bilibili"
|
||||
"CN-Official",
|
||||
"CN-Bilibili",
|
||||
"OVERSEA-America",
|
||||
"OVERSEA-Asia",
|
||||
"OVERSEA-Europe",
|
||||
"OVERSEA-TWHKMO"
|
||||
]
|
||||
},
|
||||
"GameLanguage": {
|
||||
|
@ -17,7 +17,7 @@ class GeneratedConfig:
|
||||
|
||||
# Group `Emulator`
|
||||
Emulator_Serial = 'auto'
|
||||
Emulator_PackageName = 'auto' # auto, com.miHoYo.hkrpg, com.HoYoverse.hkrpgoversea, com.miHoYo.hkrpg.bilibili
|
||||
Emulator_PackageName = 'auto' # auto, CN-Official, CN-Bilibili, OVERSEA-America, OVERSEA-Asia, OVERSEA-Europe, OVERSEA-TWHKMO
|
||||
Emulator_GameLanguage = 'auto' # auto, cn, en
|
||||
Emulator_ScreenshotMethod = 'auto' # auto, ADB, ADB_nc, uiautomator2, aScreenCap, aScreenCap_nc, DroidCast, DroidCast_raw, scrcpy
|
||||
Emulator_ControlMethod = 'MaaTouch' # minitouch, MaaTouch
|
||||
|
@ -4,9 +4,9 @@ from cached_property import cached_property
|
||||
|
||||
from deploy.Windows.utils import DEPLOY_TEMPLATE, poor_yaml_read, poor_yaml_write
|
||||
from module.base.timer import timer
|
||||
from module.config.server import VALID_CHANNEL_PACKAGE, VALID_PACKAGE, to_package
|
||||
from module.config.utils import *
|
||||
from module.config.convert import *
|
||||
from module.config.server import VALID_SERVER
|
||||
from module.config.utils import *
|
||||
|
||||
CONFIG_IMPORT = '''
|
||||
import datetime
|
||||
@ -58,6 +58,8 @@ class ConfigGenerator:
|
||||
options = deep_get(raw, keys=keys, default=[]) + options
|
||||
deep_set(raw, keys=keys, value=options)
|
||||
|
||||
# Insert packages
|
||||
option_add(keys='Emulator.PackageName.option', options=list(VALID_SERVER.keys()))
|
||||
# Insert dungeons
|
||||
from tasks.dungeon.keywords import DungeonList
|
||||
option_add(
|
||||
@ -328,18 +330,18 @@ class ConfigGenerator:
|
||||
deep_load(path, words=data['option'], default=False)
|
||||
|
||||
# Package names
|
||||
for package, server in VALID_PACKAGE.items():
|
||||
path = ['Emulator', 'PackageName', package]
|
||||
if deep_get(new, keys=path) == package:
|
||||
deep_set(new, keys=path, value=server.upper())
|
||||
for package, server_and_channel in VALID_CHANNEL_PACKAGE.items():
|
||||
server, channel = server_and_channel
|
||||
name = deep_get(new, keys=['Emulator', 'PackageName', to_package(server)])
|
||||
if lang == SERVER_TO_LANG[server]:
|
||||
value = f'{name} {channel}渠道服 {package}'
|
||||
else:
|
||||
value = f'{name} {package}'
|
||||
deep_set(new, keys=['Emulator', 'PackageName', package], value=value)
|
||||
# for package, server in VALID_PACKAGE.items():
|
||||
# path = ['Emulator', 'PackageName', package]
|
||||
# if deep_get(new, keys=path) == package:
|
||||
# deep_set(new, keys=path, value=server.upper())
|
||||
# for package, server_and_channel in VALID_CHANNEL_PACKAGE.items():
|
||||
# server, channel = server_and_channel
|
||||
# name = deep_get(new, keys=['Emulator', 'PackageName', to_package(server)])
|
||||
# if lang == SERVER_TO_LANG[server]:
|
||||
# value = f'{name} {channel}渠道服 {package}'
|
||||
# else:
|
||||
# value = f'{name} {package}'
|
||||
# deep_set(new, keys=['Emulator', 'PackageName', package], value=value)
|
||||
# Game server names
|
||||
# for server, _list in VALID_SERVER_LIST.items():
|
||||
# for index in range(len(_list)):
|
||||
@ -534,13 +536,6 @@ class ConfigGenerator:
|
||||
deep_set(self.argument, keys=f'Assignment.Name_{i + 1}.option', value=assignments)
|
||||
deep_set(self.args, keys=f'Assignment.Assignment.Name_{i + 1}.option', value=assignments)
|
||||
|
||||
def insert_package(self):
|
||||
option = deep_get(self.argument, keys='Emulator.PackageName.option')
|
||||
option += list(VALID_PACKAGE.keys())
|
||||
option += list(VALID_CHANNEL_PACKAGE.keys())
|
||||
deep_set(self.argument, keys='Emulator.PackageName.option', value=option)
|
||||
deep_set(self.args, keys='Alas.Emulator.PackageName.option', value=option)
|
||||
|
||||
@timer
|
||||
def generate(self):
|
||||
_ = self.args
|
||||
@ -548,7 +543,6 @@ class ConfigGenerator:
|
||||
_ = self.stored
|
||||
# _ = self.event
|
||||
self.insert_assignment()
|
||||
self.insert_package()
|
||||
# self.insert_server()
|
||||
write_file(filepath_args(), self.args)
|
||||
write_file(filepath_args('menu'), self.menu)
|
||||
|
@ -78,15 +78,18 @@
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "Game Server",
|
||||
"help": "Manual select is required if multiple game clients are installed on emulator",
|
||||
"help": "Can't distinguish different regions of oversea servers, please select the server manually.",
|
||||
"auto": "Auto-detect",
|
||||
"com.miHoYo.hkrpg": "CN",
|
||||
"com.HoYoverse.hkrpgoversea": "OVERSEA",
|
||||
"com.miHoYo.hkrpg.bilibili": "CN com.miHoYo.hkrpg.bilibili"
|
||||
"CN-Official": "[CN]-Official",
|
||||
"CN-Bilibili": "[CN]-Bilibili",
|
||||
"OVERSEA-America": "[OVERSEA]-America",
|
||||
"OVERSEA-Asia": "[OVERSEA]-Asia",
|
||||
"OVERSEA-Europe": "[OVERSEA]-Europe",
|
||||
"OVERSEA-TWHKMO": "[OVERSEA]-TW,HK,MO"
|
||||
},
|
||||
"GameLanguage": {
|
||||
"name": "In-game Text Language",
|
||||
"help": "",
|
||||
"help": "Currently, only Simplified Chinese and English are supported. Please set the text language in game to one of them.",
|
||||
"auto": "Auto-detect",
|
||||
"cn": "简体中文",
|
||||
"en": "English"
|
||||
|
@ -80,9 +80,12 @@
|
||||
"name": "Emulator.PackageName.name",
|
||||
"help": "Emulator.PackageName.help",
|
||||
"auto": "auto",
|
||||
"com.miHoYo.hkrpg": "CN",
|
||||
"com.HoYoverse.hkrpgoversea": "OVERSEA",
|
||||
"com.miHoYo.hkrpg.bilibili": "CN com.miHoYo.hkrpg.bilibili"
|
||||
"CN-Official": "CN-Official",
|
||||
"CN-Bilibili": "CN-Bilibili",
|
||||
"OVERSEA-America": "OVERSEA-America",
|
||||
"OVERSEA-Asia": "OVERSEA-Asia",
|
||||
"OVERSEA-Europe": "OVERSEA-Europe",
|
||||
"OVERSEA-TWHKMO": "OVERSEA-TWHKMO"
|
||||
},
|
||||
"GameLanguage": {
|
||||
"name": "Emulator.GameLanguage.name",
|
||||
|
@ -78,15 +78,18 @@
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "游戏服务器",
|
||||
"help": "模拟器上装有多个游戏客户端时,需要手动选择服务器",
|
||||
"help": "无法区分国际服的不同地区,请手动选择服务器",
|
||||
"auto": "自动检测",
|
||||
"com.miHoYo.hkrpg": "CN",
|
||||
"com.HoYoverse.hkrpgoversea": "OVERSEA",
|
||||
"com.miHoYo.hkrpg.bilibili": "CN Bilibili渠道服 com.miHoYo.hkrpg.bilibili"
|
||||
"CN-Official": "[国服]-官服",
|
||||
"CN-Bilibili": "[国服]-B服 ",
|
||||
"OVERSEA-America": "[国际服]-美洲",
|
||||
"OVERSEA-Asia": "[国际服]-亚洲",
|
||||
"OVERSEA-Europe": "[国际服]-欧洲",
|
||||
"OVERSEA-TWHKMO": "[国际服]-港澳台"
|
||||
},
|
||||
"GameLanguage": {
|
||||
"name": "游戏内文本语言",
|
||||
"help": "",
|
||||
"help": "目前仅支持简体中文和英文,请将游戏内设置文本语言设置为其中的一种",
|
||||
"auto": "自动检测",
|
||||
"cn": "简体中文",
|
||||
"en": "English"
|
||||
|
@ -78,15 +78,18 @@
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "遊戲伺服器",
|
||||
"help": "模擬器上裝有多個遊戲客戶端時,需要手動選擇伺服器",
|
||||
"help": "無法區分國際服的不同地區,請手動選擇伺服器",
|
||||
"auto": "自動檢測",
|
||||
"com.miHoYo.hkrpg": "CN",
|
||||
"com.HoYoverse.hkrpgoversea": "OVERSEA",
|
||||
"com.miHoYo.hkrpg.bilibili": "CN com.miHoYo.hkrpg.bilibili"
|
||||
"CN-Official": "[國服]-官服",
|
||||
"CN-Bilibili": "[國服]-B服 ",
|
||||
"OVERSEA-America": "[國際服]-美洲",
|
||||
"OVERSEA-Asia": "[國際服]-亞洲",
|
||||
"OVERSEA-Europe": "[國際服]-歐洲",
|
||||
"OVERSEA-TWHKMO": "[國際服]-台港澳"
|
||||
},
|
||||
"GameLanguage": {
|
||||
"name": "遊戲內文本語言",
|
||||
"help": "",
|
||||
"help": "目前僅支援簡體中文和英文,請在遊戲內設定文本語言為其中的一種",
|
||||
"auto": "自動檢測",
|
||||
"cn": "简体中文",
|
||||
"en": "English"
|
||||
|
@ -3,15 +3,18 @@ This file stores server, such as 'cn', 'en'.
|
||||
Use 'import module.config.server as server' to import, don't use 'from xxx import xxx'.
|
||||
"""
|
||||
lang = 'cn' # Setting default to cn, will avoid errors when using dev_tools
|
||||
server = 'CN-Official'
|
||||
|
||||
VALID_LANG = ['cn', 'en']
|
||||
VALID_PACKAGE = {
|
||||
'com.miHoYo.hkrpg': 'cn',
|
||||
'com.HoYoverse.hkrpgoversea': 'oversea'
|
||||
}
|
||||
VALID_CHANNEL_PACKAGE = {
|
||||
'com.miHoYo.hkrpg.bilibili': ('cn', 'Bilibili'),
|
||||
VALID_SERVER = {
|
||||
'CN-Official': 'com.miHoYo.hkrpg',
|
||||
'CN-Bilibili': 'com.miHoYo.hkrpg.bilibili',
|
||||
'OVERSEA-America': 'com.HoYoverse.hkrpgoversea',
|
||||
'OVERSEA-Asia': 'com.HoYoverse.hkrpgoversea',
|
||||
'OVERSEA-Europe': 'com.HoYoverse.hkrpgoversea',
|
||||
'OVERSEA-TWHKMO': 'com.HoYoverse.hkrpgoversea',
|
||||
}
|
||||
VALID_PACKAGE = set(list(VALID_SERVER.values()))
|
||||
|
||||
|
||||
def set_lang(lang_: str):
|
||||
@ -34,26 +37,28 @@ 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'
|
||||
# Can't distinguish different regions of oversea servers,
|
||||
# assume it's 'OVERSEA-Asia'
|
||||
if package_or_server == 'com.HoYoverse.hkrpgoversea':
|
||||
return 'OVERSEA-Asia'
|
||||
|
||||
for key, value in VALID_SERVER.items():
|
||||
if value == package_or_server:
|
||||
return key
|
||||
if key == package_or_server:
|
||||
return key
|
||||
|
||||
raise ValueError(f'Package invalid: {package_or_server}')
|
||||
|
||||
|
||||
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():
|
||||
for key, value in VALID_SERVER.items():
|
||||
if value == package_or_server:
|
||||
return key
|
||||
return value
|
||||
if key == package_or_server:
|
||||
return value
|
||||
|
||||
raise ValueError(f'Server invalid: {package_or_server}')
|
||||
|
@ -11,18 +11,13 @@ import module.config.server as server_
|
||||
from module.config.atomicwrites import atomic_write
|
||||
|
||||
LANGUAGES = ['zh-CN', 'en-US', 'ja-JP', 'zh-TW']
|
||||
SERVER_TO_LANG = {
|
||||
'cn': 'zh-CN',
|
||||
'en': 'en-US',
|
||||
'jp': 'ja-JP',
|
||||
'tw': 'zh-TW',
|
||||
}
|
||||
LANG_TO_SERVER = {v: k for k, v in SERVER_TO_LANG.items()}
|
||||
SERVER_TO_TIMEZONE = {
|
||||
'cn': timedelta(hours=8),
|
||||
'en': timedelta(hours=-7),
|
||||
'jp': timedelta(hours=9),
|
||||
'tw': timedelta(hours=8),
|
||||
'CN-Official': timedelta(hours=8),
|
||||
'CN-Bilibili': timedelta(hours=8),
|
||||
'OVERSEA-America': timedelta(hours=-5),
|
||||
'OVERSEA-Asia': timedelta(hours=8),
|
||||
'OVERSEA-Europe': timedelta(hours=1),
|
||||
'OVERSEA-TWHKMO': timedelta(hours=8),
|
||||
}
|
||||
DEFAULT_TIME = datetime(2020, 1, 1, 0, 0)
|
||||
|
||||
@ -395,7 +390,7 @@ def dict_to_kv(dictionary, allow_none=True):
|
||||
|
||||
|
||||
def server_timezone() -> timedelta:
|
||||
return SERVER_TO_TIMEZONE.get(server_.lang, SERVER_TO_TIMEZONE['cn'])
|
||||
return SERVER_TO_TIMEZONE.get(server_.server, SERVER_TO_TIMEZONE['CN-Official'])
|
||||
|
||||
|
||||
def server_time_offset() -> timedelta:
|
||||
|
@ -100,12 +100,15 @@ class Connection(ConnectionAttr):
|
||||
logger.attr('AdbDevice', self.adb)
|
||||
|
||||
# Package
|
||||
self.package = self.config.Emulator_PackageName
|
||||
if self.package == 'auto':
|
||||
if self.config.Emulator_PackageName == 'auto':
|
||||
self.detect_package()
|
||||
else:
|
||||
self.package = server_.to_package(self.config.Emulator_PackageName)
|
||||
# No set_server cause game client and UI language can be different
|
||||
# else:
|
||||
# set_server(self.package)
|
||||
logger.attr('Server', self.config.Emulator_PackageName)
|
||||
server_.server = self.config.Emulator_PackageName
|
||||
logger.attr('PackageName', self.package)
|
||||
server_.lang = self.config.Emulator_GameLanguage
|
||||
logger.attr('Lang', self.config.LANG)
|
||||
@ -830,25 +833,24 @@ class Connection(ConnectionAttr):
|
||||
packages = re.findall(r'package:([^\s]+)', output)
|
||||
return packages
|
||||
|
||||
def list_azurlane_packages(self, keywords=('hkrpg', ), show_log=True):
|
||||
def list_azurlane_packages(self, show_log=True):
|
||||
"""
|
||||
Args:
|
||||
keywords:
|
||||
show_log:
|
||||
|
||||
Returns:
|
||||
list[str]: List of package names
|
||||
"""
|
||||
packages = self.list_package(show_log=show_log)
|
||||
packages = [p for p in packages if any([k in p.lower() for k in keywords])]
|
||||
packages = [p for p in packages if p in server_.VALID_PACKAGE]
|
||||
return packages
|
||||
|
||||
def detect_package(self, keywords=('hkrpg', ), set_config=True):
|
||||
def detect_package(self, set_config=True):
|
||||
"""
|
||||
Show all possible packages with the given keyword on this device.
|
||||
"""
|
||||
logger.hr('Detect package')
|
||||
packages = self.list_azurlane_packages(keywords=keywords)
|
||||
packages = self.list_azurlane_packages()
|
||||
|
||||
# Show packages
|
||||
logger.info(f'Here are the available packages in device "{self.serial}", '
|
||||
@ -861,20 +863,20 @@ class Connection(ConnectionAttr):
|
||||
|
||||
# Auto package detection
|
||||
if len(packages) == 0:
|
||||
logger.critical(f'No {keywords[0]} package found, '
|
||||
f'please confirm {keywords[0]} has been installed on device "{self.serial}"')
|
||||
logger.critical(f'No Star Rail package found, '
|
||||
f'please confirm Star Rail has been installed on device "{self.serial}"')
|
||||
raise RequestHumanTakeover
|
||||
if len(packages) == 1:
|
||||
logger.info('Auto package detection found only one package, using it')
|
||||
self.package = packages[0]
|
||||
# Set config
|
||||
if set_config:
|
||||
self.config.Emulator_PackageName = self.package
|
||||
self.config.Emulator_PackageName = server_.to_server(self.package)
|
||||
# Set server
|
||||
# logger.info('Server changed, release resources')
|
||||
# set_server(self.package)
|
||||
else:
|
||||
logger.critical(
|
||||
f'Multiple {keywords[0]} packages found, auto package detection cannot decide which to choose, '
|
||||
f'Multiple Star Rail packages found, auto package detection cannot decide which to choose, '
|
||||
'please copy one of the available devices listed above to Alas.Emulator.PackageName')
|
||||
raise RequestHumanTakeover
|
||||
|
Loading…
Reference in New Issue
Block a user