Skip to content

Commit

Permalink
update pre-commit and format all files (#80)
Browse files Browse the repository at this point in the history
* update pre-commit-config

* meet pre-commit requirements

* fix bug caused by last commit

* fix new code pre-commit

* bump version

* update README
  • Loading branch information
0xWelt authored Oct 24, 2024
1 parent 902ade4 commit fa97ac2
Show file tree
Hide file tree
Showing 74 changed files with 2,795 additions and 2,641 deletions.
43 changes: 33 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_stages: [pre-commit, pre-push, manual]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-symlinks
- id: destroyed-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
exclude: autowsgr/data/map/
- id: check-toml
- id: check-ast
- id: check-added-large-files
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: debug-statements
- repo: https://github.com/psf/black
rev: 24.8.0
- id: double-quote-string-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
hooks:
- id: black
- id: black-jupyter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py310-plus]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: [".[toml]"]
exclude: |
(?x)(
^examples/.*\.(txt|json)$
)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

## 近期更新

- 计划弃用 `paddleocr` 后端, 请及时修改自己的 `user_settings.yaml` 中对应参数, 兼容性还将保持一段时间. **2024/10/06**
- 已弃用 Python 3.9,请升级 Python>=3.10. 2024/10/24
- 计划弃用 `paddleocr` 后端, 请及时修改自己的 `user_settings.yaml``OCR_BACKEND``easyocr`. **2024/10/06**
- 任务调度支持决战、战役、演习和活动. **2024/10/03**
- 蓝叠模拟器的连接方法改为手动填写adb地址. **2024/10/02**
- 支持当前活动 "征程启航",请重新下载example文件夹中的plans和event.py文件.活动先关的使用方法可以参考[这里](https://sincere-theater-0e6.notion.site/fb9bbe5a4b0a426db59ac7892645ee1b)**2024/09/30**
Expand Down
2 changes: 1 addition & 1 deletion autowsgr/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.2.0"
__version__ = '1.0.3.0'
64 changes: 32 additions & 32 deletions autowsgr/constants/colors.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
class COLORS:
"""存储一些用于鉴定状态的颜色信息
所有颜色为 RGB 格式
"""

CHALLENGE_BLUE = (33, 132, 226) # 演习界面,挑战按钮的颜色
SUPPORT_ENABLE = (228, 182, 60) # 支援启用的黄色
SUPPORT_DISABLE = (44, 142, 239) # 支援禁用的蓝色
SUPPORT_ENLESS = (143, 145, 154) # 支援次数用尽的灰色
BLOOD_COLORS = [
[
(69, 162, 117),
(246, 184, 51),
(
230,
58,
89,
),
(96, 91, 92),
(43, 87, 112),
],
[
(70, 182, 88),
(238, 186, 64),
(166, 33, 3),
],
]

"""血条的 RGB 格式颜色,[0] 为准备界面,[1] 为战斗结算接界面
[0]从右到左依次为 [0] 绿色,[1] 黄色,[2] 红色,[3] 黑色,[4] 蓝色
[1]从左到右依次为 [0] 绿色,[1] 黄色,[2] 红色
"""
class COLORS:
"""存储一些用于鉴定状态的颜色信息
所有颜色为 RGB 格式
"""

CHALLENGE_BLUE = (33, 132, 226) # 演习界面,挑战按钮的颜色
SUPPORT_ENABLE = (228, 182, 60) # 支援启用的黄色
SUPPORT_DISABLE = (44, 142, 239) # 支援禁用的蓝色
SUPPORT_ENLESS = (143, 145, 154) # 支援次数用尽的灰色
BLOOD_COLORS = (
(
(69, 162, 117),
(246, 184, 51),
(
230,
58,
89,
),
(96, 91, 92),
(43, 87, 112),
),
(
(70, 182, 88),
(238, 186, 64),
(166, 33, 3),
),
)

"""血条的 RGB 格式颜色,[0] 为准备界面,[1] 为战斗结算接界面
[0]从右到左依次为 [0] 绿色,[1] 黄色,[2] 红色,[3] 黑色,[4] 蓝色
[1]从左到右依次为 [0] 绿色,[1] 黄色,[2] 红色
"""
8 changes: 4 additions & 4 deletions autowsgr/constants/custom_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class ImageNotFoundErr(BaseException):
def __init__(self, *args: object):
def __init__(self, *args: object) -> None:
super().__init__(*args)


class NetworkErr(BaseException):
def __init__(self, *args: object):
def __init__(self, *args: object) -> None:
super().__init__(*args)


Expand All @@ -20,10 +20,10 @@ class CriticalErr(BaseException):
BaseException (_type_): _description_
"""

def __init__(self, *args: object):
def __init__(self, *args: object) -> None:
super().__init__(*args)


class LogitException(BaseException):
def __init__(self, *args: object):
def __init__(self, *args: object) -> None:
super().__init__()(*args)
17 changes: 9 additions & 8 deletions autowsgr/constants/data_roots.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from os.path import dirname, join

DATA_ROOT = join(dirname(dirname(__file__)), "data")
IMG_ROOT = join(DATA_ROOT, "images")
MAP_ROOT = join(DATA_ROOT, "map")
SETTING_ROOT = join(DATA_ROOT, "settings")
OCR_ROOT = join(DATA_ROOT, "ocr")

BIN_ROOT = join(dirname(DATA_ROOT), "bin")
TUNNEL_ROOT = join(BIN_ROOT, "image_recognize")
ADB_ROOT = join(BIN_ROOT, "adb")
DATA_ROOT = join(dirname(dirname(__file__)), 'data')
IMG_ROOT = join(DATA_ROOT, 'images')
MAP_ROOT = join(DATA_ROOT, 'map')
SETTING_ROOT = join(DATA_ROOT, 'settings')
OCR_ROOT = join(DATA_ROOT, 'ocr')

BIN_ROOT = join(dirname(DATA_ROOT), 'bin')
TUNNEL_ROOT = join(BIN_ROOT, 'image_recognize')
ADB_ROOT = join(BIN_ROOT, 'adb')
39 changes: 17 additions & 22 deletions autowsgr/constants/image_templates.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
from functools import partial

from airtest.core.cv import (
MATCHING_METHODS,
ST,
InvalidMatchingMethodError,
TargetPos,
Template,
)
from airtest.core.settings import Settings as ST
from airtest.core.cv import MATCHING_METHODS, ST, InvalidMatchingMethodError, TargetPos, Template

from autowsgr.constants.data_roots import IMG_ROOT
from autowsgr.utils.io import create_namespace


class MyTemplate(Template):
def __radd__(self, other):
def __radd__(self, other) -> list:
if isinstance(other, list):
return other + [self] # 添加到列表开头
else:
return NotImplemented
return [*other, self] # 添加到列表开头
return NotImplemented

def __add__(self, other):
def __add__(self, other) -> list:
if isinstance(other, list):
return [self] + other # 添加到列表末尾
else:
return NotImplemented
return [self, *other] # 添加到列表末尾
return NotImplemented

def match_in(self, screen, this_methods=None):
match_result = self._cv_match(screen, this_methods)
if not match_result:
return None
focus_pos = TargetPos().getXY(match_result, self.target_pos)
return focus_pos
return TargetPos().getXY(match_result, self.target_pos)

def _cv_match(self, screen, this_methods=None):
ori_image = self._imread()
Expand All @@ -44,9 +34,9 @@ def _cv_match(self, screen, this_methods=None):
func = MATCHING_METHODS.get(method, None)
if func is None:
raise InvalidMatchingMethodError(
f"Undefined method in CVSTRATEGY: '{method}', try 'kaze'/'brisk'/'akaze'/'orb'/'surf'/'sift'/'brief' instead."
f"Undefined method in CVSTRATEGY: '{method}', try 'kaze'/'brisk'/'akaze'/'orb'/'surf'/'sift'/'brief' instead.",
)
if method in ["mstpl", "gmstpl"]:
if method in ['mstpl', 'gmstpl']:
ret = self._try_match(
func,
ori_image,
Expand All @@ -60,13 +50,18 @@ def _cv_match(self, screen, this_methods=None):
)
else:
ret = self._try_match(
func, image, screen, threshold=self.threshold, rgb=self.rgb
func,
image,
screen,
threshold=self.threshold,
rgb=self.rgb,
)
if ret:
break
return ret


IMG = create_namespace(
IMG_ROOT, partial(MyTemplate, threshold=0.9, resolution=(960, 540))
IMG_ROOT,
partial(MyTemplate, threshold=0.9, resolution=(960, 540)),
)
10 changes: 5 additions & 5 deletions autowsgr/constants/literals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOCK_FULL_FLAG = "dock is full"
FIGHT_END_FLAG = "fight end"
FIGHT_CONTINUE_FLAG = "fight continue"
OPERATION_SUCCESS_FLAG = "success"
BATTLE_TIMES_EXCEED = "out of times"
DOCK_FULL_FLAG = 'dock is full'
FIGHT_END_FLAG = 'fight end'
FIGHT_CONTINUE_FLAG = 'fight continue'
OPERATION_SUCCESS_FLAG = 'success'
BATTLE_TIMES_EXCEED = 'out of times'
Loading

0 comments on commit fa97ac2

Please sign in to comment.