Skip to content

Commit

Permalink
暂存一下
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Nov 20, 2024
1 parent 9db690a commit ad19406
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@
"command": "y3-helper.enableGlobalScript",
"title": "启用全局脚本",
"category": "Y3开发助手"
},
{
"command": "y3-helper.compileECA",
"title": "编译ECA",
"category": "Y3开发助手"
}
],
"configuration": {
Expand Down
51 changes: 51 additions & 0 deletions src/ecaCompiler/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
import * as compiler from './compiler';
import * as vscode from 'vscode';
import * as y3 from 'y3-helper';

async function fullCompileOne(inUri: vscode.Uri, outUri: vscode.Uri) {
let c = new compiler.Compiler();
let eca = await c.compile(inUri);
let content = eca.make();
await y3.fs.writeFile(outUri, content);
}

export function init() {
vscode.commands.registerCommand('y3-helper.compileECA', async () => {
if (!y3.env.scriptUri) {
vscode.window.showErrorMessage('请先打开地图');
return;
}
let outTriggerDir = y3.uri(y3.env.scriptUri, 'y3-trigger');
await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: '编译中...',
cancellable: true,
}, async (progress, token) => {
progress.report({
message: '正在搜索触发器文件...',
});
let inTriggerDir = y3.uri(y3.env.mapUri!, 'global_trigger/trigger');
let scanResult = await y3.fs.scan(inTriggerDir, undefined, () => {
if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}
});
let fileNames = scanResult
. filter((file) => file[1] === vscode.FileType.File && file[0].endsWith('.json'))
. map((file) => file[0]);

if (fileNames.length === 0) {
return;
}
for (let i = 0; i < fileNames.length; i++) {
if (token.isCancellationRequested) {
throw new vscode.CancellationError();
}
progress.report({
message: `正在编译触发器文件(${i}/${fileNames.length})...`,
});
await fullCompileOne(y3.uri(inTriggerDir, fileNames[i]), y3.uri(outTriggerDir, fileNames[i].replace('.json', '.lua')));
}
});
vscode.window.showInformationMessage('编译完成');
});
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as y3 from 'y3-helper';
import { config } from './config';
import * as globalScript from './globalScript';
import * as luaLanguage from './luaLanguage';
import * as ecaCompiler from './ecaCompiler';

class Helper {
private context: vscode.ExtensionContext;
Expand Down Expand Up @@ -305,6 +306,7 @@ class Helper {
plugin.init();
globalScript.init();
luaLanguage.init();
ecaCompiler.init();
}, 100);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function dir(uri: vscode.Uri | string, relativePath?: string) {
}
}

export async function scan(uri: vscode.Uri | string, relativePath?: string) {
export async function scan(uri: vscode.Uri | string, relativePath?: string, partail?: (result: [string, vscode.FileType][]) => void) {
if (typeof uri === 'string') {
uri = vscode.Uri.file(uri);
}
Expand All @@ -115,6 +115,7 @@ export async function scan(uri: vscode.Uri | string, relativePath?: string) {
for (const [name, fileType] of files) {
let fullPath = path ? `${path}/${name}` : name;
result.push([fullPath, fileType]);
partail?.(result);
if (fileType === vscode.FileType.Directory) {
await doScan(uri, fullPath);
}
Expand Down

0 comments on commit ad19406

Please sign in to comment.