Skip to content

Commit

Permalink
修改插件的排版
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 12, 2024
1 parent 7e06556 commit f0c6ce7
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 34 deletions.
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
{
"command": "y3-helper.openPlugin",
"when": "viewItem == 插件",
"when": "viewItem == 插件列表",
"group": "navigation"
},
{
Expand Down Expand Up @@ -342,7 +342,7 @@
{
"command": "y3-helper.openPlugin",
"title": "打开插件",
"enablement": "viewItem == 插件",
"enablement": "viewItem == 插件列表",
"category": "Y3开发助手"
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/mainMenu/mainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,6 +17,7 @@ let mainNode = new TreeNode('主菜单', {
childs: [
new 功能,
new 地图管理,
new 插件列表,
new 界面,
new TreeNode('枚举', {
iconPath: new vscode.ThemeIcon('list-tree'),show: async () => {
Expand All @@ -32,7 +33,6 @@ let mainNode = new TreeNode('主菜单', {
new 字体,
]
}),
new 插件,
new 环境,
new TreeNode('重新选择Y3地图路径', {
command: {
Expand Down
2 changes: 2 additions & 0 deletions src/mainMenu/pages/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -12,6 +13,7 @@ export class 环境 extends TreeNode {
return env.scriptUri !== undefined;
},
childs: [
new 插件管理,
new TreeNode('编辑器', {
update: async (node) => {
await env.editorReady(true);
Expand Down
80 changes: 52 additions & 28 deletions src/mainMenu/pages/plugin.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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;
Expand All @@ -44,43 +60,51 @@ export class 插件 extends TreeNode {
event?.dispose();
event = pluginManager.onDidChange(() => {
node.refresh();
node.parent?.refresh();
});

let plugins = await pluginManager.getAll();
if (plugins.length === 0) {
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);
});
8 changes: 6 additions & 2 deletions src/y3-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
}

/**
Expand Down

0 comments on commit f0c6ce7

Please sign in to comment.