Skip to content

Commit

Permalink
:prayge:
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostboats committed May 20, 2024
1 parent 5fad752 commit 967a4e3
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 23 deletions.
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@
"type": "boolean",
"default": true,
"description": "When generating handles, add them to all loca files. If disabled, prompts for which files to add handles to."
},
"bg3ModHelper.gameInstallLocation": {
"type": "string",
"default": "",
"description": "Path to where your Baulders Gate 3 is installed, ie [W:\\SteamLibrary\\steamapps\\common\\Baldurs Gate 3, C:\\Program Files (x86)\\Steam\\steamapps\\common\\Baldurs Gate 3, etc]:"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion support_files/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function getConfig() {
autoLaunchOnPack: config.get('autoLaunchOnPack'),
launchContinueGame: config.get('launchContinueGame'),
addHandlesToAllLocas: config.get('addHandlesToAllLocas'),
excludedFiles: normalizeExcludedFiles(config.get('excludedFiles'))
excludedFiles: normalizeExcludedFiles(config.get('excludedFiles')),
gameInstallLocation: path.normalize(config.get('gameInstallLocation'))
};
}
module.exports = { setConfig, getConfig };
7 changes: 5 additions & 2 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
return normalizedExcludedFiles.includes(normalizedFile);
};
*/

console.log('test10')
if (targetExt === pak) {
prepareTempDir();

console.log('past prepare temp')
// changed these back, hope that's okay
convert(rootModPath, xml);
convert(rootModPath, lsx);
Expand All @@ -75,10 +75,13 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
}
}
else if (fs.statSync(convertPath).isDirectory()) {
console.log('plz1')
const filesToConvert = FIND_FILES(convertPath, targetExt);
console.log('fdsfdsf')
convert(filesToConvert);
}
else if (fs.statSync(convertPath).isFile()) {
console.log('plz2')
if (isLoca(targetExt)) {
try {
processLoca(convertPath, targetExt);
Expand Down
5 changes: 3 additions & 2 deletions support_files/lslib_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ function LOAD_LSLIB() {
// maybe replace with findFiles()?
function FIND_FILES(filesPath, targetExt = getFormats().lsf, isRecursive = true) {
let filesToConvert = [];

console.log(filesPath)
console.log('heree1')
const filesList = fs.readdirSync(filesPath, {
withFileTypes: false,
recursive: isRecursive
});

console.log('heree2')
for (let i = 0; i < filesList.length; i++) {
const temp = filesList[i].toString();

Expand Down
17 changes: 17 additions & 0 deletions support_files/pack_mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const temp_path = path.join(rootParentPath, temp_folder);


function prepareTempDir(movedPak = false) {
console.log('test11')
console.log(rootParentPath)
console.log(rootModPath)
if (!(fs.existsSync(temp_path))) {
console.log("making temp_path");
fs.mkdirSync(temp_path, { recursive: true});
Expand All @@ -39,13 +42,27 @@ function prepareTempDir(movedPak = false) {

// btw, sometimes this will log things before others because it's async.
async function processPak(modPath, modName_) {
console.log('check')
var build = new LSLIB.PackageBuildData();
var Packager = new LSLIB.Packager();
const lastFolderName = path.basename(rootModPath);

const modFinalDestPath = path.join(modDestPath, lastFolderName + pak);
const modTempDestPath = path.join(temp_path, lastFolderName + pak);

const metaPath = path.join(rootModPath, 'Mods', modName_, 'meta.lsx');


try {
// Read the XML content
let xmlContent = fs.readFileSync(metaPath, 'utf8');

// Modify the Name attribute in the XML
xmlContent = xmlContent.replace(/(<attribute id="Name" type="FixedString" value=")(.*?)("\/>)/, `$1${lastFolderName}$3`);

// Write the updated XML back to the file
fs.writeFileSync(metaPath, xmlContent, 'utf8');
bg3mh_logger.info('meta.lsx updated successfully.');
await Packager.CreatePackage(modTempDestPath, modPath, build);

raiseInfo(lastFolderName + pak + " packed", false);
Expand Down

0 comments on commit 967a4e3

Please sign in to comment.