Skip to content

Commit

Permalink
冲突后更新资源中的ID
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 22, 2024
1 parent 75227ff commit ac4ecec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/preset/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))) {
Expand All @@ -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)));
}
Expand Down

0 comments on commit ac4ecec

Please sign in to comment.