Skip to content

Commit db4a6bb

Browse files
Added "Default Author" setting for .tkproj
1 parent 514f4f3 commit db4a6bb

4 files changed

Lines changed: 69 additions & 46 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@
842842
"default": "totk",
843843
"markdownDescription": "Active game profile ID (`totk` by default). Controls compression backend, RomFS validation, and per-game index databases. Game addons register additional profiles via `contributes.tkvsc`."
844844
},
845+
"TKVSC.defaultProjectAuthor": {
846+
"type": "string",
847+
"default": "",
848+
"markdownDescription": "Author name written to the `Author` field of newly created `.tkproj` files. Leave empty to use `Unknown`."
849+
},
845850
"TKVSC.createRomfsOnImport": {
846851
"type": "boolean",
847852
"default": true,

src/projectAdapters/tkmmAdapter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from 'path';
44
import * as vscode from 'vscode';
55
import { TKVSC_ARCHIVE_CONTEXT } from '../api/constants';
66
import { normalizePath } from '../projectPaths';
7+
import { createDefaultTkprojData } from '../tkprojDefaults';
78
import type {
89
ProjectAdapter,
910
ProjectOptionPickResult,
@@ -328,9 +329,11 @@ export class TkmmProjectAdapter implements ProjectAdapter {
328329

329330
async scaffoldNewProject(projectFolderUri: vscode.Uri): Promise<void> {
330331
await vscode.workspace.fs.createDirectory(vscode.Uri.joinPath(projectFolderUri, 'romfs'));
332+
const projectName = path.basename(normalizePath(projectFolderUri.fsPath));
333+
const defaultData = createDefaultTkprojData(projectName || undefined);
331334
await vscode.workspace.fs.writeFile(
332335
vscode.Uri.joinPath(projectFolderUri, this.projectMarkerFile!),
333-
new Uint8Array(0),
336+
Buffer.from(JSON.stringify(defaultData, null, 2), 'utf-8'),
334337
);
335338
}
336339
}

src/tkprojDefaults.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as vscode from 'vscode';
2+
3+
export interface TkprojContributor {
4+
Author: string;
5+
Contribution: string;
6+
}
7+
8+
export interface TkprojData {
9+
Mod: {
10+
Name: string;
11+
Author: string;
12+
Version: string;
13+
Description: string;
14+
Id: string;
15+
Contributors: TkprojContributor[];
16+
Dependencies: string[];
17+
Thumbnail?: { ThumbnailPath?: string };
18+
};
19+
Flags?: Record<string, unknown>;
20+
[key: string]: unknown;
21+
}
22+
23+
/** Author written into new `.tkproj` files, from `TKVSC.defaultProjectAuthor`. */
24+
export function getDefaultProjectAuthor(): string {
25+
const configured = vscode.workspace
26+
.getConfiguration('TKVSC')
27+
.get<string>('defaultProjectAuthor', '')
28+
.trim();
29+
return configured || 'Unknown';
30+
}
31+
32+
export function createDefaultTkprojData(projectName = 'New Project'): TkprojData {
33+
return {
34+
Mod: {
35+
Name: projectName,
36+
Author: getDefaultProjectAuthor(),
37+
Version: '1.0.0',
38+
Description: '',
39+
Id: generateUlidNumber(),
40+
Contributors: [],
41+
Dependencies: [],
42+
},
43+
Flags: {
44+
TrackRemovedRsDbEntries: false,
45+
},
46+
};
47+
}
48+
49+
export function generateUlidNumber(): string {
50+
let id = '';
51+
for (let i = 0; i < 26; i++) {
52+
id += Math.floor(Math.random() * 10).toString();
53+
}
54+
if (id === '00000000000000000000000001') {
55+
return generateUlidNumber();
56+
}
57+
return id;
58+
}

src/tkprojEditor.ts

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
import * as vscode from 'vscode';
2-
3-
interface TkprojContributor {
4-
Author: string;
5-
Contribution: string;
6-
}
7-
8-
interface TkprojData {
9-
Mod: {
10-
Name: string;
11-
Author: string;
12-
Version: string;
13-
Description: string;
14-
Id: string;
15-
Contributors: TkprojContributor[];
16-
Dependencies: string[];
17-
Thumbnail?: { ThumbnailPath?: string };
18-
};
19-
Flags?: Record<string, unknown>;
20-
[key: string]: unknown;
21-
}
2+
import { createDefaultTkprojData, type TkprojContributor, type TkprojData } from './tkprojDefaults';
223

234
export class TkprojEditorProvider implements vscode.CustomTextEditorProvider {
245
public static readonly viewType = 'totk-editor.tkprojEditor';
@@ -40,20 +21,7 @@ export class TkprojEditorProvider implements vscode.CustomTextEditorProvider {
4021
webviewPanel.webview.options = { enableScripts: true };
4122

4223
if (document.getText().trim() === '') {
43-
const defaultData: TkprojData = {
44-
Mod: {
45-
Name: "New Project",
46-
Author: "Unknown",
47-
Version: "1.0.0",
48-
Description: "",
49-
Id: generateUlidNumber(),
50-
Contributors: [],
51-
Dependencies: []
52-
},
53-
Flags: {
54-
TrackRemovedRsDbEntries: false
55-
}
56-
};
24+
const defaultData = createDefaultTkprojData();
5725
const edit = new vscode.WorkspaceEdit();
5826
edit.insert(document.uri, new vscode.Position(0, 0), JSON.stringify(defaultData, null, 2));
5927
await vscode.workspace.applyEdit(edit);
@@ -162,17 +130,6 @@ function escHtml(s: string): string {
162130
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
163131
}
164132

165-
function generateUlidNumber(): string {
166-
let id = '';
167-
for (let i = 0; i < 26; i++) {
168-
id += Math.floor(Math.random() * 10).toString();
169-
}
170-
if (id === '00000000000000000000000001') {
171-
return generateUlidNumber();
172-
}
173-
return id;
174-
}
175-
176133
function buildContributorRows(contributors: TkprojContributor[]): string {
177134
if (!contributors.length) {
178135
return '';

0 commit comments

Comments
 (0)