5 changed files with 155 additions and 1 deletions
@ -0,0 +1,67 @@ |
|||
import { Request } from '@ease-forge/shared' |
|||
|
|||
/** |
|||
* 运行管理器 |
|||
*/ |
|||
class RunManager { |
|||
|
|||
// 是否正在运行
|
|||
isRunning: boolean = false |
|||
|
|||
/** |
|||
* 获取所有运行环境 |
|||
*/ |
|||
async getAllEnv(worldId: string): Promise<ServerResponse<EnvInfo[]>> { |
|||
// system.invokeServer('')
|
|||
if (!worldId) { |
|||
return Promise.resolve({ success: true, data: [], msg: '' }) |
|||
} |
|||
const res = await Request.request.post('/api/workbench/EnvController@getAllEnv', { |
|||
worldId: worldId |
|||
}) |
|||
for (const env of res.data) { |
|||
// payload 转换为 json 数据
|
|||
if (env.env_payload) { |
|||
try { |
|||
env.env_payload = JSON.parse(env.env_payload) |
|||
} catch (e) { |
|||
console.error('解析环境负载失败:', e) |
|||
env.env_payload = {} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return res |
|||
} |
|||
|
|||
/** |
|||
* 创建运行环境 |
|||
* @param worldId 世界ID |
|||
* @param envName 运行环境名称 |
|||
* @param isVirtual 是否是虚拟环境 |
|||
*/ |
|||
async createEnv(worldId: string, envName: string, isVirtual: boolean) { |
|||
throw new Error('Method not implemented.') |
|||
} |
|||
|
|||
/** |
|||
* 开始运行 |
|||
*/ |
|||
async run(timeRate: number, envId: number) { |
|||
if (this.isRunning) { |
|||
await this.stop() |
|||
} |
|||
|
|||
// 启动 websocket 监听等等
|
|||
} |
|||
|
|||
/** |
|||
* 停止运行 |
|||
*/ |
|||
async stop() { |
|||
// 停止 websocket 监听等等
|
|||
} |
|||
} |
|||
|
|||
const runManager = new RunManager() |
|||
export default runManager |
|||
Loading…
Reference in new issue