Example #1
0
 def __check(self):
     if self.identify_image is None:
         logger.error("Error : {0} Identify Image not exists".format(
             self.name))
         exit(0)
     if self.tap_image is None:
         self.tap_image = self.identify_image
Example #2
0
def load_scenes(config, context):
    prefix = config.game_name + '/assets/scenes_feature/'
    if config.game_name == 'arknights':
        return arknights_scenes(prefix, config, context)
    elif config.game_name == 'azurelane':
        context.swipe_mode = config.default_swipe_direction
        return azurelane_scenes(prefix, config, context)
    else:
        logger.error('请指定游戏名称')
        exit(0)
Example #3
0
def load_scenes(config, context):
    prefix = './games/' + config.game_name + '/assets/'
    if config.game_name == 'arknights':
        return arknights_scenes(prefix, config, context)
    elif config.game_name == 'azurelane':
        return azurelane_scenes(prefix, config, context)
    elif config.game_name == 'girlsfrontline':
        return gf_scenes(prefix, config, context)
    else:
        logger.error('请指定游戏名称')
        exit(1)
Example #4
0
 def __check_screenshot(self):
     while True:
         if self.SCREENSHOT_WAY < 0:
             logger.error('暂不支持当前设备')
             sys.exit()
         try:
             im = self.__pull_screenshot()
             im.load()
             im.close()
             logger.info('采用方式 {} 获取截图'.format(self.SCREENSHOT_WAY))
             break
         except Exception as pssEx:
             logger.error(pssEx)
             self.SCREENSHOT_WAY -= 1
Example #5
0
    def __init__(self):
        try:
            # 从配置文件读取配置
            cfg = self.__load_configuration_file()
            self.device_type = cfg.get('global', 'device_type')
            self.device_dpi = cfg.getint('global', 'device_dpi')
            self.game_name = cfg.get('global', 'game_name')
            self.repeat_count_max = cfg.getint('global', 'repeat_count_max')
            self.use_stone_max = cfg.getint('arknights', 'use_stone_max')
            self.use_pharmacy_max = cfg.getint('arknights', 'use_pharmacy_max')
            self.battle_no = cfg.get('azurelane', 'battle_no')
            self.default_swipe_direction = cfg.getint(
                'azurelane', 'default_swipe_direction')

            # 如果有命令行参数,更新覆盖配置
            self.__override_from_command_line()

            logger.info(self)
        except Exception as ex:
            logger.error(ex)
Example #6
0
# coding: utf-8

import time
from common.logutil import logger
try:
    from common import tool
    from common.scene import Scene
except Exception as importEx:
    logger.error(importEx)
    exit(1)


class EventLoop:
    scenes = None
    device = None
    vars = None

    def __init__(self, scenes, device, context=None):
        self.scenes = scenes
        self.device = device
        self.vars = context

    def recognize_and_process_page(self):
        screen = self.device.screen_capture_handler()
        if screen is None:
            return

        # 场景匹配
        matched = None
        for scene in self.scenes:
            possible_targets = scene.matched_in(screen)
Example #7
0
import numpy
import sys
import os
import subprocess

from io import StringIO
from PIL import ImageFile, Image
from common.logutil import logger

sys.path.insert(1, '../common')

try:
    from common.device.i_device import Device
    from common.device.adb import Adb
except Exception as ex:
    logger.error(ex)
    logger.error('请检查项目根目录中的 common 文件夹是否存在')
    exit(1)

screen_name = 'screen.png'
screen_path = './temp/' + screen_name
ImageFile.LOAD_TRUNCATED_IMAGES = True


class AndroidDevice(Device):
    SCREENSHOT_WAY = 3
    adb = None

    def __init__(self, address=''):
        self.adb = Adb(device=address)
        self.adb.test_device()
Example #8
0

def load_scenes(config, context):
    prefix = config.game_name + '/assets/scenes_feature/'
    if config.game_name == 'arknights':
        return arknights_scenes(prefix, config, context)
    elif config.game_name == 'azurelane':
        context.swipe_mode = config.default_swipe_direction
        return azurelane_scenes(prefix, config, context)
    else:
        logger.error('请指定游戏名称')
        exit(0)


if sys.version_info.major != 3:
    logger.error('请使用python3.x版本')
    exit(1)

if __name__ == '__main__':
    try:
        # 1. init config
        cfg = Config()
        ctx = Context()

        # 2. init scenes
        scenes = load_scenes(cfg, ctx)

        # 3. init device
        if cfg.device_type == 'ios':
            device = IOSDevice(cfg.device_dpi, address='http://127.0.0.1:8100')
        elif cfg.device_type == 'android':