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

Dev #52

Merged
merged 42 commits into from
May 23, 2024
Merged

Dev #52

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b10c1de
no longer using python script to convert dds to png and back and forth
ghostboats May 15, 2024
afaa516
all my homies hate sharp. Sharp dependencies removed and reqrite of m…
ghostboats May 15, 2024
e898b79
Merge pull request #48 from ghostboats/dds_changes
ghostboats May 15, 2024
2c518fe
initial
ghostboats May 16, 2024
5afa26b
refactor: update handle insertion logic with new extension setting
AtilioA May 18, 2024
8db188a
chore: update description for adding handles to all loca files
AtilioA May 18, 2024
38d72f2
Merge pull request #49 from AtilioA/fix/dont-unconditionally-add-hand…
ghostboats May 19, 2024
8f6d4b0
extension fixed
ghostboats May 19, 2024
3560644
now package.json and config.js
ghostboats May 19, 2024
50fdcf3
Merge pull request #50 from ghostboats/modName_hotifx
ghostboats May 19, 2024
5fad752
nothing works
ghostboats May 20, 2024
167bae6
clean installed node
khbsd May 20, 2024
76631b6
clean install and remove sharp dep. also stop converting Items_Icons.lsx
khbsd May 20, 2024
967a4e3
:prayge:
ghostboats May 20, 2024
ea27755
opps
ghostboats May 20, 2024
1957711
Merge pull request #51 from ghostboats/merger
ghostboats May 20, 2024
06e6191
feat: improve loca file creation (locale picker + Localization & loca…
AtilioA May 21, 2024
6889a16
mupdates
khbsd May 21, 2024
f2e2b55
i shouldnt push this, please go back to previous commit if something …
ghostboats May 21, 2024
198a114
Merge branch 'dev' of https://github.com/ghostboats/bg3_mod_helper in…
khbsd May 21, 2024
17bf070
merge
khbsd May 21, 2024
5f9664b
vernum
khbsd May 21, 2024
818a801
everything appears to be working, i packed quickster with this
ghostboats May 21, 2024
41f5643
initialsadsad
ghostboats May 21, 2024
a85d723
refactor: don't show picker if there's only one file, handle newlines…
AtilioA May 21, 2024
84814aa
sort of working?
ghostboats May 21, 2024
71f963b
Merge pull request #53 from AtilioA/refactor/improve-loca-file-creation
ghostboats May 21, 2024
f42c7e1
Merge pull request #54 from AtilioA/refactor/improve-handle-generatio…
ghostboats May 21, 2024
b61b5c4
need to fix math for u1 v1 u2 v2
ghostboats May 21, 2024
85b5c75
fucking sharp
ghostboats May 21, 2024
1a9e918
need to make pak_ui merged now
ghostboats May 21, 2024
e428cdf
temp
ghostboats May 21, 2024
92c5532
wow it actually works
ghostboats May 21, 2024
a8166af
remove pyton scriupts hope all is awell, worked right before this, pu…
ghostboats May 21, 2024
a5a5c59
Merge pull request #55 from ghostboats/atlas_conversion
ghostboats May 21, 2024
16dc0f8
test this
ghostboats May 21, 2024
ef6ca3f
Merge branch 'dev' of https://github.com/ghostboats/bg3_mod_helper in…
khbsd May 21, 2024
938813a
packer tool addition ui adds
ghostboats May 21, 2024
609c12b
prep work before pulling
khbsd May 21, 2024
6e1813c
Merge branch 'dev' of https://github.com/ghostboats/bg3_mod_helper in…
khbsd May 21, 2024
dbaf936
babrebones mod unpacking
khbsd May 21, 2024
00437de
unpacking file selection and dropoff location added as well as packag…
ghostboats May 23, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/settings.json
*.vsix
81 changes: 24 additions & 57 deletions commands/DDSToPNG.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,36 @@
// DDSToPNG.js
//https://github.com/mmomtchev/magickwand.js/blob/main/example/example.mjs
const vscode = require('vscode');
const path = require('path');
const { exec } = require('child_process');
const { Magick } = require('magickwand.js');

const DDSToPNGCommand = vscode.commands.registerCommand('bg3-mod-helper.DDSToPNG', async (uri) => {
if (!uri) {
vscode.window.showErrorMessage('No file selected.');
return;
}

console.log('‾‾DDSToPNGCommand‾‾');
const checkWandScriptPath = path.join(__dirname, '..', 'support_files', 'python_scripts', 'check_wand.py');
const scriptPath = path.join(__dirname, '..', 'support_files', 'scripts', 'python', 'DDS_to_PNG.py');
const filePath = uri.fsPath;
const outputPath = filePath.replace(/\.[^/.]+$/, ".png");

// Check if Wand is installed
exec(`python "${checkWandScriptPath}"`, (error, stdout, stderr) => {
if (error) {
console.error('Error:', error);
return;
}
if (stderr) {
console.error('Script error:', stderr);
try {
let image = new Magick.Image();
await image.readAsync(filePath);

const infoDDS = new Magick.CoderInfo('DDS');
if (!infoDDS || !infoDDS.isReadable()) {
vscode.window.showErrorMessage("DDS format is not supported for reading.");
return;
}
if (stdout.trim() === "Wand not installed") {
vscode.window.showInformationMessage(
"Wand Python package is not installed. Open terminal to install wand? ENSURE PIP IS UPDATED, OTHERWISE RUN THIS MANUALLY IN TERMINAL: pip install wand",
"Yes",
"No"
).then(selection => {
if (selection === "Yes") {
// Open a new terminal with the command typed but not executed
const terminal = vscode.window.createTerminal(`Wand Install`);
terminal.show();
terminal.sendText("pip install wand", false); // false means don't execute

// Prompt user to press Enter in terminal
vscode.window.showInformationMessage("The terminal has opened with the pip install command. Please press Enter in the terminal to install Wand, then rerun this command.");
}
});
} else if (stdout.trim() === "ImageMagick not installed") {
// Prompt user to download ImageMagick
vscode.window.showInformationMessage(
"ImageMagick is not installed, which is required by Wand. Would you like to download it (installed headers as well in options when downlaoding)?",
"Download ImageMagick"
).then(selection => {
if (selection === "Download ImageMagick") {
vscode.env.openExternal(vscode.Uri.parse("https://imagemagick.org/script/download.php"));
}
});
} else {
// Wand is installed, proceed with conversion
const convertCommand = `python "${scriptPath}" -f "${filePath}"`;
exec(convertCommand, (convertError, convertStdout, convertStderr) => {
if (convertError) {
console.error('Error:', convertError);
vscode.window.showErrorMessage(`Error converting file: ${convertError.message}`);
return;
}
if (convertStderr) {
console.error('Script error:', convertStderr);
}
if (convertStdout) {
console.log('Script output:', convertStdout);
}
vscode.window.showInformationMessage(`File converted successfully.`);
});
}
});
await image.magickAsync('PNG');
await image.writeAsync(outputPath);

vscode.window.showInformationMessage(`DDS file converted successfully and saved as ${outputPath}`);
} catch (error) {
console.error('Error:', error);
vscode.window.showErrorMessage('Failed to convert DDS to PNG: ' + error.message);
}

console.log('__DDSToPNGCommand__');
});

Expand Down
2 changes: 1 addition & 1 deletion commands/DDSViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const { getConfig } = require('../support_files/config');
const { CREATE_LOGGER } = require('../support_files/log_utils');

const { modName, rootModPath } = getConfig();
const { rootModPath } = getConfig();
const modsDirPath = path.normalize(rootModPath + "\\Mods");
const bg3mh_logger = CREATE_LOGGER();

Expand Down
88 changes: 23 additions & 65 deletions commands/PNGToDDS.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,33 @@
// PNGToDDS.js
//https://github.com/mmomtchev/magickwand.js/blob/main/example/example.mjs
const vscode = require('vscode');
const path = require('path');
const { exec } = require('child_process');
const { Magick } = require('magickwand.js');

const PNGToDDSCommand = vscode.commands.registerCommand('bg3-mod-helper.PNGToDDS', async (uri) => {
console.log('‾‾PNGToDDSCommand‾‾');
const checkWandScriptPath = path.join(__dirname, '..', 'support_files', 'python_scripts', 'check_wand.py');
const scriptPath = path.join(__dirname, '..', 'support_files', 'scripts', 'python', 'PNG_to_DDS.py');
if (!uri) {
vscode.window.showErrorMessage('No file selected.');
return;
}

const filePath = uri.fsPath;
const normalizedFilePath = filePath.toLowerCase().replace(/\\/g, '/');

const ddsCompression = normalizedFilePath.includes('assets/textures/icons') ? 'DXT5' : 'DXT1';
const outputExtension = normalizedFilePath.includes('assets/textures') ? '.dds' : '.DDS';
const outputPath = filePath.replace(/\.[^/.]+$/, outputExtension);

try {
let image = new Magick.Image();
await image.readAsync(filePath);

// Normalize file path and determine output format
const normalizedFilePath = filePath.replace(/\\/g, '/').toLowerCase(); // Replace backslashes with forward slashes and convert to lower case
const outputFormat = normalizedFilePath.includes('assets/textures/icons') ? '.dds' : '.DDS';
const ddsCompression = outputFormat === '.dds' ? 'dxt5' : 'dxt1';
await image.magickAsync('DDS');

// Check if Wand is installed
exec(`python "${checkWandScriptPath}"`, (error, stdout, stderr) => {
if (error) {
console.error('Error:', error);
return;
}
if (stderr) {
console.error('Script error:', stderr);
return;
}
if (stdout.trim() === "Wand not installed") {
vscode.window.showInformationMessage(
"Wand Python package is not installed. Open terminal to install wand? ENSURE PIP IS UPDATED, OTHERWISE RUN THIS MANUALLY IN TERMINAL: pip install wand",
"Yes",
"No"
).then(selection => {
if (selection === "Yes") {
// Open a new terminal with the command typed but not executed
const terminal = vscode.window.createTerminal(`Wand Install`);
terminal.show();
terminal.sendText("pip install wand", false); // false means don't execute
await image.writeAsync(outputPath);

// Prompt user to press Enter in terminal
vscode.window.showInformationMessage("The terminal has opened with the pip install command. Please press Enter in the terminal to install Wand, then rerun this command.");
}
});
} else if (stdout.trim() === "ImageMagick not installed") {
// Prompt user to download ImageMagick
vscode.window.showInformationMessage(
"ImageMagick is not installed, which is required by Wand. Would you like to download it (installed headers as well in options when downlaoding)?",
"Download ImageMagick"
).then(selection => {
if (selection === "Download ImageMagick") {
vscode.env.openExternal(vscode.Uri.parse("https://imagemagick.org/script/download.php"));
}
});
} else {
// Wand is installed, proceed with conversion
const convertCommand = `python "${scriptPath}" -o "${outputFormat}" --ddscompression "${ddsCompression}" -f "${filePath}"`;
exec(convertCommand, (convertError, convertStdout, convertStderr) => {
if (convertError) {
console.error('Error:', convertError);
vscode.window.showErrorMessage(`Error converting file: ${convertError.message}`);
return;
}
if (convertStderr) {
console.error('Script error:', convertStderr);
}
if (convertStdout) {
console.log('Script output:', convertStdout);
}
vscode.window.showInformationMessage(`File converted successfully.`);
});
}
});
console.log('__PNGToDDSCommand__');
vscode.window.showInformationMessage(`File converted successfully and saved as ${outputPath}`);
} catch (error) {
console.error('Error:', error);
vscode.window.showErrorMessage('Failed to convert image: ' + error.message);
}
});

module.exports = PNGToDDSCommand;
54 changes: 31 additions & 23 deletions commands/addIconBackground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const vscode = require('vscode');
const sharp = require('sharp');
const path = require('path');
const fs = require('fs').promises; // Use promises version of fs for async/await compatibility
const fs = require('fs').promises;
const { Magick, MagickCore } = require('magickwand.js');

async function addIconBackground(uri) {
const inputPath = uri.fsPath;
Expand All @@ -10,17 +10,14 @@ async function addIconBackground(uri) {
try {
const files = await fs.readdir(backgroundsDir);
const pngFiles = files.filter(file => file.endsWith('.png'));
// Ensure each option has an isCustom property for consistent handling
const backgroundOptions = pngFiles.map(file => ({ label: file, isCustom: false }));
backgroundOptions.push({ label: 'Custom Background...', isCustom: true });

// Prompt user for background selection
const selectedBackground = await vscode.window.showQuickPick(backgroundOptions, { placeHolder: 'Select a background' });
if (!selectedBackground) return;

let backgroundPath;
if (selectedBackground.isCustom) {
// Handle custom background selection
const customUri = await vscode.window.showOpenDialog({
openLabel: 'Use Background',
canSelectMany: false,
Expand All @@ -29,42 +26,53 @@ async function addIconBackground(uri) {
if (customUri && customUri[0]) {
backgroundPath = customUri[0].fsPath;
} else {
return; // No file selected, exit the function
return;
}
} else {
// Use selected predefined background
backgroundPath = path.join(backgroundsDir, selectedBackground.label);
}

const outputPath = inputPath.replace(/\.\w+$/, `_with_background.png`);

// Load both images to compare sizes
const iconImage = sharp(inputPath);
const background = sharp(backgroundPath);
const [iconMetadata, backgroundMetadata] = await Promise.all([iconImage.metadata(), background.metadata()]);
const iconImage = new Magick.Image;
await iconImage.readAsync(inputPath);
const background = new Magick.Image;
await background.readAsync(backgroundPath);

const iconSize = await iconImage.sizeAsync();
const backgroundSize = await background.sizeAsync();
const iconWidth = iconSize.width();
const iconHeight = iconSize.height();
let backgroundWidth = backgroundSize.width();
let backgroundHeight = backgroundSize.height();

if (iconMetadata.width !== backgroundMetadata.width || iconMetadata.height !== backgroundMetadata.height) {
if (iconWidth !== backgroundWidth || iconHeight !== backgroundHeight) {
const resizeBackground = await vscode.window.showInformationMessage(
'The background and icon sizes do not match. Resize the background to match the icon?',
'Yes', 'No'
);
if (resizeBackground === 'Yes') {
await background.resize(iconMetadata.width, iconMetadata.height);
await background.resizeAsync(`${iconWidth}x${iconHeight}`);
const backgroundSizeResize = await background.sizeAsync();
backgroundWidth = backgroundSizeResize.width();
backgroundHeight = backgroundSizeResize.height();
} else {
return;
}
}

// Composite the icon over the resized background
background
.composite([{ input: await iconImage.toBuffer(), gravity: 'centre' }])
.toFile(outputPath)
.then(() => {
vscode.window.showInformationMessage(`Background added: ${outputPath}`);
})
.catch(err => {
vscode.window.showErrorMessage(`Error adding background: ${err}`);
});
const xOffset = Math.floor((backgroundWidth - iconWidth) / 2);
const yOffset = Math.floor((backgroundHeight - iconHeight) / 2);

console.log(`Calculated xOffset: ${xOffset}, yOffset: ${yOffset}`);

// Create a Geometry object for the composite operation
const geometry = new Magick.Geometry(iconWidth, iconHeight, xOffset, yOffset);
console.log('Attempting to composite with geometry:', geometry.toString());
await background.compositeAsync(iconImage, geometry, MagickCore.OverCompositeOp);

await background.writeAsync(outputPath);
vscode.window.showInformationMessage(`Background added: ${outputPath}`);
} catch (err) {
vscode.window.showErrorMessage(`Failed to read backgrounds directory or process images: ${err}`);
}
Expand Down
Loading
Loading