Skip to content

Commit

Permalink
hotfix conversion exclusions not working, can not right click context…
Browse files Browse the repository at this point in the history
… to add files to exclude list
  • Loading branch information
ghostboats committed May 10, 2024
1 parent b3744d4 commit 06436ad
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 54 deletions.
4 changes: 0 additions & 4 deletions commands/packMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod',


function createMetaContent(templateContent, author, description, folder, major, minor, revision, build, uuid, version64) {
// Replace placeholders in templateContent with actual values
return templateContent
.replace('{AUTHOR}', author)
.replace('{DESCRIPTION}', description)
Expand All @@ -148,16 +147,13 @@ function createMetaContent(templateContent, author, description, folder, major,


function createVersion64(major, minor, build, revision) {
// Convert input numbers to BigInt
const majorBigInt = BigInt(major);
const minorBigInt = BigInt(minor);
const buildBigInt = BigInt(build);
const revisionBigInt = BigInt(revision);

// Shift bits and combine them
const version64 = (majorBigInt << BigInt(55)) | (minorBigInt << BigInt(47)) | (revisionBigInt << BigInt(31)) | buildBigInt;

// Return the version as a string
return version64;

}
Expand Down
24 changes: 20 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ const { resizeImageTooltip, resizeImageController, resizeImageHotbar, resizeImag

const { getFullPath } = require('./support_files/helper_functions');

/**
* Adds a file to the exclusion list.
* @param {vscode.Uri} fileUri - The URI of the file to be excluded.
*/
async function addToExcludeList(fileUri) {
const config = vscode.workspace.getConfiguration('bg3ModHelper');
let excludedFiles = config.get('excludedFiles') || [];

const filePath = fileUri.fsPath.replace(/\\/g, '/');

if (!excludedFiles.includes(filePath)) {
excludedFiles.push(filePath);
await config.update('excludedFiles', excludedFiles, vscode.ConfigurationTarget.Global);
vscode.window.showInformationMessage(`${filePath} added to conversion exclusion list.`);
} else {
vscode.window.showWarningMessage(`${filePath} is already in the exclusion list.`);
}
}


/**
* @param {vscode.ExtensionContext} context
Expand Down Expand Up @@ -124,7 +143,7 @@ function activate(context) {


let createModTemplateCommand = vscode.commands.registerCommand('bg3-mod-helper.createModTemplate', createModTemplateImport);

context.subscriptions.push(vscode.commands.registerCommand('bg3-mod-helper.addToExcludeList', addToExcludeList));
context.subscriptions.push(uuidsHandlesHoverProvider, functionsHoverProvider, DDSToPNG, PNGToDDS, resizeTooltipCommand, resizeControllerCommand, resizeHotbarCommand, resizeCustomCommand, createModTemplateCommand, addIconBackgroundCommand, openConverterCommand, versionGeneratorCommand);
}

Expand All @@ -145,7 +164,6 @@ function aSimpleDataProvider() {
},
getChildren: (element) => {
if (!element) {
// Root level
return Promise.resolve([
{ label: 'Pack Mod', command: 'bg3-mod-helper.packMod' },
{ label: 'Conversion Tool (Click arrow for quick actions, or text to open the tool)', command: 'bg3-mod-helper.openConverter', id: 'conversion' },
Expand All @@ -156,15 +174,13 @@ function aSimpleDataProvider() {
{ label: 'Debug Command', command: 'bg3-mod-helper.debugCommand' }
]);
} else if (element.id === 'conversion') {
// Conversion submenu
return Promise.resolve([
{ label: 'Convert all XML to LOCA', command: 'bg3-mod-helper.xmlToLoca' },
{ label: 'Convert all LOCA to XML', command: 'bg3-mod-helper.locaToXml' },
{ label: 'Convert all LSX to LSF', command: 'bg3-mod-helper.lsxToLsf' },
{ label: 'Convert all LSF to LSX', command: 'bg3-mod-helper.lsfToLsx' }
]);
} else {
// No further nesting
return Promise.resolve([]);
}
}
Expand Down
16 changes: 6 additions & 10 deletions hovers/functionDescriptions.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
const vscode = require('vscode');
const functionInfo = require('../support_files/templates/functionInfo'); // Assume this contains your function descriptions and parameters
const functionInfo = require('../support_files/templates/functionInfo');

function setupFunctionDescriptionHoverProvider() {
return vscode.languages.registerHoverProvider([
{ language: 'plaintext' }, // For .txt files
{ pattern: '**/*.lsx' } // For .lsx files using a filename pattern
{ language: 'plaintext' },
{ pattern: '**/*.lsx' }
], {
provideHover(document, position, token) {
const wordRange = document.getWordRangeAtPosition(position);
const word = document.getText(wordRange);

// Check if the word is a function name
if (functionInfo[word]) {
const info = functionInfo[word];
const contents = new vscode.MarkdownString();

// Styling the hover content
contents.appendMarkdown(`### ${word}\n\n`); // Function name in bold
contents.appendMarkdown(`**Description:**\n${info.description}\n\n`); // Description in bold
contents.appendMarkdown(`### ${word}\n\n`);
contents.appendMarkdown(`**Description:**\n${info.description}\n\n`);
contents.appendMarkdown(`**Parameters:**\n`);

// Styling each parameter
info.parameters.forEach(param => {
contents.appendMarkdown(`- \`${param}\`\n`); // Parameter in code style
contents.appendMarkdown(`- \`${param}\`\n`);
});

// Ensures that the Markdown content is rendered correctly
contents.isTrusted = true;

return new vscode.Hover(contents);
Expand Down
2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

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

4 changes: 2 additions & 2 deletions package-lock.json

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

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "bg3_mod_helper",
"publisher": "ghostboats",
"description": "This extension is designed to help you make mods in Baldur's Gate 3 by creating UUIDs and handles for you, as well as updating your .loca.xml files as well should they exist. And more to come in the future.",
"version": "2.1.0",
"version": "2.1.10",
"icon": "media/marketplace_icon.png",
"engines": {
"vscode": "^1.88.0"
Expand Down Expand Up @@ -138,6 +138,11 @@
"command": "bg3-mod-helper.versionGenerator",
"title": "Version Generator"
},
{
"command": "bg3-mod-helper.addToExcludeList",
"title": "Add to Conversion Exclusion List",
"category": "BG3 Mod Helper"
},
{
"command": "bg3-mod-helper.debugCommand",
"title": "For dev use, dont press the button"
Expand Down Expand Up @@ -193,7 +198,7 @@
},
"bg3ModHelper.excludedFiles": {
"type": "array",
"description": "List of files to exclude from conversion, ie [c:/path/to/ur/file.lsx]",
"description": "List of files to exclude from conversion. You can quick add items to this via right click on a file in the file tree -> Add to Conversion Exclusion List. Example: [c:/path/to/ur/file.lsx]",
"default": [],
"items": {
"type": "string"
Expand Down Expand Up @@ -270,6 +275,11 @@
"when": "resourceExtname == .dll || resourceExtname == .loca || resourceExtname == .xml || resourceExtname == .lsb || resourceExtname == .lsf || resourceExtname == .lsj || resourceExtname == .lsfx || resourceExtname == .lsbc || resourceExtname == .lsbs || resourceExtname == .lsx",
"command": "bg3-mod-helper.smartConvert",
"group": "navigation"
},
{
"when": "resourceExtname == .lsx || resourceExtname == .loca || resourceExtname == .xml || resourceExtname == .lsf",
"command": "bg3-mod-helper.addToExcludeList",
"group": "navigation"
}
],
"editor/context": [
Expand Down
71 changes: 40 additions & 31 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,57 @@ function getDynamicPath(filePath) {
// this should be refactored in next release
function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath))) {
const { excludedFiles } = getConfig();
//convertPath = convertPath.toString();
const normalizedExcludedFiles = excludedFiles.map(file => path.normalize(file).replace(/^([a-zA-Z]):/, (match, drive) => drive.toUpperCase() + ':'));

//bg3mh_logger.info(`Excluded Files: ${JSON.stringify(excludedFiles, null, 2)}`);
//console.log(`Excluded Files: ${JSON.stringify(excludedFiles, null, 2)}`);
console.log(`Normalized Excluded Files: ${JSON.stringify(normalizedExcludedFiles, null, 2)}`);

if (targetExt == pak) {
const isExcluded = (file) => {
const normalizedFile = path.normalize(file).replace(/^([a-zA-Z]):/, (match, drive) => drive.toUpperCase() + ':');
return normalizedExcludedFiles.includes(normalizedFile);
};

if (targetExt === '.pak') {
prepareTempDir();

convert(rootModPath, xml);
convert(rootModPath, lsx);
convert(rootModPath, '.xml');
convert(rootModPath, '.lsx');
processPak(rootModPath);
}
else if (Array.isArray(convertPath)) {
for (var i = 0; i < convertPath.length; i++) {
convert(convertPath[i], path.extname(convertPath[i]));
}
}
else if (fs.statSync(convertPath).isDirectory()) {
convert(FIND_FILES(convertPath, targetExt));
}
else if (fs.statSync(convertPath).isFile()) {
if (isLoca(targetExt)) {
try {
processLoca(convertPath, targetExt);
}
catch (Error) {
raiseError(Error);
return;
} else if (Array.isArray(convertPath)) {
for (let i = 0; i < convertPath.length; i++) {
if (!isExcluded(convertPath[i])) {
convert(convertPath[i], path.extname(convertPath[i]));
} else {
console.log(`Excluded: ${convertPath[i]}`);
}
}
else if (isLsf(targetExt)) {
try {
processLsf(convertPath, targetExt);
}
catch (Error) {
raiseError(Error);
return;
} else if (fs.statSync(convertPath).isDirectory()) {
const filesToConvert = FIND_FILES(convertPath, targetExt);
const filteredFiles = filesToConvert.filter(file => !isExcluded(file));
console.log(`Files to convert (after exclusion): ${JSON.stringify(filteredFiles, null, 2)}`);
convert(filteredFiles);
} else if (fs.statSync(convertPath).isFile()) {
if (!isExcluded(convertPath)) {
if (isLoca(targetExt)) {
try {
processLoca(convertPath, targetExt);
} catch (Error) {
raiseError(Error);
return;
}
} else if (isLsf(targetExt)) {
try {
processLsf(convertPath, targetExt);
} catch (Error) {
raiseError(Error);
return;
}
}
} else {
console.log(`Excluded: ${convertPath}`);
}

}
}



module.exports = { convert };

0 comments on commit 06436ad

Please sign in to comment.