Skip to content

Commit

Permalink
refactor: adapt to MaaFramework 2.0 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin authored Sep 22, 2024
2 parents d721716 + 888860e commit 4d30b20
Show file tree
Hide file tree
Showing 41 changed files with 1,750 additions and 299 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/release.yml

This file was deleted.

20 changes: 19 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ name: test

on:
push:
tags:
- "v*"
branches:
- "**"

pull_request:
branches:
- "**"

workflow_dispatch:

jobs:
meta:
uses: ./.github/workflows/meta.yml

windows:
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -173,4 +180,15 @@ jobs:
if: always()
with:
name: MAA-macos-${{ matrix.arch }}-full_log
path: "test/debug"
path: "test/debug"

release:
if: ${{ needs.meta.outputs.is_release == 'true' }}
needs: [meta, windows, ubuntu, macos]
runs-on: ubuntu-latest

steps:
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.meta.outputs.tag }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.idea
/test/debug
/test/debug
/test/config
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<a href="https://pkg.go.dev/github.com/MaaXYZ/maa-framework-go">
<img alt="go reference" src="https://pkg.go.dev/badge/github.com/MaaXYZ/maa-framework-go">
</a>
<a href="https://github.com/MaaXYZ/MaaFramework/releases/tag/v2.0.0-beta.1">
<img alt="maa framework" src="https://img.shields.io/badge/MaaFramework-v2.0.0--beta.1-blue">
<a href="https://github.com/MaaXYZ/MaaFramework/releases/tag/v2.0.0">
<img alt="maa framework" src="https://img.shields.io/badge/MaaFramework-v2.0.0-blue">
</a>
</p>

Expand Down Expand Up @@ -97,7 +97,7 @@ Replace `[path to maafw include directory]` with the actual path to the MaaFrame
## Examples

- [Quirk Start](#quirk-start)
- [Custom Recognizer](#custom-recognizer)
- [Custom Recognition](#custom-recognition)
- [Custom Action](#custom-action)
- [PI CLI](#pi-cli)

Expand Down Expand Up @@ -140,7 +140,7 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}
Expand All @@ -151,11 +151,11 @@ func main() {

```

### Custom Recognizer
### Custom Recognition

See [custom-recognizer](examples/custom-recognizer) for details.
See [custom-recognition](examples/custom-recognition) for details.

Here is a basic example to implement your custom recognizer:
Here is a basic example to implement your custom recognition:

```go
package main
Expand Down Expand Up @@ -190,20 +190,20 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}

res.RegisterCustomRecognizer("MyRec", &MyRec{})
res.RegisterCustomRecognition("MyRec", &MyRec{})

detail := tasker.PostPipeline("Startup").Wait().GetDetail()
fmt.Println(detail)
}

type MyRec struct{}

func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognizerArg) (maa.CustomRecognizerResult, bool) {
func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognitionArg) (maa.CustomRecognitionResult, bool) {
ctx.RunRecognition("MyCustomOCR", arg.Img, maa.J{
"MyCustomOCR": maa.J{
"roi": []int{100, 100, 200, 300},
Expand All @@ -229,7 +229,7 @@ func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognizerArg) (maa.CustomR

ctx.OverrideNext(arg.CurrentTaskName, []string{"TaskA", "TaskB"})

return maa.CustomRecognizerResult{
return maa.CustomRecognitionResult{
Box: maa.Rect{0, 0, 100, 100},
Detail: "Hello World!",
}, true
Expand Down Expand Up @@ -276,7 +276,7 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}
Expand All @@ -289,7 +289,7 @@ func main() {

type MyAct struct{}

func (a *MyAct) Run(_ *maa.Context, arg *maa.CustomActionArg) bool {
func (a *MyAct) Run(_ *maa.Context, _ *maa.CustomActionArg) bool {
return true
}

Expand Down
20 changes: 10 additions & 10 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<a href="https://pkg.go.dev/github.com/MaaXYZ/maa-framework-go">
<img alt="go reference" src="https://pkg.go.dev/badge/github.com/MaaXYZ/maa-framework-go">
</a>
<a href="https://github.com/MaaXYZ/MaaFramework/releases/tag/v2.0.0-beta.1">
<img alt="maa framework" src="https://img.shields.io/badge/MaaFramework-v2.0.0--beta.1-blue">
<a href="https://github.com/MaaXYZ/MaaFramework/releases/tag/v2.0.0">
<img alt="maa framework" src="https://img.shields.io/badge/MaaFramework-v2.0.0-blue">
</a>
</p>

Expand Down Expand Up @@ -139,7 +139,7 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}
Expand All @@ -152,7 +152,7 @@ func main() {

### 自定义识别器

有关详细信息,请参阅 [custom-recognizer](examples/custom-recognizer)
有关详细信息,请参阅 [custom-recognition](examples/custom-recognition)

以下是一个实现自定义识别器的基本示例:

Expand Down Expand Up @@ -189,20 +189,20 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}

res.RegisterCustomRecognizer("MyRec", &MyRec{})
res.RegisterCustomRecognition("MyRec", &MyRec{})

detail := tasker.PostPipeline("Startup").Wait().GetDetail()
fmt.Println(detail)
}

type MyRec struct{}

func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognizerArg) (maa.CustomRecognizerResult, bool) {
func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognitionArg) (maa.CustomRecognitionResult, bool) {
ctx.RunRecognition("MyCustomOCR", arg.Img, maa.J{
"MyCustomOCR": maa.J{
"roi": []int{100, 100, 200, 300},
Expand All @@ -228,7 +228,7 @@ func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognizerArg) (maa.CustomR

ctx.OverrideNext(arg.CurrentTaskName, []string{"TaskA", "TaskB"})

return maa.CustomRecognizerResult{
return maa.CustomRecognitionResult{
Box: maa.Rect{0, 0, 100, 100},
Detail: "Hello World!",
}, true
Expand Down Expand Up @@ -275,7 +275,7 @@ func main() {
defer res.Destroy()
res.PostPath("./resource").Wait()
tasker.BindResource(res)
if tasker.Inited() {
if tasker.Initialized() {
fmt.Println("Failed to init MAA.")
os.Exit(1)
}
Expand All @@ -288,7 +288,7 @@ func main() {

type MyAct struct{}

func (a *MyAct) Run(_ *maa.Context, arg *maa.CustomActionArg) bool {
func (a *MyAct) Run(_ *maa.Context, _ *maa.CustomActionArg) bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (ctx *Context) runRecognition(entry, override string, img image.Image) *Rec
cOverride := C.CString(override)
defer C.free(unsafe.Pointer(cOverride))
imgBuf := buffer.NewImageBuffer()
imgBuf.SetRawData(img)
imgBuf.Set(img)
defer imgBuf.Destroy()

recId := int64(C.MaaContextRunRecognition(ctx.handle, cEntry, cOverride, (*C.MaaImageBuffer)(imgBuf.Handle())))
Expand Down
Loading

0 comments on commit 4d30b20

Please sign in to comment.