mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2025-12-17 00:15:13 +00:00
feat: support load search for buttons
This commit is contained in:
parent
9604e8962a
commit
04853b6c31
@ -144,16 +144,25 @@ class ButtonWrapper(Resource):
|
|||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def iter_buttons(self) -> t.Iterator[Button]:
|
||||||
|
for _, assets in self.data_buttons.items():
|
||||||
|
if isinstance(assets, Button):
|
||||||
|
yield assets
|
||||||
|
elif isinstance(assets, list):
|
||||||
|
for asset in assets:
|
||||||
|
yield asset
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def buttons(self) -> t.List[Button]:
|
def buttons(self) -> t.List[Button]:
|
||||||
# for trial in [server.lang, 'share', 'cn']:
|
for trial in [server.lang, 'share', 'cn']:
|
||||||
for trial in [server.lang, 'share', 'jp']:
|
try:
|
||||||
assets = self.data_buttons.get(trial, None)
|
assets = self.data_buttons[trial]
|
||||||
if assets is not None:
|
|
||||||
if isinstance(assets, Button):
|
if isinstance(assets, Button):
|
||||||
return [assets]
|
return [assets]
|
||||||
elif isinstance(assets, list):
|
elif isinstance(assets, list):
|
||||||
return assets
|
return assets
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
raise ScriptError(f'ButtonWrapper({self}) on server {server.lang} has no fallback button')
|
raise ScriptError(f'ButtonWrapper({self}) on server {server.lang} has no fallback button')
|
||||||
|
|
||||||
@ -222,13 +231,24 @@ class ButtonWrapper(Resource):
|
|||||||
"""
|
"""
|
||||||
if isinstance(button, ButtonWrapper):
|
if isinstance(button, ButtonWrapper):
|
||||||
button = button.matched_button
|
button = button.matched_button
|
||||||
for b in self.buttons:
|
for b in self.iter_buttons():
|
||||||
b.load_offset(button)
|
b.load_offset(button)
|
||||||
|
|
||||||
def clear_offset(self):
|
def clear_offset(self):
|
||||||
for b in self.buttons:
|
for b in self.iter_buttons():
|
||||||
b.clear_offset()
|
b.clear_offset()
|
||||||
|
|
||||||
|
def load_search(self, area):
|
||||||
|
"""
|
||||||
|
Set `search` attribute.
|
||||||
|
Note that this method is irreversible.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
area:
|
||||||
|
"""
|
||||||
|
for b in self.iter_buttons():
|
||||||
|
b.search = area
|
||||||
|
|
||||||
|
|
||||||
class ClickButton:
|
class ClickButton:
|
||||||
def __init__(self, area, button=None, name='CLICK_BUTTON'):
|
def __init__(self, area, button=None, name='CLICK_BUTTON'):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user