Skip to content

Commit

Permalink
Add: Cloud game support
Browse files Browse the repository at this point in the history
  • Loading branch information
LmeSzinc committed Jan 14, 2024
1 parent 5b7b226 commit c493292
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 21 deletions.
Binary file added assets/share/login/LOGIN_CONFIRM.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion module/alas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def checker(self):
logger.exception(e)
exit(1)

def restart(self):
raise NotImplemented

def start(self):
raise NotImplemented

def stop(self):
raise NotImplemented

def goto_main(self):
raise NotImplemented

def run(self, command):
try:
self.device.screenshot()
Expand Down Expand Up @@ -211,7 +223,7 @@ def get_next_task(self):
method = self.config.Optimization_WhenTaskQueueEmpty
if method == 'close_game':
logger.info('Close game during wait')
self.device.app_stop()
self.run('stop')
release_resources()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
Expand Down
50 changes: 49 additions & 1 deletion module/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from module.base.utils import *
from module.config.config import AzurLaneConfig
from module.device.device import Device
from module.device.method.utils import HierarchyButton
from module.logger import logger
from module.webui.setting import cached_class_property

Expand Down Expand Up @@ -132,9 +133,56 @@ def match_template_color(self, button, interval=0, similarity=0.85, threshold=30

return appear

appear = match_template
def xpath(self, xpath) -> HierarchyButton:
if isinstance(xpath, str):
return HierarchyButton(self.device.hierarchy, xpath)
else:
return xpath

def xpath_appear(self, xpath: str, interval=0):
button = self.xpath(xpath)

self.device.stuck_record_add(button)

if interval and not self.interval_is_reached(button, interval=interval):
return False

appear = bool(button)

if appear and interval:
self.interval_reset(button, interval=interval)

return appear

def appear(self, button, interval=0, similarity=0.85):
"""
Args:
button (Button, ButtonWrapper, HierarchyButton, str):
interval (int, float): interval between two active events.
Returns:
bool:
Examples:
Template match:
```
self.device.screenshot()
self.appear(POPUP_CONFIRM)
```
Hierarchy detection (detect elements with xpath):
```
self.device.dump_hierarchy()
self.appear('//*[@resource-id="..."]')
```
"""
if isinstance(button, (HierarchyButton, str)):
return self.xpath_appear(button, interval=interval)
else:
return self.match_template(button, interval=interval, similarity=similarity)

def appear_then_click(self, button, interval=5, similarity=0.85):
button = self.xpath(button)
appear = self.appear(button, interval=interval, similarity=similarity)
if appear:
self.device.click(button)
Expand Down
13 changes: 8 additions & 5 deletions module/device/app_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def dump_hierarchy(self) -> etree._Element:
Returns:
etree._Element: Select elements with `self.hierarchy.xpath('//*[@text="Hermit"]')` for example.
"""
method = self.config.Emulator_ControlMethod
if method in AppControl._app_u2_family:
self.hierarchy = self.dump_hierarchy_uiautomator2()
else:
self.hierarchy = self.dump_hierarchy_adb()
# method = self.config.Emulator_ControlMethod
# if method in AppControl._app_u2_family:
# self.hierarchy = self.dump_hierarchy_uiautomator2()
# else:
# self.hierarchy = self.dump_hierarchy_adb()

# Using uiautomator2
self.hierarchy = self.dump_hierarchy_uiautomator2()
return self.hierarchy

def xpath_to_button(self, xpath: str) -> HierarchyButton:
Expand Down
38 changes: 35 additions & 3 deletions module/device/method/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
# We expect `screencap | nc 192.168.0.1 20298` instead of `screencap '|' nc 192.168.80.1 20298`
import adbutils
import subprocess

adbutils._utils.list2cmdline = subprocess.list2cmdline
adbutils._device.list2cmdline = subprocess.list2cmdline


# BaseDevice.shell() is missing a check_okay() call before reading output,
# resulting in an `OKAY` prefix in output.
def shell(self,
Expand All @@ -40,6 +42,7 @@ def shell(self,
output = c.read_until_close()
return output.rstrip() if rstrip else output


adbutils._device.BaseDevice.shell = shell

from module.base.decorator import cached_property
Expand Down Expand Up @@ -323,7 +326,7 @@ def name(self):
if res:
return res[0]
else:
return 'HierarchyButton'
return self.xpath

@cached_property
def count(self):
Expand All @@ -333,10 +336,17 @@ def count(self):
def exist(self):
return self.count == 1

@cached_property
def attrib(self):
if self.exist:
return self.nodes[0].attrib
else:
return {}

@cached_property
def area(self):
if self.exist:
bounds = self.nodes[0].attrib.get("bounds")
bounds = self.attrib.get("bounds")
lx, ly, rx, ry = map(int, re.findall(r"\d+", bounds))
return lx, ly, rx, ry
else:
Expand All @@ -355,6 +365,28 @@ def __str__(self):
@cached_property
def focused(self):
if self.exist:
return self.nodes[0].attrib.get("focused").lower() == 'true'
return self.attrib.get("focused").lower() == 'true'
else:
return False

@cached_property
def text(self):
if self.exist:
return self.attrib.get("text").strip()
else:
return ""


class AreaButton:
def __init__(self, area, name='AREA_BUTTON'):
self.area = area
self.color = ()
self.name = name
self.button = area

def __str__(self):
return self.name

def __bool__(self):
# Cannot appear
return False
4 changes: 4 additions & 0 deletions src.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def start(self):
from tasks.login.login import Login
Login(self.config, device=self.device).app_start()

def stop(self):
from tasks.login.login import Login
Login(self.config, device=self.device).app_stop()

def goto_main(self):
from tasks.login.login import Login
from tasks.base.ui import UI
Expand Down
23 changes: 16 additions & 7 deletions tasks/login/assets/assets_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

LOGIN_CONFIRM = ButtonWrapper(
name='LOGIN_CONFIRM',
share=Button(
file='./assets/share/login/LOGIN_CONFIRM.png',
area=(1188, 44, 1220, 74),
search=(1168, 24, 1240, 94),
color=(140, 124, 144),
button=(683, 327, 1143, 620),
),
share=[
Button(
file='./assets/share/login/LOGIN_CONFIRM.png',
area=(1188, 44, 1220, 74),
search=(1168, 24, 1240, 94),
color=(140, 124, 144),
button=(683, 327, 1143, 620),
),
Button(
file='./assets/share/login/LOGIN_CONFIRM.2.png',
area=(1109, 48, 1139, 73),
search=(1089, 28, 1159, 93),
color=(149, 145, 164),
button=(1109, 48, 1139, 73),
),
],
)
LOGIN_LOADING = ButtonWrapper(
name='LOGIN_LOADING',
Expand Down
Loading

0 comments on commit c493292

Please sign in to comment.