forked from MaaAssistantArknights/MaaAssistantArknights
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 支持woolang绑定 (MaaAssistantArknights#6142)
- Loading branch information
Showing
6 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
/pkg | ||
/.vs | ||
/build | ||
/woolang | ||
/debug_* | ||
/release_* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
||
运行示例项目。 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |