from mower.utils import config
from mower.utils.graph import SceneGraphSolver
from mower.utils.image import diff_ratio
from mower.utils.log import logger
from mower.utils.scene import Scene


class Overview(SceneGraphSolver):
    solver_name = "进驻总览"

    def transition(self):
        if self.scene() == Scene.INFRA_ARRANGE:
            gray1 = config.recog.gray
            self.swipe_update([(625, 1000), (625, 200)], [300], 700)
            gray2 = config.recog.gray
            self.sleep(0.5)
            gray3 = config.recog.gray
            if diff_ratio(gray2, gray3, thresh=20):
                logger.info("gray2 != gray3 回弹")
            if not diff_ratio(gray1, gray3, thresh=20):
                logger.info("gray1 == gray3 到底")
                return True
            self.solver_update_before_transition = False
        else:
            self.scene_graph_step(Scene.INFRA_ARRANGE)
