Skip to content

增加关闭模拟器功能&关闭游戏等待时间 #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

class Script:
def __init__(self, config_name: str ='oas') -> None:
self.device = None
logger.hr('Start', level=0)
self.server = None
self.state_queue: Queue = None
Expand Down Expand Up @@ -310,31 +311,46 @@ def get_next_task(self) -> str:
logger.info(f'Wait until {task.next_run} for task `{task.command}`')
# self.is_first_task = False
method = self.config.script.optimization.when_task_queue_empty
if method == 'close_game':
logger.info('Close game during wait')
self.device.app_stop()
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del_cached_property(self, 'config')
continue
self.run('Restart')
elif method == 'goto_main':
logger.info('Goto main page during wait')
self.run('GotoMain')
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del_cached_property(self, 'config')
continue
close_game_limit_time = self.config.script.optimization.close_game_limit_time
close_emulator_limit_time = self.config.script.optimization.close_emulator_limit_time

if method == 'goto_main':
self._handle_goto_main()
elif method == 'close_game':
self._handle_close_game(task, close_game_limit_time)
elif method in ['close_emulator_or_goto_main', 'close_emulator_or_close_game']:
self._handle_close_emulator_or(task, close_game_limit_time, close_emulator_limit_time, method)
else:
logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there')
self.device.release_during_wait()
if not self.wait_until(task.next_run):
del_cached_property(self, 'config')
continue

self.device.release_during_wait()
if not self.wait_until(task.next_run):
del_cached_property(self, 'config')
continue
break

return task.command

def _handle_goto_main(self):
logger.info('Goto main page during wait')
self.run('GotoMain')

def _handle_close_game(self, task, close_game_limit_time):
if task.next_run > datetime.now() + timedelta(hours=close_game_limit_time.hour, minutes=close_game_limit_time.minute, seconds=close_game_limit_time.second):
logger.info('Close game during wait')
self.device.app_stop()
else:
self._handle_goto_main()

def _handle_close_emulator_or(self, task, close_game_limit_time, close_emulator_limit_time, method):
if task.next_run > datetime.now() + timedelta(hours=close_emulator_limit_time.hour, minutes=close_emulator_limit_time.minute, seconds=close_emulator_limit_time.second):
logger.info('Close emulator during wait')
self.device.emulator_stop()
elif method == 'close_emulator_or_goto_main':
self._handle_goto_main()
else:
self._handle_close_game(task, close_game_limit_time)

def run(self, command: str) -> bool:
"""

Expand Down Expand Up @@ -424,17 +440,20 @@ def loop(self):
# logger.info('Server or network is recovered. Restart game client')
# self.config.task_call('Restart')

if self.is_first_task:
self.device = Device(self.config)
# Get task
task = self.get_next_task()
# 更新 gui的任务
# Init device and change server
_ = self.device
# _ = self.device
# Skip first restart
if self.is_first_task and task == 'Restart':
logger.info('Skip task `Restart` at scheduler start')
self.config.task_delay(task='Restart', success=True, server=True)
del_cached_property(self, 'config')
continue
self.device = Device(self.config)

# Run
logger.info(f'Scheduler: Start task `{task}`')
Expand Down
6 changes: 6 additions & 0 deletions tasks/Script/config_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from pydantic import BaseModel, ValidationError, validator, Field

from module.logger import logger
from tasks.Component.config_base import ConfigBase, Time

class WhenTaskQueueEmpty(str, Enum):
GOTO_MAIN = 'goto_main'
CLOSE_GAME = 'close_game'
CLOSE_EMULATOR_OR_GOTO_MAIN = 'close_emulator_or_goto_main'
CLOSE_EMULATOR_OR_CLOSE_GAME = 'close_emulator_or_close_game'


class ScheduleRule(str, Enum):
FILTER = 'Filter' # 默认的基于过滤器,(按照开发者设定的调度规则进行调度)
Expand All @@ -24,5 +28,7 @@ class Optimization(BaseModel):
description='task_hoarding_duration_help')
when_task_queue_empty: WhenTaskQueueEmpty = Field(default=WhenTaskQueueEmpty.GOTO_MAIN,
description='when_task_queue_empty_help')
close_game_limit_time: Time = Field(default=Time(minute=10), description='关闭游戏等待时间')
close_emulator_limit_time: Time = Field(default=Time(minute=30), description='关闭模拟器等待时间')
schedule_rule: ScheduleRule = Field(default=ScheduleRule.FILTER, description='schedule_rule_help')