mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-07-13 10:58:02 +08:00
Merge branch 'master' of https://github.com/LmeSzinc/AzurLaneAutoScript
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import yaml
|
||||
|
||||
from module.base.utils import random_rectangle_point, point2str
|
||||
from module.base.timer import Timer
|
||||
from module.device.method.utils import HierarchyButton
|
||||
from module.equipment.assets import *
|
||||
from module.logger import logger
|
||||
@@ -9,6 +9,7 @@ from module.storage.assets import EQUIPMENT_FULL
|
||||
from module.storage.storage import StorageHandler
|
||||
|
||||
EMPTY_CODE = "MC8wLzAvMC8wXDA="
|
||||
U2_CONTROL_METHODS = {'uiautomator2', 'minitouch', 'MaaTouch'}
|
||||
EQUIPMENT_PREVIEW = list([
|
||||
EQUIPMENT_CODE_EQUIP_0,
|
||||
EQUIPMENT_CODE_EQUIP_1,
|
||||
@@ -21,6 +22,17 @@ EQUIPMENT_PREVIEW = list([
|
||||
class EquipmentCodeHandler(StorageHandler):
|
||||
last_code: str = None
|
||||
|
||||
def equipment_code_supported(self):
|
||||
method = self.config.Emulator_ControlMethod
|
||||
if method in U2_CONTROL_METHODS:
|
||||
return True
|
||||
|
||||
logger.warning(
|
||||
f"Equipment code requires uiautomator2 based control method, "
|
||||
f"current control method is {method}, skip equipment change"
|
||||
)
|
||||
return False
|
||||
|
||||
def get_code(self, name):
|
||||
try:
|
||||
config = {}
|
||||
@@ -61,14 +73,19 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
if not self.appear(EMPTY_SHIP_R):
|
||||
break
|
||||
if TEMPLATE_BOGUE.match(self.device.image, scaling=1.46): # image has rotation
|
||||
logger.info("Bogue detected")
|
||||
return 'bogue'
|
||||
elif TEMPLATE_HERMES.match(self.device.image, scaling=124 / 89):
|
||||
logger.info("Hermes detected")
|
||||
return 'hermes'
|
||||
elif TEMPLATE_RANGER.match(self.device.image, scaling=4 / 3):
|
||||
logger.info("Ranger detected")
|
||||
return 'ranger'
|
||||
elif TEMPLATE_LANGLEY.match(self.device.image, scaling=25 / 21):
|
||||
logger.info("Langley detected")
|
||||
return 'langley'
|
||||
else:
|
||||
logger.warning("Unknown ship detected, assuming DD")
|
||||
return 'DD'
|
||||
|
||||
def _code_enter(self):
|
||||
@@ -81,7 +98,7 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
if self.appear(EQUIPMENT_CODE_PAGE_CHECK, offset=(5, 5)):
|
||||
break
|
||||
|
||||
if self.appear_then_click(EQUIPMENT_CODE_ENTRANCE, offset=(5, 5), interval=2):
|
||||
if self.appear_then_click(EQUIPMENT_CODE_ENTRANCE, offset=(5, 5), interval=1):
|
||||
continue
|
||||
|
||||
def _code_exit(self):
|
||||
@@ -108,7 +125,7 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
if not self.is_code_preview_loaded():
|
||||
return True
|
||||
|
||||
if self.appear_then_click(EQUIPMENT_CODE_CLEAR, offset=(5, 5)):
|
||||
if self.appear_then_click(EQUIPMENT_CODE_CLEAR, offset=(5, 5), interval=1):
|
||||
continue
|
||||
else:
|
||||
return False
|
||||
@@ -124,9 +141,7 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
def appear_then_click(xpath):
|
||||
b = HierarchyButton(h, xpath)
|
||||
if b:
|
||||
point = random_rectangle_point(b.button)
|
||||
logger.info(f'Click {point2str(*point)} @ {b}')
|
||||
self.device.click_adb(*point)
|
||||
self.device.click(b)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -144,18 +159,28 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
|
||||
self.device.adb_shell(['input', 'keyevent', '4'])
|
||||
|
||||
def set_fastinput_ime(self):
|
||||
d = self.device.u2
|
||||
try:
|
||||
d.set_fastinput_ime(True)
|
||||
except Exception:
|
||||
logger.warning("FastInputIME not enabled, trying to enable it")
|
||||
self.fastinput_ime_enable()
|
||||
|
||||
def _code_input(self, code):
|
||||
logger.info(f"Code input: {code}")
|
||||
d = self.device.u2
|
||||
for _ in self.loop(timeout=10):
|
||||
click_timer = Timer(1, count=3)
|
||||
for _ in self.loop():
|
||||
name, shown = d.current_ime()
|
||||
if shown:
|
||||
if name != 'com.github.uiautomator/.FastInputIME':
|
||||
self.fastinput_ime_enable()
|
||||
self.set_fastinput_ime()
|
||||
continue
|
||||
else:
|
||||
break
|
||||
self.device.click(EQUIPMENT_CODE_TEXTBOX)
|
||||
if click_timer.reached_and_reset():
|
||||
self.device.click(EQUIPMENT_CODE_TEXTBOX)
|
||||
else:
|
||||
logger.warning("Equipment code load failed")
|
||||
return False
|
||||
@@ -216,19 +241,25 @@ class EquipmentCodeHandler(StorageHandler):
|
||||
return code
|
||||
|
||||
def code_clear(self, name=None):
|
||||
if not self.equipment_code_supported():
|
||||
return False
|
||||
|
||||
self._code_enter()
|
||||
if name is None:
|
||||
name = self.current_ship()
|
||||
if self.get_code(name=name) is None:
|
||||
self.last_code = self._code_export()
|
||||
self.set_code(name=name, code=self.last_code)
|
||||
self._code_apply(code=None)
|
||||
return self._code_apply(code=None)
|
||||
|
||||
def code_apply(self, name=None):
|
||||
if not self.equipment_code_supported():
|
||||
return False
|
||||
|
||||
self._code_enter()
|
||||
if name is None:
|
||||
name = self.current_ship()
|
||||
code = self.get_code(name=name)
|
||||
if code is None:
|
||||
code = self.last_code
|
||||
self._code_apply(code=code)
|
||||
return self._code_apply(code=code)
|
||||
|
||||
Reference in New Issue
Block a user