Skip to content

Commit e4b5261

Browse files
Updated textures to be read only in game dump
1 parent d31ddfe commit e4b5261

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,8 @@ export async function activate(context: vscode.ExtensionContext) {
12181218
);
12191219
if (isBntxTextureResult(raw)) {
12201220
const texName = raw.metadata?.name ?? filePath.split('/').pop() ?? 'texture';
1221-
openTextureViewer(texName, raw, diskArchive, filePath, async (data) => {
1221+
const isReadOnly = uri.scheme === 'totk-dump' || uri.scheme === 'sarc-dump';
1222+
const onSaveCallback = isReadOnly ? undefined : async (data: any) => {
12221223
const payloadStr = JSON.stringify(data);
12231224
const updateArgs = isTxtgFile(uri.fsPath)
12241225
? ['update-txtg-metadata', diskArchive, filePath, payloadStr]
@@ -1236,7 +1237,8 @@ export async function activate(context: vscode.ExtensionContext) {
12361237

12371238
// Automatically refresh the texture viewer to show the applied changes
12381239
void vscode.commands.executeCommand('totk-editor.openBntxTexture', uri);
1239-
});
1240+
};
1241+
openTextureViewer(texName, raw, diskArchive, filePath, onSaveCallback);
12401242
} else {
12411243
void vscode.window.showErrorMessage('Failed to load texture preview.');
12421244
}

src/textureViewer.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function openTextureViewer(
3838
}
3939

4040
existing.reveal();
41-
existing.webview.html = buildHtml(result, existing.webview);
41+
existing.webview.html = buildHtml(result, existing.webview, !onSave);
4242
return;
4343
}
4444

@@ -60,7 +60,7 @@ export function openTextureViewer(
6060
{ enableScripts: true, retainContextWhenHidden: false, localResourceRoots: localRoots },
6161
);
6262

63-
panel.webview.html = buildHtml(result, panel.webview);
63+
panel.webview.html = buildHtml(result, panel.webview, !onSave);
6464
panels.set(key, panel);
6565
panel.onDidDispose(() => {
6666
panels.delete(key);
@@ -86,7 +86,7 @@ export function openTextureViewer(
8686
});
8787
}
8888

89-
function buildHtml(result: BntxTextureResult, webview: vscode.Webview): string {
89+
function buildHtml(result: BntxTextureResult, webview: vscode.Webview, isReadOnly: boolean): string {
9090
const meta = result.metadata;
9191
let imgSrc = '';
9292
if (result.pngPath) {
@@ -107,13 +107,13 @@ function buildHtml(result: BntxTextureResult, webview: vscode.Webview): string {
107107
const scaledH = Math.round(texH * scale);
108108

109109
const channelsSection = meta?.channels
110-
? buildSection('Channels', buildChannelRows(meta.channels))
110+
? buildSection('Channels', buildChannelRows(meta.channels, isReadOnly))
111111
: '';
112112
const imageInfoSection = meta?.imageInfo
113-
? buildSection('Image Info', buildImageInfoRows(meta.imageInfo))
113+
? buildSection('Image Info', buildImageInfoRows(meta.imageInfo, isReadOnly))
114114
: '';
115115
const miscSection = meta?.misc
116-
? buildSection('Misc', buildMiscRows(meta.misc))
116+
? buildSection('Misc', buildMiscRows(meta.misc, isReadOnly))
117117
: '';
118118
const metaSections = meta
119119
? `${channelsSection}${imageInfoSection}${miscSection}`
@@ -362,9 +362,9 @@ function buildHtml(result: BntxTextureResult, webview: vscode.Webview): string {
362362
: '<div class="no-image">No preview</div>'}
363363
</div>
364364
<div class="props-panel">
365-
<div style="margin-bottom: 12px; display: flex; justify-content: flex-end;">
365+
${!isReadOnly ? `<div style="margin-bottom: 12px; display: flex; justify-content: flex-end;">
366366
<button class="save-btn" onclick="saveMetadata()">Save Changes</button>
367-
</div>
367+
</div>` : ''}
368368
${metaSections}
369369
${errorNote}
370370
</div>
@@ -435,9 +435,12 @@ function buildSection(title: string, rows: string): string {
435435
</div>`;
436436
}
437437

438-
function buildChannelRows(ch: BntxChannelInfo): string {
438+
function buildChannelRows(ch: BntxChannelInfo, isReadOnly: boolean): string {
439439
const opts = ['Red', 'Green', 'Blue', 'Alpha', 'Zero', 'One'];
440440
const select = (id: string, current: string) => {
441+
if (isReadOnly) {
442+
return escapeHtml(current);
443+
}
441444
const options = opts.map(o => `<option value="${o}" ${current === o ? 'selected' : ''}>${o}</option>`).join('');
442445
return `<select id="${id}" class="meta-input">${options}</select>`;
443446
};
@@ -449,25 +452,25 @@ function buildChannelRows(ch: BntxChannelInfo): string {
449452
].join('');
450453
}
451454

452-
function buildImageInfoRows(info: BntxImageInfo): string {
455+
function buildImageInfoRows(info: BntxImageInfo, isReadOnly: boolean): string {
453456
const srgbChecked = info.useSRGB === 'True' ? 'checked' : '';
454457

455458
return [
456459
row('Width', String(info.width)),
457460
row('Height', String(info.height)),
458461
row('Mip Count', String(info.mipCount)),
459462
row('Format', info.format),
460-
row('Use SRGB', `<input type="checkbox" id="useSRGB" ${srgbChecked} />`),
461-
row('Name', `<input type="text" id="metaName" class="meta-input" value="${escapeHtml(info.name)}" />`),
462-
row('Path', `<input type="text" id="metaPath" class="meta-input" value="${escapeHtml(info.path ?? '')}" />`),
463+
row('Use SRGB', isReadOnly ? (info.useSRGB === 'True' ? 'Yes' : 'No') : `<input type="checkbox" id="useSRGB" ${srgbChecked} />`),
464+
row('Name', isReadOnly ? escapeHtml(info.name) : `<input type="text" id="metaName" class="meta-input" value="${escapeHtml(info.name)}" />`),
465+
row('Path', isReadOnly ? escapeHtml(info.path ?? '') : `<input type="text" id="metaPath" class="meta-input" value="${escapeHtml(info.path ?? '')}" />`),
463466
].join('');
464467
}
465468

466-
function buildMiscRows(misc: BntxMiscInfo): string {
469+
function buildMiscRows(misc: BntxMiscInfo, isReadOnly: boolean): string {
467470
return [
468471
row('Depth', String(misc.depth)),
469472
row('Tile Mode', misc.tileMode),
470-
row('Swizzle', `<input type="number" id="metaSwizzle" class="meta-input" value="${misc.swizzle}" />`),
473+
row('Swizzle', isReadOnly ? String(misc.swizzle) : `<input type="number" id="metaSwizzle" class="meta-input" value="${misc.swizzle}" />`),
471474
row('Alignment', String(misc.alignment)),
472475
row('Pitch', String(misc.pitch)),
473476
row('Dims', misc.dims),

0 commit comments

Comments
 (0)