Fix: Copy raw attributes of the first frame to all

This commit is contained in:
LmeSzinc 2024-01-15 02:47:53 +08:00
parent c493292181
commit 832b474a56
3 changed files with 26 additions and 14 deletions

View File

@ -108,6 +108,11 @@ class DataAssets:
color: t.Tuple[int, int, int] = ()
button: t.Tuple[int, int, int, int] = ()
has_raw_area = False
has_raw_search = False
has_raw_color = False
has_raw_button = False
@staticmethod
def area_to_search(area):
area = area_pad(area, pad=-20)
@ -131,12 +136,16 @@ class DataAssets:
self.button = image.bbox
elif image.attr == 'AREA':
self.area = image.bbox
self.has_raw_area = True
elif image.attr == 'SEARCH':
self.search = image.bbox
self.has_raw_search = True
elif image.attr == 'COLOR':
self.color = image.mean
self.has_raw_color = True
elif image.attr == 'BUTTON':
self.button = image.bbox
self.has_raw_button = True
else:
logger.warning(f'Trying to load an image with unknown attribute: {image}')
@ -182,19 +191,22 @@ def iter_assets():
# Set `search`
for path, frames in deep_iter(data, depth=3):
print(path, frames)
# If `search` attribute is set in the first frame, apply to all
first = frames[1]
if first.search:
for frame in frames.values():
for frame in frames.values():
# Generate `search` from `area`
if not frame.has_raw_search:
frame.search = DataAssets.area_to_search(frame.area)
# If an attribute is set in the first frame, apply to all
first: DataAssets = frames[1]
for frame in frames.values():
# frame: DataAssets = frame
if not frame.has_raw_area and first.has_raw_area:
frame.area = first.area
if not frame.has_raw_search and first.has_raw_search:
frame.search = first.search
else:
for frame in frames.values():
if frame.search:
# Follow frame specific `search`
pass
else:
# Generate `search` from `area`
frame.search = DataAssets.area_to_search(frame.area)
if not frame.has_raw_color and first.has_raw_color:
frame.color = first.color
if not frame.has_raw_button and first.has_raw_button:
frame.button = first.button
return data

View File

@ -62,7 +62,7 @@ GET_REWARD = ButtonWrapper(
area=(625, 144, 655, 168),
search=(605, 124, 675, 188),
color=(226, 0, 0),
button=(625, 144, 655, 168),
button=(741, 495, 1071, 644),
),
],
)

View File

@ -18,7 +18,7 @@ LOGIN_CONFIRM = ButtonWrapper(
area=(1109, 48, 1139, 73),
search=(1089, 28, 1159, 93),
color=(149, 145, 164),
button=(1109, 48, 1139, 73),
button=(683, 327, 1143, 620),
),
],
)