Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Project Interface and CLI #137

Merged
merged 12 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ option(WITH_THRIFT_CONTROLLER "build with thrift controller" ON)
option(WITH_DBG_CONTROLLER "build with debugging controller" ON)
option(WITH_WIN32_CONTROLLER "build with win32 controller" ON)

option(WITH_GRPC "build with protobuf and grpc" ON)
option(WITH_GRPC "build with protobuf and grpc" OFF)

option(BUILD_GRPC_CLI "build grpc CLI exec" ON)
option(BUILD_GRPC_CLI "build grpc CLI exec" OFF)

option(BUILD_SAMPLE "build a demo" OFF)

Expand Down
36 changes: 12 additions & 24 deletions docs/en_us/1.1-QuickStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. Download the MaaFramework Release
2. Prepare Resource Files
3. Use a Generic GUI or Write Integration Code
3. Use a Generic CLI or Write Integration Code

## Download the MaaFramework Release

Expand All @@ -22,10 +22,9 @@ my_resource
│ ├── det.onnx
│ ├── keys.txt
│ └── rec.onnx
├── pipeline
│ ├── my_pipeline_1.json
│ └── my_pipeline_2.json
└── properties.json
└── pipeline
├── my_pipeline_1.json
└── my_pipeline_2.json
```

You can modify the names of files and folders starting with "my_", but the others have fixed file names and should not be changed. Here's a breakdown:
Expand All @@ -39,7 +38,7 @@ You can refer to the [Task Pipeline Protocol](3.1-PipelineProtocol.md) for writi
Tools:

- [JSON Schema](https://github.com/MaaAssistantArknights/MaaFramework/blob/main/tools/pipeline.schema.json)
- [Graphical Editor](https://github.com/MaaAssistantArknights/MaaJsonViewer)
- [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=nekosu.maa-support)

### Image Files

Expand All @@ -57,31 +56,20 @@ You can use our pre-converted files: [MaaCommonAssets](https://github.com/MaaAss

If needed, you can also fine-tune the official pre-trained models of PaddleOCR yourself (please refer to the official PaddleOCR documentation) and convert them to ONNX files for use. You can find conversion commands [here](https://github.com/MaaAssistantArknights/MaaCommonAssets/tree/main/OCR#command).

### Directory Property File
## Run

`properties.json` can be used to set properties for the current directory. A typical JSON structure is as follows:
You can integrate MaaFramework using MaaPiCli (Generic CLI) or by writing integration code yourself.

_Please note that JSON does not support comments, and the following is for demonstration purposes only. Do not copy and use directly._
### Using MaaPiCli

```jsonc
{
"is_base": true, // Whether it is a base resource
// If true, when reading resources in this directory, all previously read content will be cleared.
}
```

## Integration

You can integrate MaaFramework using MaaY (Generic GUI) or by writing integration code yourself.

### Using MaaY
Use MaaPiCli in the `bin` folder of the Release package, and write `interface.json` and place it in the same directory to use it.

Use [MaaY](https://github.com/MaaAssistantArknights/MaaY). Refer to the corresponding documentation in MaaY to organize the `.maay` folder and directly import and use it in the GUI.
The Cli has completed basic function development, and more functions are being continuously improved! Detailed documentation needs to be further improved. Currently, you can refer to sample to write it.

Examples:

- [M9A.maay](https://github.com/MaaAssistantArknights/M9A/tree/main/assets/.maay)
- [MAS.maay](https://github.com/MaaAssistantArknights/MaaAssistantSkland/tree/main/.maay)
- [Sample](https://github.com/MaaAssistantArknights/MaaFramework/blob/main/sample/interface.json)
- [M9A](https://github.com/MaaAssistantArknights/M9A/tree/main/assets/interface.json)

### Writing Integration Code Yourself

Expand Down
36 changes: 12 additions & 24 deletions docs/zh_cn/1.1-快速开始.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. 下载 MaaFramework 发行版
2. 准备资源文件
3. 使用通用 GUI / 自行编写集成代码
3. 使用通用 CLI / 自行编写集成代码

## 下载 MaaFramework 发行版

Expand All @@ -22,10 +22,9 @@ my_resource
│ ├── det.onnx
│ ├── keys.txt
│ └── rec.onnx
├── pipeline
│ ├── my_pipeline_1.json
│ └── my_pipeline_2.json
└── properties.json
└── pipeline
├── my_pipeline_1.json
└── my_pipeline_2.json
```

其中以 `my_` 开头的文件/文件夹均可自行修改名称,其他的则为固定文件名,不可修改,下面依次介绍:
Expand All @@ -39,7 +38,7 @@ my_resource
小工具:

- [JSON Schema](https://github.com/MaaAssistantArknights/MaaFramework/blob/main/tools/pipeline.schema.json)
- [图形化编辑器](https://github.com/MaaAssistantArknights/MaaJsonViewer)
- [VSCode 插件](https://marketplace.visualstudio.com/items?itemName=nekosu.maa-support)

### 图片文件

Expand All @@ -57,31 +56,20 @@ my_resource

若有需要也可以自行对 PaddleOCR 的官方预训练模型进行 fine-tuning (请自行参考 [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) 官方文档),并转换成 ONNX 文件使用,转换命令可参考 [这里](https://github.com/MaaAssistantArknights/MaaCommonAssets/tree/main/OCR#command)

### 目录属性文件
## 运行

`properties.json` 可用于设置部分当前目录下的属性,典型 JSON 结构如下:
使用 MaaPiCli(通用 CLI)或者 自行编写集成代码

_请注意,JSON 不支持注释,以下仅为演示,请勿直接复制使用。_
### 使用 MaaPiCli

```jsonc
{
"is_base": true, // 是否是基准资源
// 若为 true,在读取本目录下的资源时,会清除之前读取的所有内容
}
```

## 集成

使用 MaaY(通用 GUI)或者 自行编写集成代码

### 使用 MaaY
使用 Release 包 bin 文件夹中的 MaaPiCli,并编写 `interface.json` 置于同目录下,即可使用

使用 [MaaY](https://github.com/MaaAssistantArknights/MaaY),参考 MaaY 中对应的文档整理 `.maay` 文件夹,并在 GUI 中直接导入使用。
该 Cli 已完成基本功能开发,更多功能不断完善中!详细文档待进一步完善,当前可参考 sample 编写

实践:

- [M9A.maay](https://github.com/MaaAssistantArknights/M9A/tree/main/assets/.maay)
- [MAS.maay](https://github.com/MaaAssistantArknights/MaaAssistantSkland/tree/main/.maay)
- [Sample](https://github.com/MaaAssistantArknights/MaaFramework/blob/main/sample/interface.json)
- [M9A](https://github.com/MaaAssistantArknights/M9A/tree/main/assets/interface.json)

### 自行编写集成代码

Expand Down
122 changes: 94 additions & 28 deletions sample/interface.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,78 @@
{
"resource": [
{
"name": "official",
"name": "Official",
"path": [
"{PROJECT_DIR}/resource/base"
]
},
{
"name": "bilibili",
"name": "Bilibili",
"path": [
"{PROJECT_DIR}/resource/base",
"{PROJECT_DIR}/resource/bilibili"
]
}
],
"entry": [
"task": [
{
"task": "StartUp"
"name": "启动游戏",
"entry": "StartUp"
},
{
"task": "Awards"
"name": "收取荒原",
"entry": "Wilderness"
},
{
"task": "Combat",
"name": "每日心相(意志解析)",
"entry": "Psychube"
},
{
"name": "常规作战",
"entry": "Combat",
"option": [
"combat_stage",
"combat_times"
"作战关卡",
"复现次数",
"刷完全部体力",
"吃全部临期糖"
]
}
],
"executor": [
},
{
"type": "Recognizer",
"exec_name": "StageDropRecognition",
"exec_path": "Python",
"exec_param": [
"{PROJECT_DIR}/exec_agent/StageDropRecognition/main.py"
]
"name": "活动:绿湖噩梦 17 艰难(活动已结束)",
"entry": "ANightmareAtGreenLake",
"option": [
"复现次数",
"刷完全部体力",
"吃全部临期糖"
],
"param": {
"EnterTheShow": {
"next": "ANightmareAtGreenLake"
},
"TargetStageName": {
"text": "17"
},
"StageDifficulty": {
"next": "ActivityStageDifficulty"
}
}
},
{
"name": "领取奖励",
"entry": "Awards"
},
{
"name": "关闭游戏",
"entry": "Close1999"
}
],
"option": [
{
"name": "combat_stage",
"case": [
"recognizer": {},
"action": {},
"option": {
"作战关卡": {
"cases": [
{
"name": "3-9",
"name": "3-9 厄险(百灵百验鸟)",
"param": {
"EnterTheShow": {
"next": "MainChapter_3"
Expand All @@ -58,7 +86,7 @@
}
},
{
"name": "4-20",
"name": "4-20 厄险(双头形骨架)",
"param": {
"EnterTheShow": {
"next": "MainChapter_4"
Expand All @@ -73,10 +101,8 @@
}
]
},
{
"name": "combat_times",
"default": "x1",
"case": [
"复现次数": {
"cases": [
{
"name": "x1",
"param": {
Expand Down Expand Up @@ -110,6 +136,46 @@
}
}
]
},
"刷完全部体力": {
"cases": [
{
"name": "Yes",
"param": {
"AllIn": {
"enabled": true
}
}
},
{
"name": "No",
"param": {
"AllIn": {
"enabled": false
}
}
}
]
},
"吃全部临期糖": {
"cases": [
{
"name": "Yes",
"param": {
"EatCandyWithin24H": {
"enabled": true
}
}
},
{
"name": "No",
"param": {
"EatCandyWithin24H": {
"enabled": false
}
}
}
]
}
]
}
}
3 changes: 2 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ if (WITH_DBG_CONTROLLER)
endif()

add_subdirectory(LibraryHolder)
add_subdirectory(ProjectInterface)
add_subdirectory(MaaFramework)
add_subdirectory(MaaToolkit)
add_subdirectory(ProjectInterface)
add_subdirectory(MaaProjectInterfaceCli)

if(WITH_GRPC)
add_subdirectory(MaaRpc)
Expand Down
18 changes: 18 additions & 0 deletions source/MaaProjectInterfaceCli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
file(GLOB_RECURSE maa_pi_cli_src *.h *.hpp *.cpp)
file(GLOB_RECURSE maa_pi_cli_header ../include/MaaPiCli/*)

add_executable(MaaPiCli ${maa_pi_cli_src} ${maa_pi_cli_header})

target_include_directories(MaaPiCli
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include ${CMAKE_CURRENT_SOURCE_DIR}/../../include)

target_link_libraries(MaaPiCli ProjectInterface MaaUtils MaaFramework MaaToolkit HeaderOnlyLibraries Boost::system)

add_dependencies(MaaPiCli ProjectInterface MaaUtils MaaFramework MaaToolkit)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_pi_cli_src})

install(TARGETS MaaPiCli
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
)
Loading
Loading