From ac4ecec5f8423db1e4e532fd031e4e5af45fd3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 22 Mar 2024 19:15:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B2=E7=AA=81=E5=90=8E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=AD=E7=9A=84ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/preset/ui.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/preset/ui.ts b/src/preset/ui.ts index 39dfd09..ac5f786 100644 --- a/src/preset/ui.ts +++ b/src/preset/ui.ts @@ -207,6 +207,10 @@ export class UI { let icon = textureInfo.icon; if (icon !== undefined) { let iconUri = vscode.Uri.joinPath(this.env.projectUri!, 'editor_table/editoricon', textureInfo.newName.toString() + '.json'); + // 全词匹配数字,如果数字 === oldName,替换为newName + if (textureInfo.oldName !== textureInfo.newName) { + icon = icon.replace(new RegExp(`(?<=\\D)${textureInfo.oldName}(?=\\D)`, 'g'), textureInfo.newName.toString()); + } pushTask(vscode.workspace.fs.writeFile(iconUri, Buffer.from(icon))); } let texture = textureInfo.texture; @@ -216,6 +220,14 @@ export class UI { } } + // 收集oldName和newName的对应关系 + let nameMap: { [key: number]: number } = {}; + for (let textureInfo of textureInfos) { + if (textureInfo.oldName !== textureInfo.newName) { + nameMap[textureInfo.oldName] = textureInfo.newName; + } + } + // 导入UI定义 let basePath = 'maps/EntryMap/ui/'; for (let file of this.zip!.filter(path => path.startsWith(basePath))) { @@ -226,6 +238,9 @@ export class UI { if (fileContent === undefined) { continue; } + // 全词匹配数字,将oldName替换为newName + fileContent = fileContent.replace(/\b\d+\b/g, (match) => nameMap[parseInt(match)]?.toString() ?? match); + let uri = vscode.Uri.joinPath(this.env.mapUri!, 'ui', file.name.slice(basePath.length)); pushTask(vscode.workspace.fs.writeFile(uri, Buffer.from(fileContent))); }