diff --git a/package-lock.json b/package-lock.json index 7a090ca..9aa128e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "fast-xml-parser": "^4.3.5", "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", + "is": "^3.3.0", "jsonc-parser": "^3.3.1", "jszip": "^3.10.1", "module-alias": "2.2.3", @@ -20,6 +21,7 @@ }, "devDependencies": { "@types/fs-extra": "^11.0.4", + "@types/is": "^0.0.25", "@types/mocha": "^10.0.3", "@types/module-alias": "^2.0.4", "@types/node": "^18.19.18", @@ -28,6 +30,7 @@ "@types/winreg": "^1.2.34", "@typescript-eslint/eslint-plugin": "^6.9.0", "@typescript-eslint/parser": "^6.9.0", + "@vscode/dts": "^0.4.1", "@vscode/test-electron": "^2.3.6", "dts-bundle-generator": "^9.5.1", "eslint": "^8.57.0", @@ -321,6 +324,13 @@ "@types/node": "*" } }, + "node_modules/@types/is": { + "version": "0.0.25", + "resolved": "https://registry.npmjs.org/@types/is/-/is-0.0.25.tgz", + "integrity": "sha512-1tBuxKlnPVPNCWPXbPQvFs5dTn4G6SuesBjlGiMHLfOPWDoH4wO/17QNl5/tTqA2GSMo/aC0LH06SVBqAIvFiw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/json-schema": { "version": "7.0.14", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.14.tgz", @@ -577,6 +587,45 @@ "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", "dev": true }, + "node_modules/@vscode/dts": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@vscode/dts/-/dts-0.4.1.tgz", + "integrity": "sha512-o8cI5Vqt6S6Y5mCI7yCkSQdiLQaLG5DMUpciJV3zReZwE+dA5KERxSVX8H3cPEhyKw21XwKGmIrg6YmN6M5uZA==", + "dev": true, + "license": "MIT", + "dependencies": { + "https-proxy-agent": "^7.0.0", + "minimist": "^1.2.8", + "prompts": "^2.4.2" + }, + "bin": { + "dts": "index.js" + } + }, + "node_modules/@vscode/dts/node_modules/agent-base": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", + "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/@vscode/dts/node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/@vscode/test-electron": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.9.tgz", @@ -2520,6 +2569,15 @@ "node": ">=10.13.0" } }, + "node_modules/is": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", + "integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -2788,6 +2846,16 @@ "node": ">=0.10.0" } }, + "node_modules/kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/lazystream": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz", @@ -3430,6 +3498,20 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, + "node_modules/prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -3782,6 +3864,13 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true, + "license": "MIT" + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", diff --git a/package.json b/package.json index 3ffb83f..92aa01e 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, { "command": "y3-helper.openPlugin", - "when": "viewItem == 插件", + "when": "viewItem == 插件列表", "group": "navigation" }, { @@ -342,7 +342,7 @@ { "command": "y3-helper.openPlugin", "title": "打开插件", - "enablement": "viewItem == 插件", + "enablement": "viewItem == 插件列表", "category": "Y3开发助手" }, { @@ -432,6 +432,7 @@ "fast-xml-parser": "^4.3.5", "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", + "is": "^3.3.0", "jsonc-parser": "^3.3.1", "jszip": "^3.10.1", "module-alias": "2.2.3", @@ -440,6 +441,7 @@ }, "devDependencies": { "@types/fs-extra": "^11.0.4", + "@types/is": "^0.0.25", "@types/mocha": "^10.0.3", "@types/module-alias": "^2.0.4", "@types/node": "^18.19.18", @@ -448,6 +450,7 @@ "@types/winreg": "^1.2.34", "@typescript-eslint/eslint-plugin": "^6.9.0", "@typescript-eslint/parser": "^6.9.0", + "@vscode/dts": "^0.4.1", "@vscode/test-electron": "^2.3.6", "dts-bundle-generator": "^9.5.1", "eslint": "^8.57.0", diff --git a/src/mainMenu/mainMenu.ts b/src/mainMenu/mainMenu.ts index 6305025..d255245 100644 --- a/src/mainMenu/mainMenu.ts +++ b/src/mainMenu/mainMenu.ts @@ -8,7 +8,7 @@ import { 玩家属性 } from './pages/playerAttrs'; import { 自定义事件 } from './pages/events'; import { 界面 } from './pages/ui'; import { 时间轴动画 } from './pages/uiAnim'; -import { 插件 } from './pages/plugin'; +import { 插件列表 } from './pages/plugin'; import { 地图管理 } from './pages/mapManager'; import { 跳字 } from './pages/jumpword'; import { 字体 } from './pages/font'; @@ -17,6 +17,7 @@ let mainNode = new TreeNode('主菜单', { childs: [ new 功能, new 地图管理, + new 插件列表, new 界面, new TreeNode('枚举', { iconPath: new vscode.ThemeIcon('list-tree'),show: async () => { @@ -32,7 +33,6 @@ let mainNode = new TreeNode('主菜单', { new 字体, ] }), - new 插件, new 环境, new TreeNode('重新选择Y3地图路径', { command: { diff --git a/src/mainMenu/pages/environments.ts b/src/mainMenu/pages/environments.ts index 0b38075..68ec87a 100644 --- a/src/mainMenu/pages/environments.ts +++ b/src/mainMenu/pages/environments.ts @@ -2,6 +2,7 @@ import { env } from "../../env"; import { TreeNode, ViewInExplorerNode, ViewInNewVSCode, ViewInVSCode } from "../treeNode"; import * as vscode from 'vscode'; import * as y3 from 'y3-helper'; +import { 插件管理 } from './plugin'; export class 环境 extends TreeNode { constructor() { @@ -12,6 +13,7 @@ export class 环境 extends TreeNode { return env.scriptUri !== undefined; }, childs: [ + new 插件管理, new TreeNode('编辑器', { update: async (node) => { await env.editorReady(true); diff --git a/src/mainMenu/pages/plugin.ts b/src/mainMenu/pages/plugin.ts index 63aea6f..4ecf733 100644 --- a/src/mainMenu/pages/plugin.ts +++ b/src/mainMenu/pages/plugin.ts @@ -1,11 +1,9 @@ import { TreeNode } from "../treeNode"; import * as vscode from 'vscode'; import * as y3 from 'y3-helper'; -import * as path from 'path'; -export class 插件 extends TreeNode { +export class 插件管理 extends TreeNode { constructor() { - let event: vscode.Disposable | undefined; super('插件', { iconPath: new vscode.ThemeIcon('extensions'), show: async () => { @@ -35,7 +33,25 @@ export class 插件 extends TreeNode { }, }), ]; + }, + }); + } +} +export class 插件列表 extends TreeNode { + constructor() { + let event: vscode.Disposable | undefined; + super('插件', { + iconPath: new vscode.ThemeIcon('extensions'), + show: async () => { + let pluginManager = y3.plugin.getManager(); + if (!pluginManager) { + return false; + } + let plugins = await pluginManager.getAll(); + return plugins.length > 0; + }, + update: async (node) => { let pluginManager = y3.plugin.getManager(); if (!pluginManager) { return; @@ -44,6 +60,7 @@ export class 插件 extends TreeNode { event?.dispose(); event = pluginManager.onDidChange(() => { node.refresh(); + node.parent?.refresh(); }); let plugins = await pluginManager.getAll(); @@ -51,36 +68,43 @@ export class 插件 extends TreeNode { return; } - node.childs.push(new TreeNode('插件列表', { - iconPath: new vscode.ThemeIcon('list-unordered'), - update: async (node) => { - node.childs = plugins.map(plugin => new TreeNode(plugin.name, { - iconPath: new vscode.ThemeIcon('bracket-dot'), - contextValue: '插件', - data: plugin.uri, - update: async (node) => { - let exports = await plugin.getExports(); - node.childs = Object.values(exports).map(exp => new TreeNode(exp.name, { - iconPath: new vscode.ThemeIcon('run'), - description: exp.name === 'onGame' ? '启动游戏时运行' - : exp.name === 'onSave' ? '保存地图时运行' - : exp.name === 'onEditor' ? '用编辑器打开时运行' - : '点击运行', - command: { - command: 'y3-helper.runPlugin', - title: exp.name, - arguments: [plugin.uri, exp.name], - }, - })); + node.childs = []; + let autos = []; + + for (const plugin of plugins) { + let exports = await plugin.getExports(); + for (const exp of Object.values(exports)) { + let child = new TreeNode(`${exp.name}`, { + iconPath: new vscode.ThemeIcon('run'), + description: `${plugin.name}`, + command: { + command: 'y3-helper.runPlugin', + title: exp.name, + arguments: [plugin.uri, exp.name], }, - })); - }, - })); + contextValue: '插件列表', + data: { + uri: plugin.uri, + line: exp.line, + } + }); + if (exp.name === 'onGame' || exp.name === 'onSave' || exp.name === 'onEditor') { + autos.push(child); + } else { + node.childs.push(child); + } + } + } + + if (autos.length > 0) { + node.childs.push(new TreeNode('------- 以下会自动运行 -------')); + node.childs.push(...autos); + } }, }); } } vscode.commands.registerCommand('y3-helper.openPlugin', async (node: TreeNode) => { - y3.open(node.data); + y3.open(node.data.uri, node.data.line); }); diff --git a/src/y3-helper.ts b/src/y3-helper.ts index 3c8f43a..04240f0 100644 --- a/src/y3-helper.ts +++ b/src/y3-helper.ts @@ -10,6 +10,8 @@ export { env } from './env'; export * as plugin from './plugin'; export * as exceljs from 'exceljs'; export let helper: vscode.ExtensionContext; +import is from 'is'; +export { is }; /** * 拼接路径为 Uri @@ -51,11 +53,13 @@ export function print(...args: any[]) { * 在VSCode中打开文件 * @param uri 文件路径 */ -export function open(uri: vscode.Uri | string) { +export function open(uri: vscode.Uri | string, line?: number) { if (typeof uri === 'string') { uri = vscode.Uri.parse(uri); } - vscode.commands.executeCommand('vscode.open', uri); + vscode.window.showTextDocument(uri, { + selection: line ? new vscode.Range(line, 0, line, 0) : undefined, + }); } /**