Skip to content

Commit

Permalink
feat: 支持woolang绑定 (MaaAssistantArknights#6142)
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO authored and ABA2396 committed Sep 1, 2023
1 parent f0081e7 commit b76f859
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ MAA 以中文(简体)为第一语言,翻译词条均以中文(简体)
- [Java HTTP 接口](src/Java/Readme.md)
- [Rust 接口](src/Rust/src/maa_sys/):[HTTP 接口](src/Rust)
- [TypeScript 接口](https://github.com/MaaAssistantArknights/MaaAsstElectronUI/tree/main/packages/main/coreLoader)
- [Woolang 接口](src/Woolang/maa.wo):[集成示例](src/Woolang/main.wo)
- [集成文档](https://maa.plus/docs/3.1-集成文档.html)
- [回调消息协议](https://maa.plus/docs/3.2-回调消息协议.html)
- [任务流程协议](https://maa.plus/docs/3.4-任务流程协议.html)
Expand Down
8 changes: 8 additions & 0 deletions src/Woolang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/pkg
/.vs
/build
/woolang
/debug_*
/release_*

38 changes: 38 additions & 0 deletions src/Woolang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# MAA Woolang 接口

~~Woolang是每个窝窝头都需要使用的语言,更适合窝窝头的体质!~~

目前MAA-Woolang接口仅是对C-API的简单包装;Woolang是一门静态类型的脚本语言,关于Woolang的更多信息,请看[这里](https://github.com/cinogama/woolang)

## 运行前准备

MAA-Woolang使用了 `woffi``filesystem`,因此需要使用 baozi 安装这些依赖:

```
baozi 是 Woolang 的包管理器,可以这里获取到Chief(由BiDuang提供):
https://github.com/BiDuang/Chief_Reloaded
这将帮助你在Windows操作系统下安装baozi和Woolang运行时。
对于Linux用户,可以直接从这个仓库直接获取 baozi 的源码和二进制文件:
https://git.cinogama.net/cinogamaproject/woolangpackages/baozi
```

切换到Woolang包配置文件 `package.json` 所在路径,在命令行中输入:

```shell
baozi install
```

## 运行

由于窝窝头没有用过MAA(悲),因此没法进行测试;理论上MAA-Woolang接口的运行和C-API类似(但是我也不知道C-API是咋跑的)。假设一切顺利,应该可以通过:

```shell
woodriver demo.wo
```

运行示例项目。



101 changes: 101 additions & 0 deletions src/Woolang/demo.wo
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import maa;
import pkg::filesystem;

let ASST_DEBUG = true;

func main()
{
let cur_path = filesys::normalize(std::exepath());

if (AsstLoadResource(cur_path->tostring) == AsstTrue)
{
if (ASST_DEBUG)
{
let overseas_dir = cur_path / "resource" / "global";
for (let _, client: ["YoStarJP", "YoStarEN", "YoStarKR", "txwy"])
{
let overseas_path = overseas_dir / client;
let loaded = AsstLoadResource(cur_path->tostring);

if (AsstLoadResource(overseas_path->tostring) != AsstTrue || loaded != AsstTrue)
return result::err("Load resource failed.");
}
}

let ptr = AsstCreate();
if (ptr == nullptr: AsstHandle)
return result::err("AsstCreate() failed.");

if (ASST_DEBUG)
do AsstAsyncConnect(ptr, "adb", "127.0.0.1:5555", "DEBUG", AsstTrue);
else
do AsstAsyncConnect(ptr, "adb", "127.0.0.1:5555", "", AsstTrue);

if (AsstConnected(ptr) == AsstFalse)
{
AsstDestroy(ptr);
return result::err("Connect failed.");
}

if (ASST_DEBUG)
{
do AsstAppendTask(ptr, "Debug", "");
}
else
{
do AsstAppendTask(ptr, "StartUp", "");
do AsstAppendTask(ptr, "Fight", @"
{
"stage": "1-7"
}
"@);
do AsstAppendTask(ptr, "Recruit", @"
{
"select":[4],
"confirm":[3,4],
"times":4
}
"@);
do AsstAppendTask(ptr, "Infrast", @"
{
"facility": ["Mfg", "Trade", "Power", "Control", "Reception", "Office", "Dorm"],
"drones": "Money"
}
"@);
do AsstAppendTask(ptr, "Mall", @"
{
"shopping": true,
"buy_first": [
"许可"
],
"black_list": [
"家具",
"碳"
]
}
"@);
do AsstAppendTask(ptr, "Award", "");
do AsstAppendTask(ptr, "Roguelike", @"
{
"squad": "突击战术分队",
"roles": "先手必胜",
"core_char": "棘刺"
}
"@);
}

do AsstStart(ptr);
while (AsstRunning(ptr) == AsstTrue)
{
std::sleep(0.1);
}
do AsstStop(ptr);
do AsstDestroy(ptr);

return result::ok(do nil);
}
else
return result::err("Load resource failed.");
}

main()->unwarp();
73 changes: 73 additions & 0 deletions src/Woolang/maa.wo
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// maa.wo

import woo::std;
import pkg::woffi;

WOFFI_TYPEDEF!
{
public using AsstHandle = pointer;
public using AsstBool = uint8;
public using AsstSize = uint64;

public using AsstId = int32;
public using AsstMsgId = int32;
public using AsstTaskId = int32;
public using AsstAsyncCallId = int32;

public using AsstOptionKey = int32;
public using AsstStaticOptionKey = int32;
public using AsstInstanceOptionKey = int32;

public using AsstApiCallback = cfunction;
}

public let AsstTrue = 1: AsstBool;
public let AsstFalse = 0: AsstBool;

WOFFI_FUNCTIONS!
{
import "MaaCore.dll";

public stdcall func AsstSetUserDir(path: cstring)=> AsstBool;
public stdcall func AsstLoadResource(path: cstring)=> AsstBool;
public stdcall func AsstSetStaticOption(key: AsstStaticOptionKey, value: cstring)=> AsstBool;

public stdcall func AsstCreate()=> AsstHandle;
public stdcall func AsstCreateEx(callback: AsstApiCallback, custom_arg: pointer)=> AsstHandle;
public stdcall func AsstDestroy(handle: AsstHandle)=> void;

public stdcall func AsstSetInstanceOption(
handle: AsstHandle, key: AsstInstanceOptionKey, value: cstring)=> AsstBool;

// deprecated in 5.0
public stdcall func AsstConnect(
handle: AsstHandle, adb_path: cstring, address: cstring, config: cstring)=> AsstBool;

public stdcall func AsstAppendTask(
handle: AsstHandle, type: cstring, params: cstring)=> AsstTaskId;
public stdcall func AsstSetTaskParams(
handle: AsstHandle, id: AsstTaskId, params: cstring)=> AsstTaskId;

public stdcall func AsstStart(handle: AsstHandle)=> AsstBool;
public stdcall func AsstStop(handle: AsstHandle)=> AsstBool;
public stdcall func AsstRunning(handle: AsstHandle)=> AsstBool;
public stdcall func AsstConnected(handle: AsstHandle)=> AsstBool;

public stdcall func AsstAsyncConnect(
handle: AsstHandle,
adb_path: cstring,
address: cstring,
config: cstring,
block: AsstBool)=> AsstAsyncCallId;
public stdcall func AsstAsyncClick(handle: AsstHandle, x: int32, y: int32, block: AsstBool)=> AsstAsyncCallId;
public stdcall func AsstAsyncScreencap(handle: AsstHandle, block: AsstBool)=>AsstAsyncCallId;

public stdcall func AsstGetImage(handle: AsstHandle, buff: pointer, buff_size: AsstSize)=> AsstSize;
public stdcall func AsstGetUUID(handle: AsstHandle, buff: pointer, buff_size: AsstSize)=> AsstSize;
public stdcall func AsstGetTasksList(handle: AsstHandle, buff: pointer, buff_size: AsstSize)=> AsstSize;
public stdcall func AsstGetNullSize()=> AsstSize;

public stdcall func AsstGetVersion()=> cstring;
public stdcall func AsstLog(level: cstring, message: cstring)=> void;
}
;
23 changes: 23 additions & 0 deletions src/Woolang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"config" : [
"release_x64"
],
"dependence" : {
"filesystem" : {
"path" : "pkg",
"remote" : "https://git.cinogama.net/cinogamaproject/woolangpackages",
"version" : "1.0.0"
},
"woffi" : {
"path" : "pkg",
"remote" : "https://git.cinogama.net/cinogamaproject/woolangpackages",
"version" : "1.0.0"
}
},
"name" : "maa",
"version" : "1.0.0",
"woolang" : {
"remote" : "https://git.cinogama.net/cinogamaproject",
"version" : "1.0.0"
}
}

0 comments on commit b76f859

Please sign in to comment.