add function to check position and find all matches on screen

This commit is contained in:
2026-04-21 19:22:47 +02:00
parent d015689a6f
commit 6f44817a1f
2 changed files with 40 additions and 10 deletions
+25 -2
View File
@@ -16,7 +16,7 @@ except ImportError as e:
class Command:
"""Dataclass for commands"""
__AUTHOR__ = 'anima'
__VERSION__ = '1.0.0'
__VERSION__ = '1.1.3'
image_dir: Path = Path('images/')
supported_extensions = {".png", ".jpg", ".jpeg", ".bmp"}
@@ -63,4 +63,27 @@ class Command:
return self.valid
def check_position(self, )
def check_position(self, position: tuple) -> bool:
"""check if image on expected position
Args:
position (tuple): expected x, y position
Returns:
bool: True if image on expected position
"""
if self.position is None:
logging.debug('no expected position set, skip check')
return True
if not isinstance(position, tuple):
logging.debug(f'position check get wrong value {position=} ({type(position)})')
return False
i_x, i_y = self.position
p_x, p_y = position
if (i_x - self.pos_dif) < int(p_x) < (i_x + self.pos_dif) and \
(i_y - self.pos_dif) < int(p_y) < (i_y + self.pos_dif):
return True
else:
logging.debug(f'image is not on expected {position=}')
return False