Skip to content

Commit

Permalink
Merge pull request #423 from LmeSzinc/dev
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
LmeSzinc authored Apr 18, 2024
2 parents 9849267 + 9216d8b commit 3f50d42
Show file tree
Hide file tree
Showing 27 changed files with 365 additions and 32 deletions.
Binary file added assets/character/Aventurine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions module/config/argument/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
"Argenti",
"Arlan",
"Asta",
"Aventurine",
"Bailu",
"BlackSwan",
"Blade",
Expand Down Expand Up @@ -1341,6 +1342,7 @@
"Argenti",
"Arlan",
"Asta",
"Aventurine",
"Bailu",
"BlackSwan",
"Blade",
Expand Down
4 changes: 4 additions & 0 deletions module/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def close_game(self):
self.data, keys="Alas.Optimization.CloseGameDuringWait", default=False
)

@property
def is_actual_task(self):
return self.task.command.lower() not in ['alas', 'template']

@property
def is_cloud_game(self):
return deep_get(
Expand Down
2 changes: 1 addition & 1 deletion module/config/config_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GeneratedConfig:

# Group `DungeonSupport`
DungeonSupport_Use = 'when_daily' # always_use, when_daily, do_not_use
DungeonSupport_Character = 'FirstCharacter' # FirstCharacter, Acheron, Argenti, Arlan, Asta, Bailu, BlackSwan, Blade, Bronya, Clara, DanHeng, DanHengImbibitorLunae, DrRatio, FuXuan, Gallagher, Gepard, Guinaifen, Hanya, Herta, Himeko, Hook, Huohuo, JingYuan, Jingliu, Kafka, Luka, Luocha, Lynx, March7th, Misha, Natasha, Pela, Qingque, RuanMei, Sampo, Seele, Serval, SilverWolf, Sparkle, Sushang, Tingyun, TopazNumby, TrailblazerDestruction, TrailblazerPreservation, Welt, Xueyi, Yanqing, Yukong
DungeonSupport_Character = 'FirstCharacter' # FirstCharacter, Acheron, Argenti, Arlan, Asta, Aventurine, Bailu, BlackSwan, Blade, Bronya, Clara, DanHeng, DanHengImbibitorLunae, DrRatio, FuXuan, Gallagher, Gepard, Guinaifen, Hanya, Herta, Himeko, Hook, Huohuo, JingYuan, Jingliu, Kafka, Luka, Luocha, Lynx, March7th, Misha, Natasha, Pela, Qingque, RuanMei, Sampo, Seele, Serval, SilverWolf, Sparkle, Sushang, Tingyun, TopazNumby, TrailblazerDestruction, TrailblazerPreservation, Welt, Xueyi, Yanqing, Yukong

# Group `DungeonStorage`
DungeonStorage_TrailblazePower = {}
Expand Down
2 changes: 1 addition & 1 deletion module/config/config_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def option_add(keys, options):
options=[dungeon.name for dungeon in DungeonList.instances.values() if dungeon.is_Echo_of_War])
# Insert characters
from tasks.character.keywords import CharacterList
unsupported_characters = ['Aventurine']
unsupported_characters = []
characters = [character.name for character in CharacterList.instances.values()
if character.name not in unsupported_characters]
option_add(keys='DungeonSupport.Character.option', options=characters)
Expand Down
1 change: 1 addition & 0 deletions module/config/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
"Argenti": "Argenti",
"Arlan": "Arlan",
"Asta": "Asta",
"Aventurine": "Aventurine",
"Bailu": "Bailu",
"BlackSwan": "Black Swan",
"Blade": "Blade",
Expand Down
1 change: 1 addition & 0 deletions module/config/i18n/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
"Argenti": "Argenti",
"Arlan": "Arlan",
"Asta": "Asta",
"Aventurine": "Aventurino",
"Bailu": "Bailu",
"BlackSwan": "Cisne Negro",
"Blade": "Blade",
Expand Down
1 change: 1 addition & 0 deletions module/config/i18n/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
"Argenti": "アルジェンティ",
"Arlan": "アーラン",
"Asta": "アスター",
"Aventurine": "アベンチュリン",
"Bailu": "白露",
"BlackSwan": "ブラックスワン",
"Blade": "",
Expand Down
1 change: 1 addition & 0 deletions module/config/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
"Argenti": "银枝",
"Arlan": "阿兰",
"Asta": "艾丝妲",
"Aventurine": "砂金",
"Bailu": "白露",
"BlackSwan": "黑天鹅",
"Blade": "",
Expand Down
1 change: 1 addition & 0 deletions module/config/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
"Argenti": "銀枝",
"Arlan": "阿蘭",
"Asta": "艾絲妲",
"Aventurine": "砂金",
"Bailu": "白露",
"BlackSwan": "黑天鵝",
"Blade": "",
Expand Down
13 changes: 13 additions & 0 deletions module/device/device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import collections
import itertools

# Patch pkg_resources before importing adbutils and uiautomator2
from module.device.pkg_resources import get_distribution

# Just avoid being removed by import optimization
_ = get_distribution

from module.base.timer import Timer
from module.device.app_control import AppControl
from module.device.control import Control
Expand Down Expand Up @@ -88,6 +94,13 @@ def __init__(self, *args, **kwargs):
if not self.config.is_template_config and self.config.Emulator_ScreenshotMethod == 'auto':
self.run_simple_screenshot_benchmark()

# Early init
if self.config.is_actual_task:
if self.config.Emulator_ControlMethod == 'MaaTouch':
self.early_maatouch_init()
if self.config.Emulator_ControlMethod == 'minitouch':
self.early_minitouch_init()

# SRC only, use nemu_ipc if available
available = self.nemu_ipc_available()
logger.attr('nemu_ipc_available', available)
Expand Down
49 changes: 41 additions & 8 deletions module/device/method/maatouch.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import socket
import threading
from functools import wraps

from adbutils.errors import AdbError

from module.base.decorator import cached_property, del_cached_property
from module.base.decorator import cached_property, del_cached_property, has_cached_property
from module.base.timer import Timer
from module.base.utils import *
from module.device.connection import Connection
from module.device.method.minitouch import CommandBuilder, insert_swipe
from module.device.method.utils import RETRY_TRIES, retry_sleep, handle_adb_error
from module.device.method.utils import RETRY_TRIES, handle_adb_error, retry_sleep
from module.exception import RequestHumanTakeover
from module.logger import logger

Expand Down Expand Up @@ -36,20 +37,20 @@ def retry_wrapper(self, *args, **kwargs):

def init():
self.adb_reconnect()
del_cached_property(self, 'maatouch_builder')
del_cached_property(self, '_maatouch_builder')
# Emulator closed
except ConnectionAbortedError as e:
logger.error(e)

def init():
self.adb_reconnect()
del_cached_property(self, 'maatouch_builder')
del_cached_property(self, '_maatouch_builder')
# AdbError
except AdbError as e:
if handle_adb_error(e):
def init():
self.adb_reconnect()
del_cached_property(self, 'maatouch_builder')
del_cached_property(self, '_maatouch_builder')
else:
break
# MaaTouchNotInstalledError: Received "Aborted" from MaaTouch
Expand All @@ -58,12 +59,12 @@ def init():

def init():
self.maatouch_install()
del_cached_property(self, 'maatouch_builder')
del_cached_property(self, '_maatouch_builder')
except BrokenPipeError as e:
logger.error(e)

def init():
del_cached_property(self, 'maatouch_builder')
del_cached_property(self, '_maatouch_builder')
# Unknown, probably a trucked image
except Exception as e:
logger.exception(e)
Expand Down Expand Up @@ -103,12 +104,39 @@ class MaaTouch(Connection):
max_y: int
_maatouch_stream = socket.socket
_maatouch_stream_storage = None
_maatouch_init_thread = None

@cached_property
def maatouch_builder(self):
@retry
def _maatouch_builder(self):
self.maatouch_init()
return MaatouchBuilder(self)

@property
def maatouch_builder(self):
# Wait init thread
if self._maatouch_init_thread is not None:
self._maatouch_init_thread.join()
del self._maatouch_init_thread
self._maatouch_init_thread = None

return self._maatouch_builder

def early_maatouch_init(self):
"""
Start a thread to init maatouch connection while the Alas instance just starting to take screenshots
This would speed up the first click 0.2 ~ 0.4s.
"""
if has_cached_property(self, '_maatouch_builder'):
return

def early_maatouch_init_func():
_ = self._maatouch_builder

thread = threading.Thread(target=early_maatouch_init_func, daemon=True)
self._maatouch_init_thread = thread
thread.start()

def maatouch_init(self):
logger.hr('MaaTouch init')
max_x, max_y = 1280, 720
Expand Down Expand Up @@ -245,3 +273,8 @@ def drag_maatouch(self, p1, p2, point_random=(-10, -10, 10, 10)):

builder.up().commit()
builder.send()


if __name__ == '__main__':
self = MaaTouch('src')
self.maatouch_uninstall()
41 changes: 34 additions & 7 deletions module/device/method/minitouch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import json
import re
import socket
import threading
import time
from functools import wraps
from typing import List
Expand All @@ -10,11 +10,11 @@
from adbutils.errors import AdbError
from uiautomator2 import _Service

from module.base.decorator import Config, cached_property, del_cached_property
from module.base.decorator import Config, cached_property, del_cached_property, has_cached_property
from module.base.timer import Timer
from module.base.utils import *
from module.device.connection import Connection
from module.device.method.utils import RETRY_TRIES, retry_sleep, handle_adb_error
from module.device.method.utils import RETRY_TRIES, handle_adb_error, retry_sleep
from module.exception import RequestHumanTakeover, ScriptError
from module.logger import logger

Expand Down Expand Up @@ -328,7 +328,7 @@ def init():
self.install_uiautomator2()
if self._minitouch_port:
self.adb_forward_remove(f'tcp:{self._minitouch_port}')
del_cached_property(self, 'minitouch_builder')
del_cached_property(self, '_minitouch_builder')
# MinitouchOccupiedError: Timeout when connecting to minitouch
except MinitouchOccupiedError as e:
logger.error(e)
Expand All @@ -337,7 +337,7 @@ def init():
self.restart_atx()
if self._minitouch_port:
self.adb_forward_remove(f'tcp:{self._minitouch_port}')
del_cached_property(self, 'minitouch_builder')
del_cached_property(self, '_minitouch_builder')
# AdbError
except AdbError as e:
if handle_adb_error(e):
Expand All @@ -349,7 +349,7 @@ def init():
logger.error(e)

def init():
del_cached_property(self, 'minitouch_builder')
del_cached_property(self, '_minitouch_builder')
# Unknown, probably a trucked image
except Exception as e:
logger.exception(e)
Expand All @@ -370,12 +370,39 @@ class Minitouch(Connection):
_minitouch_ws: websockets.WebSocketClientProtocol
max_x: int
max_y: int
_minitouch_init_thread = None

@cached_property
def minitouch_builder(self):
@retry
def _minitouch_builder(self):
self.minitouch_init()
return CommandBuilder(self)

@property
def minitouch_builder(self):
# Wait init thread
if self._minitouch_init_thread is not None:
self._minitouch_init_thread.join()
del self._minitouch_init_thread
self._minitouch_init_thread = None

return self._minitouch_builder

def early_minitouch_init(self):
"""
Start a thread to init minitouch connection while the Alas instance just starting to take screenshots
This would speed up the first click 0.05s.
"""
if has_cached_property(self, '_minitouch_builder'):
return

def early_minitouch_init_func():
_ = self._minitouch_builder

thread = threading.Thread(target=early_minitouch_init_func, daemon=True)
self._minitouch_init_thread = thread
thread.start()

@Config.when(DEVICE_OVER_HTTP=False)
def minitouch_init(self):
logger.hr('MiniTouch init')
Expand Down
2 changes: 1 addition & 1 deletion module/device/method/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def remove_suffix(s, suffix):
Returns:
str, bytes:
"""
return s[:len(suffix)] if s.endswith(suffix) else s
return s[:-len(suffix)] if s.endswith(suffix) else s


def remove_shell_warning(s):
Expand Down
Loading

0 comments on commit 3f50d42

Please sign in to comment.