Skip to content

Commit

Permalink
#44 完善运行状态显示
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Aug 4, 2024
1 parent 194f56e commit b42afec
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
13 changes: 12 additions & 1 deletion assets/game_data/screen_info/random_play.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ area_list:
- 1792
- 998
text: 开始营业
lcs_percent: 0.5
lcs_percent: 7.5
template_sub_dir: ''
template_id: ''
template_match_threshold: 0.7
Expand All @@ -200,3 +200,14 @@ area_list:
template_sub_dir: ''
template_id: ''
template_match_threshold: 0.7
- area_name: 正在营业
pc_rect:
- 1536
- 950
- 1792
- 998
text: 正在营业
lcs_percent: 0.75
template_sub_dir: ''
template_id: ''
template_match_threshold: 0.7
4 changes: 3 additions & 1 deletion src/one_dragon/base/operation/application_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class ApplicationEventId(Enum):

APPLICATION_START: str = '应用开始运行'
APPLICATION_STOP: str = '应用停止运行'


class Application(Operation):
Expand Down Expand Up @@ -58,7 +59,7 @@ def _init_before_execute(self) -> None:

self.init_for_application()
self.ctx.start_running()
self.ctx.dispatch_event(ApplicationEventId.APPLICATION_START.value)
self.ctx.dispatch_event(ApplicationEventId.APPLICATION_START.value, self.app_id)

def handle_resume(self) -> None:
"""
Expand All @@ -76,6 +77,7 @@ def _after_operation_done(self, result: OperationResult):
self._update_record_after_stop(result)
if self.stop_context_after_stop:
self.ctx.stop_running()
self.ctx.dispatch_event(ApplicationEventId.APPLICATION_STOP.value, self.app_id)

def _update_record_after_stop(self, result: OperationResult):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/one_dragon/base/operation/application_run_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self, app_id: str,
self.game_refresh_hour_offset: int = game_refresh_hour_offset # 游戏内每天刷新的偏移小时数 以凌晨12点为界限
super().__init__(app_id, instance_idx=instance_idx, sub_dir=['app_run_record'], sample=False)

self._init_after_read_file()

def _init_after_read_file(self):
self.dt = self.get('dt', self.get_current_dt())
self.run_time = self.get('run_time', '-')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import List

from one_dragon.base.config.config_item import ConfigItem
from one_dragon.base.operation.application_base import Application
from one_dragon.base.operation.application_base import Application, ApplicationEventId
from one_dragon.base.operation.context_event_bus import ContextEventItem
from one_dragon.base.operation.one_dragon_app import OneDragonApp
from one_dragon.base.operation.one_dragon_context import OneDragonContext, ContextRunningStateEventEnum, \
Expand Down Expand Up @@ -156,6 +156,8 @@ def on_interface_shown(self) -> None:
self._init_app_list()
self.log_card.set_update_log(True)
self.ctx.listen_event(ContextKeyboardEventEnum.PRESS.value, self._on_key_press)
self.ctx.listen_event(ApplicationEventId.APPLICATION_START.value, self._on_app_state_changed)
self.ctx.listen_event(ApplicationEventId.APPLICATION_STOP.value, self._on_app_state_changed)

def on_interface_hidden(self) -> None:
VerticalScrollInterface.on_interface_hidden(self)
Expand Down Expand Up @@ -209,6 +211,13 @@ def _on_context_state_changed(self) -> None:
self.start_btn.setIcon(icon)
self.state_text.setText('%s %s' % (gt('当前状态', 'ui'), self.ctx.context_running_status_text))

for app_card in self._app_run_cards:
app_card.update_display()

def _on_app_state_changed(self, event) -> None:
for app_card in self._app_run_cards:
app_card.update_display()

def _on_app_card_move_up(self, app_id: str) -> None:
"""
将该应用往上调整一位
Expand Down
12 changes: 12 additions & 0 deletions src/zzz_od/application/random_play/random_play_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class RandomPlayApp(ZApplication):

STATUS_ALL_VIDEO_CHOOSE: ClassVar[str] = '已选择全部录像带'
STATUS_ALREADY_RUNNING: ClassVar[str] = '正在营业'

def __init__(self, ctx: ZContext):
"""
Expand Down Expand Up @@ -94,6 +95,16 @@ def check_yesterday(self) -> OperationRoundResult:
return self.round_retry(status='未识别当前画面')

@node_from(from_name='识别画面')
@operation_node(name='识别营业状态')
def check_running(self) -> OperationRoundResult:
screen = self.screenshot()
result = self.round_by_find_area(screen, '影像店营业', '正在营业')
if result.is_success:
return self.round_success(RandomPlayApp.STATUS_ALREADY_RUNNING)
else:
return self.round_success()

@node_from(from_name='识别营业状态')
@operation_node(name='点击宣传员入口')
def click_promoter_entry(self) -> OperationRoundResult:
"""
Expand Down Expand Up @@ -270,6 +281,7 @@ def confirm(self) -> OperationRoundResult:
success_wait=1, retry_wait=1)

@node_from(from_name='开始营业确认')
@node_from(from_name='识别营业状态', status=STATUS_ALREADY_RUNNING)
@operation_node(name='返回大世界')
def back_to_world(self) -> OperationRoundResult:
op = BackToNormalWorld(self.ctx)
Expand Down
7 changes: 2 additions & 5 deletions src/zzz_od/application/scratch_card/scratch_card_app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import time

import difflib
from typing import List, ClassVar
from typing import ClassVar

from one_dragon.base.geometry.point import Point
from one_dragon.base.operation.operation_edge import node_from
from one_dragon.base.operation.operation_node import operation_node
from one_dragon.base.operation.operation_round_result import OperationRoundResult
from one_dragon.utils import cv2_utils
from one_dragon.utils.i18_utils import gt
from zzz_od.application.zzz_application import ZApplication
from zzz_od.context.zzz_context import ZContext
Expand All @@ -29,7 +26,7 @@ def __init__(self, ctx: ZContext):
ctx=ctx, app_id='scratch_card',
node_max_retry_times=10,
op_name=gt('刮刮卡', 'ui'),
run_record=ctx.email_run_record
run_record=ctx.scratch_card_run_record
)

def handle_init(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/zzz_od/operation/wait_normal_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, ctx: ZContext):
:param ctx:
"""
ZOperation.__init__(self, ctx,
timeout_seconds=60,
node_max_retry_times=60,
op_name=gt('等待大世界画面', 'ui')
)

Expand Down

0 comments on commit b42afec

Please sign in to comment.