Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merger #51

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions commands/debug.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
const vscode = require('vscode');
const fs = require('fs');
const path = require('path');
const { getConfig } = require('../support_files/config');

const { FILTER_PATHS, FIND_FILES, getFormats } = require('../support_files/lslib_utils');
const { xml, lsx } = getFormats();
const debugCommand = vscode.commands.registerCommand('bg3-mod-helper.debugCommand', async function () {
const config = getConfig();
const localizationPath = path.join(config.rootModPath, 'Localization');

const { rootModPath } = require('../support_files/config.js').getConfig();
try {
// Step 1: List subdirectories
const directories = fs.readdirSync(localizationPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);

const { CREATE_LOGGER, raiseInfo } = require('../support_files/log_utils');
var bg3mh_logger = CREATE_LOGGER();
// Step 2: Show QuickPick for subdirectories
const selectedDirectory = await vscode.window.showQuickPick(directories, {
placeHolder: 'Select a Localization folder to merge'
});

var test_paths;
if (!selectedDirectory) return;

let debugCommand = vscode.commands.registerCommand('bg3-mod-helper.debugCommand', async function () { // Made the function async
console.log('‾‾debugCommand‾‾');
vscode.window.showWarningMessage(
'cmon dude i said no :('
)
// Step 3: List XML files in the selected subdirectory
const selectedDirPath = path.join(localizationPath, selectedDirectory);
const xmlFiles = fs.readdirSync(selectedDirPath, { withFileTypes: true })
.filter(dirent => dirent.isFile() && dirent.name.endsWith('.xml'))
.map(dirent => dirent.name);

console.log('__debugCommand__');
// Step 4: Use QuickPick to select XML files
const selectedFiles = await vscode.window.showQuickPick(xmlFiles, {
canPickMany: true,
placeHolder: 'Select XML files to merge'
});

if (!selectedFiles || selectedFiles.length === 0) return;

// Step 5: Ask for save location
const uri = await vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(path.join(selectedDirPath, 'xml_merged.xml')),
filters: { 'XML files': ['xml'] }
});

if (!uri) return;

// Step 6: Read and merge selected XML files
const mergedContent = selectedFiles
.map(file => fs.readFileSync(path.join(selectedDirPath, file), 'utf8'))
.join('\n');

// Step 7: Save the merged file
fs.writeFileSync(uri.fsPath, mergedContent, 'utf8');
vscode.window.showInformationMessage('XML files merged and saved successfully!');
} catch (error) {
vscode.window.showErrorMessage('Error merging XML files: ' + error.message);
}
});

module.exports = debugCommand;
15 changes: 11 additions & 4 deletions commands/launchGame.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const vscode = require('vscode');
const { spawn } = require('child_process');
const path = require('path');

const { getConfig } = require('../support_files/config');


const launchGameCommand = vscode.commands.registerCommand('bg3-mod-helper.launchGame', function () {
const { launchContinueGame } = getConfig();
const gameDir = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Baldurs Gate 3\\bin";
const gamePath = "bg3.exe";
const { launchContinueGame, gameInstallLocation } = getConfig();
if (!gameInstallLocation || gameInstallLocation === "") {
vscode.window.showErrorMessage('Game installation location is not set. Please configure it correctly in settings.');
return; // Stop execution if the path is not set
}

// Construct the path to the executable
const binLocation = path.join(gameInstallLocation, 'bin');
const gamePath = path.join(binLocation, "bg3.exe");
const args = launchContinueGame ? ["-continueGame"] : [];

const game = spawn(gamePath, args, { cwd: gameDir });
const game = spawn(gamePath, args, { cwd: binLocation });

game.on('error', (err) => {
console.error('Failed to start game:', err);
Expand Down
6 changes: 6 additions & 0 deletions commands/packMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,23 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod',
if (fs.existsSync(settingsFilePath)) {
settingsContent = fs.readFileSync(settingsFilePath, 'utf8');
}
console.log('test1')
fs.rmSync(vscodeDirPath, { recursive: true }); // Delete .vscode directory
console.log('test2')
}
// send the directory to the convert() function, and let it know it's a pak
convert(rootModPath, pak, modName);

if (settingsContent) {
console.log('test3')
if (!fs.existsSync(vscodeDirPath)) {
fs.mkdirSync(vscodeDirPath, { recursive: true });
console.log('test4')
}
fs.writeFileSync(settingsFilePath, settingsContent, 'utf8');
console.log('test5')
}
console.log('test6')
});


Expand Down
2 changes: 1 addition & 1 deletion commands/smartConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let smartConvertCommand = vscode.commands.registerCommand('bg3-mod-helper.smartC
let temp_ext = path.extname(temp_dir);
console.log("%s \n%s", temp_dir, temp_ext);

convert(temp_dir, temp_ext, true);
convert(temp_dir, temp_ext);
});

module.exports = smartConvertCommand;
3 changes: 2 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function activate(context) {
autoLaunchOnPack: config.get('autoLaunchOnPack'),
launchContinueGame: config.get('launchContinueGame'),
addHandlesToAllLocas: config.get('addHandlesToAllLocas'),
excludedFiles: config.get('excludedFiles') || []
excludedFiles: config.get('excludedFiles') || [],
gameInstallLocation: config.get('gameInstallLocation')
});
bg3mh_logger.info('Initial configs set:' + JSON.stringify(config, null, 2))
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
Expand Down
22 changes: 1 addition & 21 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 0 additions & 191 deletions node_modules/@img/sharp-win32-x64/LICENSE

This file was deleted.

Loading
Loading