From 502558dbbd2cce06ae587da179a5992c9464e7b5 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 00:57:40 +0800 Subject: [PATCH 1/6] Fix: brute_force_connect() was called on linux --- module/device/connection.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/module/device/connection.py b/module/device/connection.py index ce5e1968e..0611d523b 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -4,6 +4,7 @@ import platform import re import socket import subprocess +import sys import time from functools import wraps @@ -805,8 +806,11 @@ class Connection(ConnectionAttr): # brute_force_connect if self.config.Emulator_Serial == 'auto' and available.count == 0: logger.warning(f'No available device found') - brute_force_connect() - continue + if sys.platform == 'win32': + brute_force_connect() + continue + else: + break else: break From 16ba4aaad6079b82554320b9911635aeb7dba50d Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 02:54:44 +0800 Subject: [PATCH 2/6] Chore: Poorly search mxnet-cu* instead of using pkg_resources --- module/base/base.py | 4 ++-- module/ocr/al_ocr.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/module/base/base.py b/module/base/base.py index 6c676abc7..8f33d433e 100644 --- a/module/base/base.py +++ b/module/base/base.py @@ -83,8 +83,8 @@ class ModuleBase: time.sleep(0.01) logger.info('early_ocr_import start') - from cnocr import CnOcr - _ = CnOcr + from module.ocr.al_ocr import AlOcr + _ = AlOcr logger.info('early_ocr_import finish') logger.info('early_ocr_import call') diff --git a/module/ocr/al_ocr.py b/module/ocr/al_ocr.py index 5f6fee115..b662b1501 100644 --- a/module/ocr/al_ocr.py +++ b/module/ocr/al_ocr.py @@ -17,10 +17,12 @@ from cnocr.hyperparams.cn_hyperparams import CnHyperparams as Hyperparams def get_mxnet_context(): import re - import pkg_resources - for pkg in pkg_resources.working_set: - if re.match(r'^mxnet-cu\d+$', pkg.key): - logger.info(f'MXNet gpu package: {pkg.key}=={pkg.version} found, using it') + import cnocr + site_packages = os.path.abspath(os.path.join(cnocr.__file__, '../../')) + for file in os.listdir(site_packages): + # mxnet_cu101-1.6.0.dist-info + if re.match(r'^mxnet[-_]cu\d+', file): + logger.info(f'MXNet gpu package: {file} found, using it') return 'gpu' return 'cpu' From 31da8d42a144005e4ba716e2c5995b248c8f4b28 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 03:48:37 +0800 Subject: [PATCH 3/6] Opt: Early init minitouch and MaaTouch for faster startup --- module/base/base.py | 2 +- module/config/config.py | 4 +++ module/device/device.py | 7 +++++ module/device/method/maatouch.py | 43 +++++++++++++++++++++++++------ module/device/method/minitouch.py | 40 +++++++++++++++++++++++----- 5 files changed, 80 insertions(+), 16 deletions(-) diff --git a/module/base/base.py b/module/base/base.py index 8f33d433e..587951663 100644 --- a/module/base/base.py +++ b/module/base/base.py @@ -70,7 +70,7 @@ class ModuleBase: """ if ModuleBase.EARLY_OCR_IMPORT: return - if self.config.task.command.lower() in ['alas', 'template']: + if not self.config.is_actual_task: logger.info('No actual task bound, skip early_ocr_import') return diff --git a/module/config/config.py b/module/config/config.py index 1b7d0dc54..c91660937 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -189,6 +189,10 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher self.data, keys="Alas.Optimization.CloseGameDuringWait", default=False ) + @property + def is_actual_task(self): + return self.task.command.lower() not in ['alas', 'template'] + def get_next_task(self): """ Calculate tasks, set pending_task and waiting_task diff --git a/module/device/device.py b/module/device/device.py index f24833bc6..1aa6a033a 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -87,6 +87,13 @@ class Device(Screenshot, Control, AppControl): 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() + def run_simple_screenshot_benchmark(self): """ Perform a screenshot method benchmark, test 3 times on each method. diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index b1d6e3471..8aa59e13a 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -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 @@ -36,20 +37,20 @@ def retry(func): 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 @@ -58,12 +59,12 @@ def retry(func): 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) @@ -90,13 +91,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): + def _maatouch_builder(self): self.maatouch_init() # Orientation is handled inside MaaTouch return CommandBuilder(self, handle_orientation=False) + @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 diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index 70abd1a1c..42c582271 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -1,7 +1,7 @@ import asyncio import json -import re import socket +import threading import time from functools import wraps from typing import List @@ -10,11 +10,11 @@ import websockets 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 @@ -324,7 +324,7 @@ def retry(func): 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) @@ -333,7 +333,7 @@ def retry(func): 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): @@ -345,7 +345,7 @@ def retry(func): 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) @@ -366,12 +366,38 @@ class Minitouch(Connection): _minitouch_ws: websockets.WebSocketClientProtocol max_x: int max_y: int + _minitouch_init_thread = None @cached_property - def minitouch_builder(self): + 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') From 4858d55c460897da18fac8e4fc0b4f74d913a7e3 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:43:42 +0800 Subject: [PATCH 4/6] Opt: Patch pkg_resources for faster startup --- module/device/device.py | 6 ++ module/device/pkg_resources/__init__.py | 82 +++++++++++++++++++++++++ module/ocr/al_ocr.py | 12 ++-- 3 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 module/device/pkg_resources/__init__.py diff --git a/module/device/device.py b/module/device/device.py index 1aa6a033a..038b6719b 100644 --- a/module/device/device.py +++ b/module/device/device.py @@ -1,6 +1,12 @@ import collections from datetime import datetime +# 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.config.utils import get_server_next_update from module.device.app_control import AppControl diff --git a/module/device/pkg_resources/__init__.py b/module/device/pkg_resources/__init__.py new file mode 100644 index 000000000..61014ef79 --- /dev/null +++ b/module/device/pkg_resources/__init__.py @@ -0,0 +1,82 @@ +import os +import re +import sys + +from module.base.decorator import cached_property + +""" +Importing pkg_resources is so slow, like 0.4 ~ 1.0s, just google it you will find it indeed really slow. +Since it was some kind of standard library there is no way to modify it or speed it up. +So here's a poor but fast implementation of pkg_resources returning the things in need. + +To patch: +``` +# 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 +``` +""" +# Inject sys.modules, pretend we have pkg_resources imported +sys.modules['pkg_resources'] = sys.modules['module.device.pkg_resources'] + + +class FakeDistributionObject: + def __init__(self, dist, version): + self.dist = dist + self.version = version + + def __str__(self): + return f'{self.__class__.__name__}({self.dist}={self.version})' + + __repr__ = __str__ + + +class PackageCache: + @cached_property + def site_packages(self): + # Just whatever library to locate the `site-packages` directory + import requests + path = os.path.abspath(os.path.join(requests.__file__, '../../')) + return path + + @cached_property + def dict_installed_packages(self): + """ + Returns: + dict: Key: str, package name + Value: FakeDistributionObject + """ + dic = {} + for file in os.listdir(self.site_packages): + # mxnet_cu101-1.6.0.dist-info + res = re.match(r'^(.+)-(.+)\.dist-info$', file) + if res: + obj = FakeDistributionObject( + dist=res.group(1), + version=res.group(2), + ) + dic[obj.dist] = obj + + return dic + + +PACKAGE_CACHE = PackageCache() + + +def resource_filename(*args): + if args == ("adbutils", "binaries"): + path = os.path.abspath(os.path.join(PACKAGE_CACHE.site_packages, *args)) + return path + + +def get_distribution(dist): + """Return a current distribution object for a Requirement or string""" + if dist == 'adbutils': + return PACKAGE_CACHE.dict_installed_packages.get('adbutils', '0.11.0') + if dist == 'uiautomator2': + return PACKAGE_CACHE.dict_installed_packages.get('uiautomator2', '2.16.17') + + +class DistributionNotFound(Exception): + pass diff --git a/module/ocr/al_ocr.py b/module/ocr/al_ocr.py index b662b1501..e913c42f3 100644 --- a/module/ocr/al_ocr.py +++ b/module/ocr/al_ocr.py @@ -13,16 +13,14 @@ from cnocr.cn_ocr import (check_model_name, data_dir, gen_network, load_module, read_charset) from cnocr.fit.ctc_metrics import CtcMetrics from cnocr.hyperparams.cn_hyperparams import CnHyperparams as Hyperparams +from module.device.pkg_resources import PACKAGE_CACHE def get_mxnet_context(): - import re - import cnocr - site_packages = os.path.abspath(os.path.join(cnocr.__file__, '../../')) - for file in os.listdir(site_packages): - # mxnet_cu101-1.6.0.dist-info - if re.match(r'^mxnet[-_]cu\d+', file): - logger.info(f'MXNet gpu package: {file} found, using it') + for dist in PACKAGE_CACHE.dict_installed_packages.values(): + # mxnet_cu101 + if dist.dist.startswith('mxnet_cu'): + logger.info(f'MXNet gpu package: {dist.dist}=={dist.version} found, using it') return 'gpu' return 'cpu' From 8376d628437c66c6fb38f97253003bcc3efa26c5 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:17:18 +0800 Subject: [PATCH 5/6] Sync: [ALAS] Minitouch multi-finger support --- module/device/method/maatouch.py | 42 ++++++++++++++++--------- module/device/method/minitouch.py | 52 +++++++++++++++++-------------- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/module/device/method/maatouch.py b/module/device/method/maatouch.py index b1d6e3471..8122505bc 100644 --- a/module/device/method/maatouch.py +++ b/module/device/method/maatouch.py @@ -77,6 +77,19 @@ def retry(func): return retry_wrapper +class MaatouchBuilder(CommandBuilder): + def __init__(self, device, contact=0, handle_orientation=False): + """ + Args: + device (MaaTouch): + """ + + super().__init__(device, contact, handle_orientation) + + def send(self): + return self.device.maatouch_send(builder=self) + + class MaaTouchNotInstalledError(Exception): pass @@ -94,8 +107,7 @@ class MaaTouch(Connection): @cached_property def maatouch_builder(self): self.maatouch_init() - # Orientation is handled inside MaaTouch - return CommandBuilder(self, handle_orientation=False) + return MaatouchBuilder(self) def maatouch_init(self): logger.hr('MaaTouch init') @@ -166,14 +178,14 @@ class MaaTouch(Connection): ) ) - def maatouch_send(self): - content = self.maatouch_builder.to_minitouch() + def maatouch_send(self, builder: MaatouchBuilder): + content = builder.to_minitouch() # logger.info("send operation: {}".format(content.replace("\n", "\\n"))) byte_content = content.encode('utf-8') self._maatouch_stream.sendall(byte_content) self._maatouch_stream.recv(0) - self.sleep(self.maatouch_builder.delay / 1000 + self.maatouch_builder.DEFAULT_DELAY) - self.maatouch_builder.clear() + self.sleep(self.maatouch_builder.delay / 1000 + builder.DEFAULT_DELAY) + builder.clear() def maatouch_install(self): logger.hr('MaaTouch install') @@ -188,7 +200,7 @@ class MaaTouch(Connection): builder = self.maatouch_builder builder.down(x, y).commit() builder.up().commit() - self.maatouch_send() + builder.send() @retry def long_click_maatouch(self, x, y, duration=1.0): @@ -196,7 +208,7 @@ class MaaTouch(Connection): builder = self.maatouch_builder builder.down(x, y).commit().wait(duration) builder.up().commit() - self.maatouch_send() + builder.send() @retry def swipe_maatouch(self, p1, p2): @@ -204,14 +216,14 @@ class MaaTouch(Connection): builder = self.maatouch_builder builder.down(*points[0]).commit() - self.maatouch_send() + builder.send() for point in points[1:]: builder.move(*point).commit().wait(10) - self.maatouch_send() + builder.send() builder.up().commit() - self.maatouch_send() + builder.send() @retry def drag_maatouch(self, p1, p2, point_random=(-10, -10, 10, 10)): @@ -221,15 +233,15 @@ class MaaTouch(Connection): builder = self.maatouch_builder builder.down(*points[0]).commit() - self.maatouch_send() + builder.send() for point in points[1:]: builder.move(*point).commit().wait(10) - self.maatouch_send() + builder.send() builder.move(*p2).commit().wait(140) builder.move(*p2).commit().wait(140) - self.maatouch_send() + builder.send() builder.up().commit() - self.maatouch_send() + builder.send() diff --git a/module/device/method/minitouch.py b/module/device/method/minitouch.py index 70abd1a1c..405bc0299 100644 --- a/module/device/method/minitouch.py +++ b/module/device/method/minitouch.py @@ -184,7 +184,7 @@ class CommandBuilder: max_x = 1280 max_y = 720 - def __init__(self, device, handle_orientation=True): + def __init__(self, device, contact=0, handle_orientation=True): """ Args: device: @@ -192,6 +192,7 @@ class CommandBuilder: self.device = device self.commands = [] self.delay = 0 + self.contact = contact self.handle_orientation = handle_orientation @property @@ -243,21 +244,21 @@ class CommandBuilder: self.delay += ms return self - def up(self, contact=0): + def up(self): """ add minitouch command: 'u \n' """ - self.commands.append(Command('u', contact=contact)) + self.commands.append(Command('u', contact=self.contact)) return self - def down(self, x, y, contact=0, pressure=100): + def down(self, x, y, pressure=100): """ add minitouch command: 'd \n' """ x, y = self.convert(x, y) - self.commands.append(Command('d', x=x, y=y, contact=contact, pressure=pressure)) + self.commands.append(Command('d', x=x, y=y, contact=self.contact, pressure=pressure)) return self - def move(self, x, y, contact=0, pressure=100): + def move(self, x, y, pressure=100): """ add minitouch command: 'm \n' """ x, y = self.convert(x, y) - self.commands.append(Command('m', x=x, y=y, contact=contact, pressure=pressure)) + self.commands.append(Command('m', x=x, y=y, contact=self.contact, pressure=pressure)) return self def clear(self): @@ -271,6 +272,9 @@ class CommandBuilder: def to_atx_agent(self) -> List[str]: return [command.to_atx_agent(self.max_x, self.max_y) for command in self.commands] + def send(self): + return self.device.minitouch_send(builder=self) + class MinitouchNotInstalledError(Exception): pass @@ -446,14 +450,14 @@ class Minitouch(Connection): ) @Config.when(DEVICE_OVER_HTTP=False) - def minitouch_send(self): - content = self.minitouch_builder.to_minitouch() + def minitouch_send(self, builder: CommandBuilder): + content = builder.to_minitouch() # logger.info("send operation: {}".format(content.replace("\n", "\\n"))) byte_content = content.encode('utf-8') self._minitouch_client.sendall(byte_content) self._minitouch_client.recv(0) - time.sleep(self.minitouch_builder.delay / 1000 + self.minitouch_builder.DEFAULT_DELAY) - self.minitouch_builder.clear() + time.sleep(self.minitouch_builder.delay / 1000 + builder.DEFAULT_DELAY) + builder.clear() @cached_property def _minitouch_loop(self): @@ -514,8 +518,8 @@ class Minitouch(Connection): self._minitouch_ws = self._minitouch_loop_run(connect()) @Config.when(DEVICE_OVER_HTTP=True) - def minitouch_send(self): - content = self.minitouch_builder.to_atx_agent() + def minitouch_send(self, builder: CommandBuilder): + content = builder.to_atx_agent() async def send(): for row in content: @@ -523,15 +527,15 @@ class Minitouch(Connection): await self._minitouch_ws.send(row) self._minitouch_loop_run(send()) - time.sleep(self.minitouch_builder.delay / 1000 + self.minitouch_builder.DEFAULT_DELAY) - self.minitouch_builder.clear() + time.sleep(builder.delay / 1000 + builder.DEFAULT_DELAY) + builder.clear() @retry def click_minitouch(self, x, y): builder = self.minitouch_builder builder.down(x, y).commit() builder.up().commit() - self.minitouch_send() + builder.send() @retry def long_click_minitouch(self, x, y, duration=1.0): @@ -539,7 +543,7 @@ class Minitouch(Connection): builder = self.minitouch_builder builder.down(x, y).commit().wait(duration) builder.up().commit() - self.minitouch_send() + builder.send() @retry def swipe_minitouch(self, p1, p2): @@ -547,14 +551,14 @@ class Minitouch(Connection): builder = self.minitouch_builder builder.down(*points[0]).commit() - self.minitouch_send() + builder.send() for point in points[1:]: builder.move(*point).commit().wait(10) - self.minitouch_send() + builder.send() builder.up().commit() - self.minitouch_send() + builder.send() @retry def drag_minitouch(self, p1, p2, point_random=(-10, -10, 10, 10)): @@ -564,15 +568,15 @@ class Minitouch(Connection): builder = self.minitouch_builder builder.down(*points[0]).commit() - self.minitouch_send() + builder.send() for point in points[1:]: builder.move(*point).commit().wait(10) - self.minitouch_send() + builder.send() builder.move(*p2).commit().wait(140) builder.move(*p2).commit().wait(140) - self.minitouch_send() + builder.send() builder.up().commit() - self.minitouch_send() + builder.send() From 485c024b448e11a970dafa26e1d29be50c84f6db Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:20:52 +0800 Subject: [PATCH 6/6] Fix: Chain call minitouch in dorm --- module/dorm/dorm.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/module/dorm/dorm.py b/module/dorm/dorm.py index 1f7df2e6d..5c76eded7 100644 --- a/module/dorm/dorm.py +++ b/module/dorm/dorm.py @@ -108,12 +108,13 @@ class RewardDorm(UI): # Long tap to feed. This requires minitouch. timeout = Timer(count // 5 + 5).start() x, y = random_rectangle_point(button.button) - self.device.minitouch_builder.down(x, y).commit() - self.device.minitouch_send() + builder = self.device.minitouch_builder + builder.down(x, y).commit() + builder.send() while 1: - self.device.minitouch_builder.move(x, y).commit().wait(10) - self.device.minitouch_send() + builder.move(x, y).commit().wait(10) + builder.send() self.device.screenshot() if not self._dorm_has_food(button) \ @@ -124,19 +125,20 @@ class RewardDorm(UI): logger.warning('Wait dorm feed timeout') break - self.device.minitouch_builder.up().commit() - self.device.minitouch_send() + builder.up().commit() + builder.send() @Config.when(DEVICE_CONTROL_METHOD='MaaTouch') def _dorm_feed_long_tap(self, button, count): timeout = Timer(count // 5 + 5).start() x, y = random_rectangle_point(button.button) - self.device.maatouch_builder.down(x, y).commit() - self.device.maatouch_send() + builder = self.device.maatouch_builder + builder.down(x, y).commit() + builder.send() while 1: - self.device.maatouch_builder.move(x, y).commit().wait(10) - self.device.maatouch_send() + builder.move(x, y).commit().wait(10) + builder.send() self.device.screenshot() if not self._dorm_has_food(button) \ @@ -147,8 +149,8 @@ class RewardDorm(UI): logger.warning('Wait dorm feed timeout') break - self.device.maatouch_builder.up().commit() - self.device.maatouch_send() + builder.up().commit() + builder.send() @Config.when(DEVICE_CONTROL_METHOD='uiautomator2') def _dorm_feed_long_tap(self, button, count):