Fix: Use match instead of ocr for assignment group

This commit is contained in:
Zebartin 2023-09-26 22:35:55 +08:00
parent afdef03711
commit a6a6b70c87
21 changed files with 201 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -200,6 +200,8 @@ def generate_code():
output = os.path.join(path, 'assets')
os.makedirs(output, exist_ok=True)
for prev in iter_folder(output, ext='.py'):
if os.path.basename(prev) == '__init__.py':
continue
os.remove(prev)
for module, module_data in all.items():

View File

@ -0,0 +1,18 @@
from module.config.server import VALID_LANG
from tasks.assignment.assets.assets_assignment_ui import (
CHARACTER_MATERIALS_CHECK, CHARACTER_MATERIALS_CLICK,
EXP_MATERIALS_CREDITS_CHECK, EXP_MATERIALS_CREDITS_CLICK, GROUP_SEARCH,
SPACE_STATION_TASK_FORCE_CHECK, SPACE_STATION_TASK_FORCE_CLICK,
SYNTHESIS_MATERIALS_CHECK, SYNTHESIS_MATERIALS_CLICK)
for group_button_wrapper in (
SPACE_STATION_TASK_FORCE_CHECK, SPACE_STATION_TASK_FORCE_CLICK,
CHARACTER_MATERIALS_CHECK, CHARACTER_MATERIALS_CLICK,
EXP_MATERIALS_CREDITS_CHECK, EXP_MATERIALS_CREDITS_CLICK,
SYNTHESIS_MATERIALS_CHECK, SYNTHESIS_MATERIALS_CLICK,
):
for lang in VALID_LANG:
button = getattr(group_button_wrapper, lang, None)
if button is None:
continue
button.search = GROUP_SEARCH.button

View File

@ -3,6 +3,40 @@ from module.base.button import Button, ButtonWrapper
# This file was auto-generated, do not modify it manually. To generate:
# ``` python -m dev_tools.button_extract ```
CHARACTER_MATERIALS_CHECK = ButtonWrapper(
name='CHARACTER_MATERIALS_CHECK',
cn=Button(
file='./assets/cn/assignment/ui/CHARACTER_MATERIALS_CHECK.png',
area=(346, 97, 421, 117),
search=(326, 77, 441, 137),
color=(177, 176, 173),
button=(346, 97, 421, 117),
),
en=Button(
file='./assets/en/assignment/ui/CHARACTER_MATERIALS_CHECK.png',
area=(339, 88, 429, 126),
search=(319, 68, 449, 146),
color=(193, 192, 189),
button=(339, 88, 429, 126),
),
)
CHARACTER_MATERIALS_CLICK = ButtonWrapper(
name='CHARACTER_MATERIALS_CLICK',
cn=Button(
file='./assets/cn/assignment/ui/CHARACTER_MATERIALS_CLICK.png',
area=(347, 97, 421, 117),
search=(327, 77, 441, 137),
color=(60, 60, 60),
button=(347, 97, 421, 117),
),
en=Button(
file='./assets/en/assignment/ui/CHARACTER_MATERIALS_CLICK.png',
area=(339, 88, 429, 127),
search=(319, 68, 449, 147),
color=(49, 49, 49),
button=(339, 88, 429, 127),
),
)
DISPATCHED = ButtonWrapper(
name='DISPATCHED',
cn=Button(
@ -30,6 +64,50 @@ ENTRY_LOADED = ButtonWrapper(
button=(467, 235, 498, 619),
),
)
EXP_MATERIALS_CREDITS_CHECK = ButtonWrapper(
name='EXP_MATERIALS_CREDITS_CHECK',
cn=Button(
file='./assets/cn/assignment/ui/EXP_MATERIALS_CREDITS_CHECK.png',
area=(514, 97, 614, 117),
search=(494, 77, 634, 137),
color=(178, 177, 174),
button=(514, 97, 614, 117),
),
en=Button(
file='./assets/en/assignment/ui/EXP_MATERIALS_CREDITS_CHECK.png',
area=(529, 88, 599, 126),
search=(509, 68, 619, 146),
color=(202, 201, 198),
button=(529, 88, 599, 126),
),
)
EXP_MATERIALS_CREDITS_CLICK = ButtonWrapper(
name='EXP_MATERIALS_CREDITS_CLICK',
cn=Button(
file='./assets/cn/assignment/ui/EXP_MATERIALS_CREDITS_CLICK.png',
area=(514, 97, 614, 117),
search=(494, 77, 634, 137),
color=(61, 60, 60),
button=(514, 97, 614, 117),
),
en=Button(
file='./assets/en/assignment/ui/EXP_MATERIALS_CREDITS_CLICK.png',
area=(528, 88, 599, 127),
search=(508, 68, 619, 147),
color=(42, 42, 42),
button=(528, 88, 599, 127),
),
)
GROUP_SEARCH = ButtonWrapper(
name='GROUP_SEARCH',
share=Button(
file='./assets/share/assignment/ui/GROUP_SEARCH.png',
area=(111, 76, 835, 140),
search=(91, 56, 855, 160),
color=(82, 79, 77),
button=(111, 76, 835, 140),
),
)
OCR_ASSIGNMENT_ENTRY_LIST = ButtonWrapper(
name='OCR_ASSIGNMENT_ENTRY_LIST',
share=Button(
@ -70,3 +148,71 @@ OCR_ASSIGNMENT_TIME = ButtonWrapper(
button=(605, 564, 886, 589),
),
)
SPACE_STATION_TASK_FORCE_CHECK = ButtonWrapper(
name='SPACE_STATION_TASK_FORCE_CHECK',
cn=Button(
file='./assets/cn/assignment/ui/SPACE_STATION_TASK_FORCE_CHECK.png',
area=(157, 97, 249, 117),
search=(137, 77, 269, 137),
color=(181, 181, 178),
button=(157, 97, 249, 117),
),
en=Button(
file='./assets/en/assignment/ui/SPACE_STATION_TASK_FORCE_CHECK.png',
area=(176, 88, 239, 126),
search=(156, 68, 259, 146),
color=(198, 197, 194),
button=(176, 88, 239, 126),
),
)
SPACE_STATION_TASK_FORCE_CLICK = ButtonWrapper(
name='SPACE_STATION_TASK_FORCE_CLICK',
cn=Button(
file='./assets/cn/assignment/ui/SPACE_STATION_TASK_FORCE_CLICK.png',
area=(157, 97, 249, 117),
search=(137, 77, 269, 137),
color=(71, 70, 68),
button=(157, 97, 249, 117),
),
en=Button(
file='./assets/en/assignment/ui/SPACE_STATION_TASK_FORCE_CLICK.png',
area=(176, 88, 239, 126),
search=(156, 68, 259, 146),
color=(60, 58, 56),
button=(176, 88, 239, 126),
),
)
SYNTHESIS_MATERIALS_CHECK = ButtonWrapper(
name='SYNTHESIS_MATERIALS_CHECK',
cn=Button(
file='./assets/cn/assignment/ui/SYNTHESIS_MATERIALS_CHECK.png',
area=(708, 97, 783, 117),
search=(688, 77, 803, 137),
color=(180, 179, 176),
button=(708, 97, 783, 117),
),
en=Button(
file='./assets/en/assignment/ui/SYNTHESIS_MATERIALS_CHECK.png',
area=(703, 88, 790, 126),
search=(683, 68, 810, 146),
color=(189, 188, 185),
button=(703, 88, 790, 126),
),
)
SYNTHESIS_MATERIALS_CLICK = ButtonWrapper(
name='SYNTHESIS_MATERIALS_CLICK',
cn=Button(
file='./assets/cn/assignment/ui/SYNTHESIS_MATERIALS_CLICK.png',
area=(709, 97, 783, 117),
search=(689, 77, 803, 137),
color=(68, 66, 65),
button=(709, 97, 783, 117),
),
en=Button(
file='./assets/en/assignment/ui/SYNTHESIS_MATERIALS_CLICK.png',
area=(702, 88, 790, 126),
search=(682, 68, 810, 146),
color=(61, 59, 58),
button=(702, 88, 790, 126),
),
)

View File

@ -8,6 +8,7 @@ from module.base.timer import Timer
from module.exception import ScriptError
from module.logger import logger
from module.ocr.ocr import DigitCounter, Duration, Ocr
from tasks.dungeon.ui import DungeonTabSwitch as Switch
from module.ui.draggable_list import DraggableList
from tasks.assignment.assets.assets_assignment_claim import CLAIM
from tasks.assignment.assets.assets_assignment_dispatch import EMPTY_SLOT
@ -37,14 +38,10 @@ class AssignmentOcr(Ocr):
(KEYWORDS_ASSIGNMENT_ENTRY.Akashic_Records.name, '阿[未][夏复]记录'),
(KEYWORDS_ASSIGNMENT_ENTRY.Legend_of_the_Puppet_Master.name, '^师传说'),
(KEYWORDS_ASSIGNMENT_ENTRY.The_Wages_of_Humanity.name, '[赠]养人类'),
(KEYWORDS_ASSIGNMENT_EVENT_GROUP.Space_Station_Task_Force.name,
'[新0]空间站特派[新]'),
],
'en': [
(KEYWORDS_ASSIGNMENT_EVENT_ENTRY.Food_Improvement_Plan.name,
'Food\s*[I]{0}mprovement Plan'),
(KEYWORDS_ASSIGNMENT_EVENT_GROUP.Space_Station_Task_Force.name,
'^(S[np]ace Station Ta[^sk]{0,3})?[F-]orce')
]
}
@ -78,14 +75,12 @@ class AssignmentOcr(Ocr):
return result
keyword_lang = self.lang
for keyword_class in (
KEYWORDS_ASSIGNMENT_ENTRY, KEYWORDS_ASSIGNMENT_EVENT_ENTRY,
KEYWORDS_ASSIGNMENT_GROUP, KEYWORDS_ASSIGNMENT_EVENT_GROUP,
KEYWORDS_ASSIGNMENT_ENTRY,
KEYWORDS_ASSIGNMENT_EVENT_ENTRY,
):
try:
matched = getattr(keyword_class, matched.lastgroup)
matched = getattr(keyword_class, matched.lastgroup, None)
if matched is not None:
break
except AttributeError:
continue
else:
raise ScriptError(f'No keyword found for {matched.lastgroup}')
matched = getattr(matched, keyword_lang)
@ -94,14 +89,29 @@ class AssignmentOcr(Ocr):
return matched
ASSIGNMENT_GROUP_LIST = DraggableList(
'AssignmentGroupList',
keyword_class=[AssignmentGroup, AssignmentEventGroup],
ocr_class=AssignmentOcr,
search_button=OCR_ASSIGNMENT_GROUP_LIST,
check_row_order=False,
active_color=(240, 240, 240),
drag_direction='right'
ASSIGNMENT_GROUP_SWITCH = Switch(
'AssignmentGroupSwitch',
is_selector=True
)
ASSIGNMENT_GROUP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_EVENT_GROUP.Space_Station_Task_Force,
check_button=SPACE_STATION_TASK_FORCE_CHECK,
click_button=SPACE_STATION_TASK_FORCE_CLICK
)
ASSIGNMENT_GROUP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.Character_Materials,
check_button=CHARACTER_MATERIALS_CHECK,
click_button=CHARACTER_MATERIALS_CLICK
)
ASSIGNMENT_GROUP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.EXP_Materials_Credits,
check_button=EXP_MATERIALS_CREDITS_CHECK,
click_button=EXP_MATERIALS_CREDITS_CLICK
)
ASSIGNMENT_GROUP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.Synthesis_Materials,
check_button=SYNTHESIS_MATERIALS_CHECK,
click_button=SYNTHESIS_MATERIALS_CLICK
)
ASSIGNMENT_ENTRY_LIST = DraggableList(
'AssignmentEntryList',
@ -124,12 +134,10 @@ class AssignmentUI(UI):
self.device.screenshot()
self.goto_group(KEYWORDS_ASSIGNMENT_GROUP.Character_Materials)
"""
selected = ASSIGNMENT_GROUP_LIST.get_selected_row(self)
if selected and selected.matched_keyword == group:
if ASSIGNMENT_GROUP_SWITCH.get(self) == group:
return
logger.hr('Assignment group goto', level=3)
self._wait_until_group_loaded()
if ASSIGNMENT_GROUP_LIST.select_row(group, self):
if ASSIGNMENT_GROUP_SWITCH.set(group, self):
self._wait_until_entry_loaded()
def goto_entry(self, entry: AssignmentEntry):
@ -228,10 +236,11 @@ class AssignmentUI(UI):
def _iter_groups(self) -> Iterator[AssignmentGroup]:
self._wait_until_group_loaded()
ASSIGNMENT_GROUP_LIST.insight_row(
KEYWORDS_ASSIGNMENT_GROUP.Character_Materials, self)
for button in ASSIGNMENT_GROUP_LIST.cur_buttons:
yield button.matched_keyword
for state in ASSIGNMENT_GROUP_SWITCH.state_list:
check = state['check_button']
click = state['click_button']
if ASSIGNMENT_GROUP_SWITCH.appear(check) or ASSIGNMENT_GROUP_SWITCH.appear(click):
yield state['state']
def _iter_entries(self) -> Iterator[AssignmentEntry]:
"""