mirror of
https://gitee.com/dlmu-cone/Arborflow
synced 2026-10-23 17:52:20 +08:00
feat: launch ArborFlow behavior tree studio
This commit is contained in:
32
scripts/mock-monitor.cjs
Normal file
32
scripts/mock-monitor.cjs
Normal file
@@ -0,0 +1,32 @@
|
||||
const { WebSocketServer } = require('ws')
|
||||
|
||||
const port = Number(process.env.ARBORFLOW_MOCK_PORT || 1667)
|
||||
const server = new WebSocketServer({ port })
|
||||
const steps = [
|
||||
{ BatteryOK: 'RUNNING', NavigateToPose: 'IDLE', ReportResult: 'IDLE' },
|
||||
{ BatteryOK: 'SUCCESS', NavigateToPose: 'RUNNING', ReportResult: 'IDLE' },
|
||||
{ BatteryOK: 'SUCCESS', NavigateToPose: 'SUCCESS', ReportResult: 'RUNNING' },
|
||||
{ BatteryOK: 'SUCCESS', NavigateToPose: 'SUCCESS', ReportResult: 'SUCCESS' },
|
||||
]
|
||||
|
||||
server.on('connection', (socket) => {
|
||||
let step = 0
|
||||
const publish = () => {
|
||||
socket.send(JSON.stringify({ type: 'snapshot', timestamp: Date.now(), nodes: steps[step] }))
|
||||
step = (step + 1) % steps.length
|
||||
}
|
||||
const timer = setInterval(publish, 1200)
|
||||
publish()
|
||||
|
||||
socket.on('message', (raw) => {
|
||||
try {
|
||||
const message = JSON.parse(String(raw))
|
||||
if (message.type === 'ping') socket.send(JSON.stringify({ type: 'pong', timestamp: message.timestamp }))
|
||||
} catch {
|
||||
// Ignore non-JSON messages in the development mock.
|
||||
}
|
||||
})
|
||||
socket.on('close', () => clearInterval(timer))
|
||||
})
|
||||
|
||||
console.log(`ArborFlow mock monitor listening on ws://127.0.0.1:${port}`)
|
||||
20
scripts/render-icon.cjs
Normal file
20
scripts/render-icon.cjs
Normal file
@@ -0,0 +1,20 @@
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const fs = require('node:fs/promises')
|
||||
const path = require('node:path')
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
const svg = await fs.readFile(path.join(__dirname, '..', 'public', 'arborflow.svg'), 'utf8')
|
||||
const window = new BrowserWindow({
|
||||
width: 512,
|
||||
height: 512,
|
||||
show: false,
|
||||
transparent: true,
|
||||
frame: false,
|
||||
webPreferences: { offscreen: true },
|
||||
})
|
||||
await window.loadURL(`data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`)
|
||||
const image = await window.webContents.capturePage({ x: 0, y: 0, width: 512, height: 512 })
|
||||
await fs.writeFile(path.join(__dirname, '..', 'build', 'icon.png'), image.toPNG())
|
||||
window.destroy()
|
||||
app.quit()
|
||||
})
|
||||
Reference in New Issue
Block a user