29 lines
1.6 KiB
TypeScript
29 lines
1.6 KiB
TypeScript
import type {NodeHandler} from '../../../types/bot/workflow/runtime.ts';
|
|
import type {WorkflowNodeTemplate} from '../../../types/bot/workflow/metadata.ts';
|
|
import {describe, failure_port, output, success_port} from '../metadata.ts';
|
|
|
|
export const config_template: WorkflowNodeTemplate = {
|
|
name: 'sleep', version: '1.0.0',
|
|
i18n: describe('等待', '按毫秒或游戏刻等待指定时长,再继续执行。'),
|
|
config: [
|
|
{name: 'mode', type: 'select', required: true, default: 'milliseconds',
|
|
i18n: describe('计时方式', '选择等待时长的单位。'),
|
|
options: [
|
|
{value: 'milliseconds', i18n: describe('毫秒', '按毫秒等待,1000 毫秒为 1 秒。')},
|
|
{value: 'ticks', i18n: describe('游戏刻', '按游戏刻等待,实际时长取决于游戏刻推进速度。')},
|
|
]},
|
|
{name: 'value', type: 'number', required: true, default: 1000, integer: true, min: 0, max: 2_147_483_647,
|
|
i18n: describe('等待时长', '使用所选单位的非负整数时长,0 表示不增加等待时长。')},
|
|
],
|
|
output: output('null', '等待结果', '等待完成后输出 null。'),
|
|
ports: [success_port, failure_port],
|
|
};
|
|
|
|
export const execute: NodeHandler = async (node, _state, signal, deps) => {
|
|
if (node.type !== 'sleep') throw new Error('Expected a sleep node');
|
|
signal.throwIfAborted();
|
|
await deps.sleep(node.config.mode, node.config.value, signal);
|
|
signal.throwIfAborted();
|
|
return {port: 'success', result: {status: 'success', output: null}};
|
|
};
|