Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: introduce MaaJSLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 9, 2023
1 parent abca87a commit 7c9f57a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ coverage
*.sln
*.sw?

library
saves
out
*.zip
*.zip
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "server/MaaJSLoader"]
path = server/MaaJSLoader
url = https://github.com/neko-para/MaaJSLoader
1 change: 1 addition & 0 deletions server/MaaJSLoader
Submodule MaaJSLoader added at 664366
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "maa-json-viewer-server",
"scripts": {
"build": "esbuild --bundle src/index.ts --outfile=dist/index.js --sourcemap --platform=node",
"build": "esbuild --bundle src/index.ts --outfile=dist/index.js --sourcemap --platform=node --loader:.node=copy",
"run": "npm run build && node dist/index.js"
},
"devDependencies": {
Expand Down
52 changes: 52 additions & 0 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import fs from 'fs/promises'
import multer, { memoryStorage } from 'multer'
import path from 'path'

import {
MaaController,
MaaFrameworkLoader,
MaaInstance,
MaaResource
} from '../MaaJSLoader'
import { MaaAdbControllerTypeEnum } from '../MaaJSLoader/src/framework/types'

async function main() {
const config = JSON.parse(await fs.readFile('config.json', 'utf-8')) as {
port: number
Expand Down Expand Up @@ -54,4 +62,48 @@ async function main() {
})
}

async function testLoader() {
const loader = new MaaFrameworkLoader()
loader.load('./library/maaframework/bin')

loader.setLogging('./debug')

const res = new MaaResource(loader)
console.log(
'resource load:',
await res.load('./library/maaframework/share/resource')
)

const ctrl = new MaaController(
loader,
'adb.exe',
'127.0.0.1:16384',
MaaAdbControllerTypeEnum.Input_Preset_Adb |
MaaAdbControllerTypeEnum.Screencap_RawWithGzip,
await fs.readFile(
'./library/maaframework/share/controller_config.json',
'utf-8'
),
(msg, detail) => {
console.log(msg, detail)
}
)
console.log('controller connect:', await ctrl.connect())
await ctrl.screencap()
const buf = ctrl.image()
if (buf) {
await fs.writeFile('test.png', buf)
}

const inst = new MaaInstance(loader, (msg, detail) => {
console.log(msg, detail)
})

inst.bindResource(res)
inst.bindController(ctrl)

console.log('instance inited:', inst.inited())
}

testLoader()
main()

0 comments on commit 7c9f57a

Please sign in to comment.