From cbaef849d24b3d818802a776e488b75be0edd68c Mon Sep 17 00:00:00 2001 From: Mou Lai Date: Fri, 11 Oct 2024 19:02:03 +0800 Subject: [PATCH] Initial commit --- .github/workflows/check.yml | 36 +++ .github/workflows/install.yml | 197 +++++++++++ .gitignore | 448 ++++++++++++++++++++++++++ .gitmodules | 3 + .vscode/settings.json | 33 ++ LICENSE | 21 ++ README.md | 129 ++++++++ assets/MaaCommonAssets | 1 + assets/interface.json | 74 +++++ assets/resource/image/empty.png | 1 + assets/resource/model/.gitignore | 1 + assets/resource/pipeline/my_task.json | 5 + check_resource.py | 39 +++ configure.py | 28 ++ deps/.gitkeep | 1 + install.py | 78 +++++ 16 files changed, 1095 insertions(+) create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/install.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 README.md create mode 160000 assets/MaaCommonAssets create mode 100644 assets/interface.json create mode 100644 assets/resource/image/empty.png create mode 100644 assets/resource/model/.gitignore create mode 100644 assets/resource/pipeline/my_task.json create mode 100644 check_resource.py create mode 100644 configure.py create mode 100644 deps/.gitkeep create mode 100644 install.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..eede63c --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,36 @@ +name: check + +on: + push: + branches: + - "**" + paths: + - ".github/workflows/check.yml" + - "assets/**" + - "**.py" + pull_request: + branches: + - "**" + paths: + - ".github/workflows/check.yml" + - "assets/**" + - "**.py" + workflow_dispatch: + +jobs: + resource: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # pip install maafw + - name: Install maafw + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade maafw --pre + + - name: Check Resource + run: | + python ./check_resource.py ./assets/resource/ diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000..1cc519e --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,197 @@ +name: install + +on: + push: + tags: + - "v*" + branches: + - "**" + paths: + - ".github/workflows/install.yml" + - "assets/**" + - "**.py" + pull_request: + branches: + - "**" + paths: + - ".github/workflows/install.yml" + - "assets/**" + - "**.py" + workflow_dispatch: + +jobs: + meta: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: set_tag + run: | + is_release=${{ startsWith(github.ref, 'refs/tags/v') }} + tag=$(git describe --tags --match "v*" ${{ github.ref }} || true) + if [[ $tag != v* ]]; then + tag=$(curl -sX GET "https://api.github.com/repos/${{ github.repository }}/releases/latest" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | awk '/tag_name/{print $4}' FS='["]') + if [[ $tag != v* ]]; then + tag="v0.0.0" + fi + tag=$(date "+$tag-%y%m%d-$(git rev-parse --short HEAD)") + fi + if ! $($is_release) ; then + prefix=${tag%-*-*} + suffix=${tag#$prefix-} + tag="$prefix-ci.$suffix" + fi + + echo tag=$tag | tee -a $GITHUB_OUTPUT + echo is_release=$is_release | tee -a $GITHUB_OUTPUT + outputs: + tag: ${{ steps.set_tag.outputs.tag }} + is_release: ${{ steps.set_tag.outputs.is_release }} + + windows: + needs: meta + runs-on: windows-latest + strategy: + matrix: + arch: [aarch64, x86_64] + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Download MaaFramework + uses: robinraju/release-downloader@v1 + with: + repository: MaaXYZ/MaaFramework + fileName: "MAA-win-${{ matrix.arch }}*" + latest: true + out-file-path: "deps" + extract: true + + - name: Install + shell: bash + run: | + python ./install.py ${{ needs.meta.outputs.tag }} + + - uses: actions/upload-artifact@v4 + with: + name: MaaXXX-win-${{ matrix.arch }} + path: "install" + + ubuntu: + needs: meta + runs-on: ubuntu-latest + strategy: + matrix: + arch: [aarch64, x86_64] + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Download MaaFramework + uses: robinraju/release-downloader@v1 + with: + repository: MaaXYZ/MaaFramework + fileName: "MAA-linux-${{ matrix.arch }}*" + latest: true + out-file-path: "deps" + extract: true + + - name: Install + shell: bash + run: | + python ./install.py ${{ needs.meta.outputs.tag }} + + - uses: actions/upload-artifact@v4 + with: + name: MaaXXX-linux-${{ matrix.arch }} + path: "install" + + macos: + needs: meta + runs-on: macos-latest + strategy: + matrix: + arch: [aarch64, x86_64] + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Download MaaFramework + uses: robinraju/release-downloader@v1 + with: + repository: MaaXYZ/MaaFramework + fileName: "MAA-macos-${{ matrix.arch }}*" + latest: true + out-file-path: "deps" + extract: true + + - name: Install + shell: bash + run: | + python ./install.py ${{ needs.meta.outputs.tag }} + + - uses: actions/upload-artifact@v4 + with: + name: MaaXXX-macos-${{ matrix.arch }} + path: "install" + + android: + needs: meta + runs-on: macos-latest + strategy: + matrix: + arch: [aarch64, x86_64] + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Download MaaFramework + uses: robinraju/release-downloader@v1 + with: + repository: MaaXYZ/MaaFramework + fileName: "MAA-android-${{ matrix.arch }}*" + latest: true + out-file-path: "deps" + extract: true + + - name: Install + shell: bash + run: | + python ./install.py ${{ needs.meta.outputs.tag }} + + - uses: actions/upload-artifact@v4 + with: + name: MaaXXX-android-${{ matrix.arch }} + path: "install" + + release: + if: ${{ needs.meta.outputs.is_release == 'true' }} + needs: [meta, windows, ubuntu, macos, android] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + path: assets + + - run: | + cd assets + for f in *; do + (cd $f && zip -r ../$f-${{ needs.meta.outputs.tag }}.zip .) + done + - uses: softprops/action-gh-release@v2 + with: + files: assets/* + tag_name: ${{ needs.meta.outputs.tag }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a652f0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,448 @@ +# docs +docs/node_modules +docs/.vuepress/.temp +# Prerequisites +*.d + +# Compiled Object files +build +build-* +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod +!go.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +Debug +Release +.vs +*.vcxproj.user +*.swp + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ +cmake-build-debug/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Nuget personal access tokens and Credentials +nuget.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +**/.vscode/* +.vscode/* +!.vscode/settings.json +# !.vscode/tasks.json +# !.vscode/launch.json +# !.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +.idea/ +*.sln.iml + +enc_temp_folder/* + +# Nuke +.nuke/temp/* + +# Build +deps +build +install + +# Tools +tools/ImageCropper/**/*.png diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..77e2077 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assets/MaaCommonAssets"] + path = assets/MaaCommonAssets + url = https://github.com/MaaXYZ/MaaCommonAssets diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3cdb8c6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,33 @@ +{ + "json.schemas": [ + { + "fileMatch": [ + "/assets/resource/**/*.json", + "/install/resource/**/*.json" + ], + "url": "/deps/tools/pipeline.schema.json" + }, + { + "fileMatch": [ + "/assets/interface.json", + "/install/interface.json" + ], + "url": "/deps/tools/interface.schema.json" + }, + { + "fileMatch": [ + "/install/config/maa_pi_config.json" + ], + "url": "/deps/tools/interface_config.schema.json" + } + ], + "[json]": { + "editor.formatOnSave": true, + "editor.insertSpaces": true, + "editor.tabSize": 4, + "editor.indentSize": "tabSize" + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..34faa45 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 MaaXYZ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e047a1d --- /dev/null +++ b/README.md @@ -0,0 +1,129 @@ + +

+ LOGO +

+ +
+ +# MaaPracticeBoilerplate + +
+ +本仓库为 [MaaFramework](https://github.com/MaaXYZ/MaaFramework) 所提供的项目模板,开发者可基于此模板直接创建自己的 MaaXXX 项目。 + +> **MaaFramework** 是基于图像识别技术、运用 [MAA](https://github.com/MaaAssistantArknights/MaaAssistantArknights) 开发经验去芜存菁、完全重写的新一代自动化黑盒测试框架。 +> 低代码的同时仍拥有高扩展性,旨在打造一款丰富、领先、且实用的开源库,助力开发者轻松编写出更好的黑盒测试程序,并推广普及。 + +## 即刻开始 + +- [⭐ 开发思路](https://github.com/MaaXYZ/MaaFramework/blob/main/docs/zh_cn/0.1-%E5%BC%80%E5%8F%91%E6%80%9D%E8%B7%AF.md) +- [📄 资源准备](https://github.com/MaaXYZ/MaaFramework/blob/main/docs/zh_cn/1.1-%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B.md) +- [🎞️ 视频教程](https://www.bilibili.com/video/BV1yr421E7MW) + +## 如何开发 + +0. 使用右上角 `Use this template` - `Create a new repository` 来基于本模板创建您自己的项目。 + +1. 完整克隆本项目及子项目(地址请修改为您基于本模板创建的新项目地址)。 + + ```bash + git clone --recursive https://github.com/MaaXYZ/MaaPracticeBoilerplate.git + ``` + + **请注意,一定要完整克隆子项目,不要漏了 `--recursive`,也不要下载 zip 包!** 这步未正确操作会导致所有 OCR(文字识别)失败! + +2. 下载 MaaFramework 的 [Release 包](https://github.com/MaaXYZ/MaaFramework/releases),解压到 `deps` 文件夹中。 + +3. 配置资源文件。 + + ```bash + python ./configure.py + ``` + +4. 按需求修改 `assets` 中的资源文件,请参考 MaaFramework 相关文档。 + + - 可使用 [MaaDebugger](https://github.com/MaaXYZ/MaaDebugger) 进行调试; + - 也可以在本地安装后测试: + + 1. 执行安装脚本 + + ```bash + python ./install.py + ``` + + 2. 运行 `install/MaaPiCli.exe` + +5. 完成开发工作后,上传您的代码并发布版本。 + + ```bash + # 配置 git 信息(仅第一次需要,后续不用再配置) + git config user.name "您的 GitHub 昵称" + git config user.email "您的 GitHub 邮箱" + + # 提交修改 + git add . + git commit -m "XX 新功能" + git push origin HEAD -u + ``` + +6. 发布您的版本 + + 需要先修改仓库设置 `Settings` - `Actions` - `General` - `Read and write permissions` - `Save` + + ```bash + # CI 检测到 tag 会自动进行发版 + git tag v1.0.0 + git push origin v1.0.0 + ``` + +## 生态共建 + +MAA 正计划建设为一类项目,而非舟的单一软件。 + +若您的项目依赖于 MaaFramework,我们欢迎您将它命名为 MaaXXX, MXA, MAX 等等。当然,这是许可而不是限制,您也可以自由选择其他与 MAA 无关的名字,完全取决于您自己的想法! + +同时,我们也非常欢迎您提出 PR,在 [最佳实践列表](https://github.com/MaaXYZ/MaaFramework#%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5) 中添加上您的项目! + +## FAQ + +### 1. 我是第一次使用 Python,在命令行输入 `python ./configure.py` 或 `python -m pip install MaaFW` 之后没有反应?没有报错,也没有提示成功,什么都没有 + +Win10 或者 Win11 系统自带了一份 "Python",但它其实只是一个安装器,是没法用的。 +你需要做的是关闭它或者删除它的环境变量,然后自己去 Python 官网下载并安装一份 Python。 +[参考方法](https://www.bilibili.com/read/cv24692025/) + +### 2. 我输入 `python ./configure.py` 后报错:`Please clone this repository completely, don’t miss "--recursive", and don’t download the zip package!` + +![项目不完整1](https://github.com/user-attachments/assets/e1f697c0-e5b6-4853-8664-a358df7327a8) + +**请仔细阅读文档!!!** +就是你现在正在看的本篇文档,就在上面,“如何开发”里的第一条,都已经用粗体标出来了,再问我要骂人了! + +### 3. 使用 MaaDebugger 或 MaaPicli 时弹窗报错,应用程序错误:应用程序无法正常启动 + +![缺少运行库](https://github.com/user-attachments/assets/942df84b-f47d-4bb5-98b5-ab5d44bc7c2a) + +一般是电脑缺少某些运行库,请安装一下 [vc_redist](https://aka.ms/vs/17/release/vc_redist.x64.exe) 。 + +### 4. 我在这个仓库里提了 Issue 很久没人回复 + +这里是《项目模板》仓库,它仅仅是一个模板,一般很少会修改,开发者也较少关注。 +在此仓库请仅提问模板相关问题,其他问题最好前往对应的仓库提出,如果有 log,最好也带上它(`debug/maa.log` 文件) + +- MaaFW 本身及 MaaPiCli 的问题:[MaaFramework/issues](https://github.com/MaaXYZ/MaaFramework/issues) +- MaaDebugger 的问题:[MaaDebugger/issues](https://github.com/MaaXYZ/MaaDebugger/issues) +- 不知道算是哪里的、其他疑问等:[讨论区](https://github.com/orgs/MaaXYZ/discussions) + +### 5. OCR 文字识别一直没有识别结果,报错 "Failed to load det or rec", "ocrer_ is null" + +你不但没有仔细阅读文档,还无视了前面步骤的报错。我不想解释了,请再把本文档仔细阅读一遍! + +## 鸣谢 + +本项目由 **[MaaFramework](https://github.com/MaaXYZ/MaaFramework)** 强力驱动! + +感谢以下开发者对本项目作出的贡献(下面链接改成你自己的项目地址): + + + + diff --git a/assets/MaaCommonAssets b/assets/MaaCommonAssets new file mode 160000 index 0000000..33f3ba4 --- /dev/null +++ b/assets/MaaCommonAssets @@ -0,0 +1 @@ +Subproject commit 33f3ba463ea5979138f85e91bb43d065fc7b5d4b diff --git a/assets/interface.json b/assets/interface.json new file mode 100644 index 0000000..30e1352 --- /dev/null +++ b/assets/interface.json @@ -0,0 +1,74 @@ +{ + "controller": [ + { + "name": "安卓端", + "type": "Adb" + }, + { + "name": "桌面端", + "type": "Win32", + "win32": { + "class_regex": ".*", + "window_regex": "Visual Studio" + } + } + ], + "resource": [ + { + "name": "官服", + "path": [ + "{PROJECT_DIR}/resource" + ] + }, + { + "name": "B 服", + "path": [ + "{PROJECT_DIR}/resource", + "{PROJECT_DIR}/resource_bilibili" + ] + } + ], + "task": [ + { + "name": "普通任务", + "entry": "MyTask1" + }, + { + "name": "选项任务", + "entry": "MyTask2", + "option": [ + "任务选项1" + ] + }, + { + "name": "参数任务", + "entry": "MyTask3", + "option": [ + "任务选项1" + ], + "pipeline_override": {} + } + ], + "option": { + "任务选项1": { + "cases": [ + { + "name": "文本1", + "pipeline_override": { + "OcrTask": { + "text": "文本1" + } + } + }, + { + "name": "文本2", + "pipeline_override": { + "OcrTask": { + "text": "文本2" + } + } + } + ] + } + } +} diff --git a/assets/resource/image/empty.png b/assets/resource/image/empty.png new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/assets/resource/image/empty.png @@ -0,0 +1 @@ + diff --git a/assets/resource/model/.gitignore b/assets/resource/model/.gitignore new file mode 100644 index 0000000..37faf48 --- /dev/null +++ b/assets/resource/model/.gitignore @@ -0,0 +1 @@ +ocr \ No newline at end of file diff --git a/assets/resource/pipeline/my_task.json b/assets/resource/pipeline/my_task.json new file mode 100644 index 0000000..581eaa8 --- /dev/null +++ b/assets/resource/pipeline/my_task.json @@ -0,0 +1,5 @@ +{ + "MyTask1": {}, + "MyTask2": {}, + "MyTask3": {} +} \ No newline at end of file diff --git a/check_resource.py b/check_resource.py new file mode 100644 index 0000000..229daef --- /dev/null +++ b/check_resource.py @@ -0,0 +1,39 @@ +import sys + +from typing import List +from pathlib import Path + +from maa.resource import Resource +from maa.tasker import Tasker, LoggingLevelEnum + + +def check(dirs: List[Path]) -> bool: + resource = Resource() + + print(f"Checking {len(dirs)} directories...") + + for dir in dirs: + print(f"Checking {dir}...") + status = resource.post_path(dir).wait().status() + if not status.succeeded(): + print(f"Failed to check {dir}.") + return False + + print("All directories checked.") + return True + + +def main(): + if len(sys.argv) < 2: + print("Usage: python configure.py ") + sys.exit(1) + + Tasker.set_stdout_level(LoggingLevelEnum.All) + + dirs = [Path(arg) for arg in sys.argv[1:]] + if not check(dirs): + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/configure.py b/configure.py new file mode 100644 index 0000000..8af89d9 --- /dev/null +++ b/configure.py @@ -0,0 +1,28 @@ +from pathlib import Path + +import shutil + +assets_dir = Path(__file__).parent / "assets" + + +def configure_ocr_model(): + if not (assets_dir / "MaaCommonAssets" / "OCR").exists(): + print("Please clone this repository completely, don’t miss \"--recursive\", and don’t download the zip package!") + print("请完整克隆本仓库,不要漏掉 \"--recursive\",也不要下载 zip 包!") + exit(1) + + ocr_dir = assets_dir / "resource" / "model" / "ocr" + if not ocr_dir.exists(): # copy default OCR model only if dir does not exist + shutil.copytree( + assets_dir / "MaaCommonAssets" / "OCR" / "ppocr_v4" / "zh_cn", + ocr_dir, + dirs_exist_ok=True, + ) + else: + print("Found existing OCR directory, skipping default OCR model import.") + + +if __name__ == "__main__": + configure_ocr_model() + + print("OCR model configured.") \ No newline at end of file diff --git a/deps/.gitkeep b/deps/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/deps/.gitkeep @@ -0,0 +1 @@ + diff --git a/install.py b/install.py new file mode 100644 index 0000000..155c812 --- /dev/null +++ b/install.py @@ -0,0 +1,78 @@ +from pathlib import Path + +import shutil +import sys +import json + +from configure import configure_ocr_model + + +working_dir = Path(__file__).parent +install_path = working_dir / Path("install") +version = len(sys.argv) > 1 and sys.argv[1] or "v0.0.1" + + +def install_deps(): + if not (working_dir / "deps" / "bin").exists(): + print("Please download the MaaFramework to \"deps\" first.") + print("请先下载 MaaFramework 到 \"deps\"。") + sys.exit(1) + + shutil.copytree( + working_dir / "deps" / "bin", + install_path, + ignore=shutil.ignore_patterns( + "*MaaDbgControlUnit*", + "*MaaThriftControlUnit*", + "*MaaRpc*", + "*MaaHttp*", + ), + dirs_exist_ok=True, + ) + shutil.copytree( + working_dir / "deps" / "share" / "MaaAgentBinary", + install_path / "MaaAgentBinary", + dirs_exist_ok=True, + ) + + +def install_resource(): + + configure_ocr_model() + + shutil.copytree( + working_dir / "assets" / "resource", + install_path / "resource", + dirs_exist_ok=True, + ) + shutil.copy2( + working_dir / "assets" / "interface.json", + install_path, + ) + + with open(install_path / "interface.json", "r", encoding="utf-8") as f: + interface = json.load(f) + + interface["version"] = version + + with open(install_path / "interface.json", "w", encoding="utf-8") as f: + json.dump(interface, f, ensure_ascii=False, indent=4) + + +def install_chores(): + shutil.copy2( + working_dir / "README.md", + install_path, + ) + shutil.copy2( + working_dir / "LICENSE", + install_path, + ) + + +if __name__ == "__main__": + install_deps() + install_resource() + install_chores() + + print(f"Install to {install_path} successfully.") \ No newline at end of file