-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from runhey/dev
Dev
- Loading branch information
Showing
54 changed files
with
1,456 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This Python file uses the following encoding: utf-8 | ||
# @author runhey | ||
# github https://github.com/runhey | ||
import cv2 | ||
import time | ||
from datetime import timedelta, datetime | ||
from cached_property import cached_property | ||
from random import choice | ||
from pathlib import Path | ||
|
||
|
||
from module.exception import TaskEnd | ||
from module.logger import logger | ||
from module.base.timer import Timer | ||
|
||
from tasks.Script.config_device import ScreenshotMethod, ControlMethod | ||
from tasks.base_task import BaseTask | ||
from tasks.Exploration.version import highlight | ||
|
||
class GetAnimation(BaseTask): | ||
|
||
@cached_property | ||
def save_folder(self) -> Path: | ||
save_time = datetime.now().strftime('%Y%m%dT%H%M%S') | ||
save_folder = Path(f'./log/temp/{save_time}') | ||
save_folder.mkdir(parents=True, exist_ok=True) | ||
return save_folder | ||
|
||
def run_screenshot(self): | ||
self.config.model.script.device.screenshot_method = ScreenshotMethod.WINDOW_BACKGROUND | ||
run_timer = Timer(3) | ||
sho_timer = Timer(0.1) | ||
run_timer.start() | ||
sho_timer.start() | ||
save_images = {} | ||
while 1: | ||
if run_timer.reached(): | ||
break | ||
if sho_timer.reached(): | ||
sho_timer.reset() | ||
image = self.device.screenshot_window_background() | ||
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
image = highlight(image) | ||
time_now1 = int(time.time() * 1000) | ||
save_images[time_now1] = image | ||
for time_now, image in save_images.items(): | ||
cv2.imwrite(str(self.save_folder / f'all{time_now}.png'), image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This Python file uses the following encoding: utf-8 | ||
# @author runhey | ||
# github https://github.com/runhey | ||
import numpy as np | ||
|
||
from module.atom.image import RuleImage | ||
|
||
|
||
|
||
class RuleGif: | ||
# 大部分实现同RuleImage 的接口 | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.appear_target.name | ||
|
||
def __init__(self, targets: list[RuleImage]): | ||
self.targets = targets | ||
self.roi_front: list = [0, 0, 0, 0] | ||
self.appear_target = targets[0] | ||
|
||
def pre_process(self, image): | ||
return image | ||
|
||
|
||
def search(self, image, roi: list = None, threshold: float = None) -> tuple: | ||
""" | ||
:param image: | ||
:param roi: | ||
:param threshold: | ||
:return: bool | ||
第一项是否为出现, 第二项为匹配的RuleImage | ||
""" | ||
image = self.pre_process(image) | ||
# | ||
threshold = self.targets[0].threshold if threshold is None else threshold | ||
roi = self.targets[0].roi_back if roi is None else roi | ||
for target in self.targets: | ||
target.roi_back = roi | ||
if target.match(image, threshold): | ||
self.roi_front = target.roi_front | ||
self.appear_target = target | ||
return True, target | ||
return False, None | ||
|
||
def match(self, image, threshold: float = None) -> bool: | ||
return self.search(image, threshold=threshold)[0] | ||
|
||
|
||
def coord(self) -> tuple: | ||
x, y, w, h = self.roi_front | ||
return x + np.random.randint(0, w), y + np.random.randint(0, h) | ||
|
||
def front_center(self) -> tuple: | ||
x, y, w, h = self.roi_front | ||
return int(x + w//2), int(y + h//2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This Python file uses the following encoding: utf-8 | ||
# https://github.com/LmeSzinc/StarRailCopilot/blob/master/module/device/env.py | ||
import sys | ||
|
||
IS_WINDOWS = sys.platform == 'win32' | ||
IS_MACINTOSH = sys.platform == 'darwin' | ||
IS_LINUX = sys.platform == 'linux' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- 必须支持多人,队员队长和单人 三个模式 | ||
- 无脑启动 | ||
- 可选buff | ||
- 绘卷模式 | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.