Skip to content

Commit

Permalink
更新插件
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 12, 2024
1 parent bc3fc29 commit fa627e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,30 @@ async function initPlugin() {
}
}

function initPluginManager() {
if (y3.env.scriptUri) {
pluginManager = new plugin.PluginManager(y3.uri(y3.env.scriptUri, scriptDir));
pluginManager.onDidChange(() => {
runButtonProvider.notifyChange();
});
function updatePluginManager() {
pluginManager?.dispose();
if (!y3.env.scriptUri) {
return;
}
y3.env.onDidChange(() => {
pluginManager?.dispose();
if (y3.env.scriptUri) {
pluginManager = new plugin.PluginManager(y3.uri(y3.env.scriptUri, scriptDir));
pluginManager.onDidChange(() => {
runButtonProvider.notifyChange();
});
}
pluginManager = new plugin.PluginManager(y3.uri(y3.env.scriptUri, scriptDir));
pluginManager.onDidChange(() => {
runButtonProvider.notifyChange();
});
}

let watcher: vscode.FileSystemWatcher | undefined;

function updateMapSaveWatcher() {
watcher?.dispose();
if (!y3.env.mapUri) {
return;
}
watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(y3.env.mapUri, '*.gmp'));
watcher.onDidCreate(() => {
runAllPlugins('onSave');
});
watcher.onDidChange(() => {
runAllPlugins('onSave');
});
}

Expand All @@ -107,7 +116,12 @@ export async function runAllPlugins(funcName: string) {
export async function init() {
await y3.env.mapReady();

initPluginManager();
updatePluginManager();
updateMapSaveWatcher();
y3.env.onDidChange(() => {
updatePluginManager();
updateMapSaveWatcher();
});

vscode.commands.registerCommand('y3-helper.initPlugin', initPlugin);

Expand Down
4 changes: 4 additions & 0 deletions template/plugin/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export async function onEditor() {

export async function onSave() {
y3.print('保存地图!')
// 在你的Lua代码里加入 `require 'log.onSave'` 试试看
y3.fs.writeFile(y3.uri(y3.env.scriptUri, 'log/onSave.lua'), `
print('保存者:${os.userInfo().username},保存时间:${new Date().toLocaleString()}')
`)
}

0 comments on commit fa627e4

Please sign in to comment.