From 945c3b14b80cc1093d7b3db34d4be83ecfe9f73c Mon Sep 17 00:00:00 2001
From: ghostboats <106226990+ghostboats@users.noreply.github.com>
Date: Thu, 9 May 2024 11:48:07 -0500
Subject: [PATCH] working verison generator!
---
commands/versionGenerator.js | 310 +++++++++++++++++++++++++++++++++++
extension.js | 4 +-
package.json | 6 +-
3 files changed, 318 insertions(+), 2 deletions(-)
create mode 100644 commands/versionGenerator.js
diff --git a/commands/versionGenerator.js b/commands/versionGenerator.js
new file mode 100644
index 00000000..cb756f6b
--- /dev/null
+++ b/commands/versionGenerator.js
@@ -0,0 +1,310 @@
+const vscode = require('vscode');
+const fs = require('fs');
+const path = require('path');
+const { getConfig } = require('../support_files/config');
+const { CREATE_LOGGER } = require('../support_files/log_utils.js');
+const { modName, rootModPath } = getConfig();
+const modsDirPath = path.normalize(rootModPath + "\\Mods");
+const metaPath = path.normalize(modsDirPath + "\\" + modName + "\\meta.lsx");
+const bg3mh_logger = CREATE_LOGGER();
+
+let versionGeneratorCommand = vscode.commands.registerCommand('bg3-mod-helper.versionGenerator', function () {
+ bg3mh_logger.info('‾‾versionGeneratorCommand‾‾');
+ const panel = vscode.window.createWebviewPanel(
+ 'versionGenerator',
+ 'Version Generator',
+ vscode.ViewColumn.One,
+ { enableScripts: true }
+ );
+
+ panel.webview.html = getWebviewContent();
+
+ panel.webview.onDidReceiveMessage(async (message) => {
+ if (message.command === 'copyToClipboard') {
+ vscode.env.clipboard.writeText(message.text).then(() => {
+ vscode.window.showInformationMessage('Version number copied to clipboard!');
+ });
+ } else if (message.command === 'addToMeta') {
+ await addToMeta(message.version);
+ }
+ });
+
+ bg3mh_logger.info('__versionGeneratorCommand__');
+});
+
+async function addToMeta(version) {
+ bg3mh_logger.info('Updating Version64 in meta.lsx');
+ if (!fs.existsSync(metaPath)) {
+ vscode.window.showErrorMessage(`Meta file not found at ${metaPath}`);
+ return;
+ }
+
+ try {
+ let content = fs.readFileSync(metaPath, 'utf8');
+ const regex = //g;
+ const updatedContent = content.replace(regex, ``);
+
+ if (content === updatedContent) {
+ vscode.window.showErrorMessage('Version64 attribute not found in meta.lsx');
+ } else {
+ fs.writeFileSync(metaPath, updatedContent, 'utf8');
+ vscode.window.showInformationMessage('Version64 attribute updated successfully!');
+ }
+ } catch (error) {
+ vscode.window.showErrorMessage(`Error updating meta.lsx: ${error.message}`);
+ }
+}
+
+function getWebviewContent() {
+ const nonce = getNonce();
+ return `
+
+
+
+
+
+ Version Generator
+
+
+
+ Version Generator
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `;
+}
+
+function getNonce() {
+ let text = '';
+ const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ for (let i = 0; i < 32; i++) {
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
+ }
+ return text;
+}
+
+module.exports = versionGeneratorCommand;
diff --git a/extension.js b/extension.js
index 78577cac..d4a0d747 100644
--- a/extension.js
+++ b/extension.js
@@ -19,6 +19,7 @@ const smartConvertCommand = require('./commands/smartConvert');
const { xmlToLocaCommand, locaToXmlCommand, lsxToLsfCommand, lsfToLsxCommand } = require('./commands/commands')
const openConverterCommand = require('./commands/openConverter');
+const versionGeneratorCommand = require('./commands/versionGenerator');
const AutoCompleteProvider = require('./autocomplete/autoCompleteProvider');
@@ -124,7 +125,7 @@ function activate(context) {
let createModTemplateCommand = vscode.commands.registerCommand('bg3-mod-helper.createModTemplate', createModTemplateImport);
- context.subscriptions.push(uuidsHandlesHoverProvider, functionsHoverProvider, DDSToPNG, PNGToDDS, resizeTooltipCommand, resizeControllerCommand, resizeHotbarCommand, resizeCustomCommand, createModTemplateCommand, addIconBackgroundCommand);
+ context.subscriptions.push(uuidsHandlesHoverProvider, functionsHoverProvider, DDSToPNG, PNGToDDS, resizeTooltipCommand, resizeControllerCommand, resizeHotbarCommand, resizeCustomCommand, createModTemplateCommand, addIconBackgroundCommand, openConverterCommand, versionGeneratorCommand);
}
@@ -151,6 +152,7 @@ function aSimpleDataProvider() {
{ label: 'Launch Game', command: 'bg3-mod-helper.launchGame' },
{ label: 'Generate Folder Structure', command: 'bg3-mod-helper.createModTemplate' },
{ label: 'Supply a folder of icons to make an atlas and its corresponding .dds with those icons', command: 'bg3-mod-helper.createAtlas' },
+ { label: 'Version Generator', command: 'bg3-mod-helper.versionGenerator' },
{ label: 'Debug Command', command: 'bg3-mod-helper.debugCommand' }
]);
} else if (element.id === 'conversion') {
diff --git a/package.json b/package.json
index 3cfd4dba..f27f0a05 100644
--- a/package.json
+++ b/package.json
@@ -133,7 +133,11 @@
{
"command": "bg3-mod-helper.openConverter",
"title": "Open Converter"
- },
+ },
+ {
+ "command": "bg3-mod-helper.versionGenerator",
+ "title": "Version Generator"
+ },
{
"command": "bg3-mod-helper.debugCommand",
"title": "For dev use, dont press the button"