mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-16 06:25:24 +00:00
Fix: [ALAS] Re-init MaaTouch when orientation changed
This commit is contained in:
parent
670541f515
commit
3757510ecd
@ -183,6 +183,16 @@ class Device(Screenshot, Control, AppControl):
|
||||
if self.config.Emulator_ScreenshotMethod == 'nemu_ipc':
|
||||
self.nemu_ipc_release()
|
||||
|
||||
def get_orientation(self):
|
||||
"""
|
||||
Callbacks when orientation changed.
|
||||
"""
|
||||
o = super().get_orientation()
|
||||
|
||||
self.on_orientation_change_maatouch()
|
||||
|
||||
return o
|
||||
|
||||
def stuck_record_add(self, button):
|
||||
self.detect_record.add(str(button))
|
||||
|
||||
|
@ -102,9 +102,10 @@ class MaaTouch(Connection):
|
||||
"""
|
||||
max_x: int
|
||||
max_y: int
|
||||
_maatouch_stream = socket.socket
|
||||
_maatouch_stream: socket.socket = None
|
||||
_maatouch_stream_storage = None
|
||||
_maatouch_init_thread = None
|
||||
_maatouch_orientation: int = None
|
||||
|
||||
@cached_property
|
||||
def _maatouch_builder(self):
|
||||
@ -136,12 +137,40 @@ class MaaTouch(Connection):
|
||||
self._maatouch_init_thread = thread
|
||||
thread.start()
|
||||
|
||||
def on_orientation_change_maatouch(self):
|
||||
"""
|
||||
MaaTouch caches devices orientation at its startup
|
||||
A restart is required when orientation changed
|
||||
"""
|
||||
if self._maatouch_orientation is None:
|
||||
return
|
||||
if self.orientation == self._maatouch_orientation:
|
||||
return
|
||||
|
||||
logger.info(f'Orientation changed {self._maatouch_orientation} => {self.orientation}, re-init MaaTouch')
|
||||
del_cached_property(self, '_maatouch_builder')
|
||||
self.early_maatouch_init()
|
||||
|
||||
def maatouch_init(self):
|
||||
logger.hr('MaaTouch init')
|
||||
max_x, max_y = 1280, 720
|
||||
max_contacts = 2
|
||||
max_pressure = 50
|
||||
|
||||
# Try to close existing stream
|
||||
if self._maatouch_stream is not None:
|
||||
try:
|
||||
self._maatouch_stream.close()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
del self._maatouch_stream
|
||||
if self._maatouch_stream_storage is not None:
|
||||
del self._maatouch_stream_storage
|
||||
|
||||
# MaaTouch caches devices orientation at its startup
|
||||
super(MaaTouch, self).get_orientation()
|
||||
self._maatouch_orientation = self.orientation
|
||||
|
||||
# CLASSPATH=/data/local/tmp/maatouch app_process / com.shxyke.MaaTouch.App
|
||||
stream = self.adb_shell(
|
||||
['CLASSPATH=/data/local/tmp/maatouch', 'app_process', '/', 'com.shxyke.MaaTouch.App'],
|
||||
|
@ -408,6 +408,15 @@ class Minitouch(Connection):
|
||||
max_x, max_y = 1280, 720
|
||||
max_contacts = 2
|
||||
max_pressure = 50
|
||||
|
||||
# Try to close existing stream
|
||||
if self._minitouch_client is not None:
|
||||
try:
|
||||
self._minitouch_client.close()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
del self._minitouch_client
|
||||
|
||||
self.get_orientation()
|
||||
|
||||
self._minitouch_port = self.adb_forward("localabstract:minitouch")
|
||||
|
Loading…
Reference in New Issue
Block a user