Skip to content

Commit

Permalink
Merge pull request #50 from ghostboats/modName_hotifx
Browse files Browse the repository at this point in the history
initial
  • Loading branch information
ghostboats authored May 19, 2024
2 parents 38d72f2 + 3560644 commit 50fdcf3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 42 deletions.
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
15 changes: 3 additions & 12 deletions commands/createAtlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const { v4: uuidv4 } = require('uuid');
const fs = require('fs');
const { getConfig } = require('../support_files/config');
const { getModName } = require('../support_files/helper_functions.js');

function findDivineExe(lslibPath) {
let divinePath = null;
Expand Down Expand Up @@ -43,8 +44,7 @@ let createAtlasCommand = vscode.commands.registerCommand('bg3-mod-helper.createA
const { rootModPath, lslibPath } = getConfig();

const scriptPath = path.join(__dirname, '..', 'support_files', 'scripts', 'python', 'add_icons_to_atlas.py');
const modsDirPath = path.join(rootModPath, 'Mods');
let modName = '';

let import_test = false

let divinePath_;
Expand All @@ -55,16 +55,7 @@ let createAtlasCommand = vscode.commands.registerCommand('bg3-mod-helper.createA
return;
}

// Check if Mods directory exists and get the first subfolder name
if (fs.existsSync(modsDirPath) && fs.lstatSync(modsDirPath).isDirectory()) {
const subfolders = fs.readdirSync(modsDirPath).filter(file => fs.lstatSync(path.join(modsDirPath, file)).isDirectory());
modName = subfolders.length > 0 ? subfolders[0] : '';
}

if (!modName) {
vscode.window.showErrorMessage('Mods directory not found or no subfolders to determine mod name.');
return;
}
const modName = await getModName();

function checkPythonImports(packages) {
return new Promise((resolve, reject) => {
Expand Down
11 changes: 7 additions & 4 deletions commands/packMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ const fs = require('fs');

const { exec } = require('child_process');
const { getConfig } = require('../support_files/config');
const { modName, rootModPath } = getConfig();
const { rootModPath } = getConfig();

const { CREATE_LOGGER, raiseError, raiseInfo } = require('../support_files/log_utils');
const bg3mh_logger = CREATE_LOGGER();

const vscodeDirPath = path.join(rootModPath, '.vscode');
const modsDirPath = path.normalize(rootModPath + "\\Mods");
const metaPath = path.normalize(modsDirPath + "\\" + modName + "\\meta.lsx");

const { v4: uuidv4 } = require('uuid');

const { convert } = require('../support_files/conversion_junction.js');
const { getModName } = require('../support_files/helper_functions.js');
const { getFormats } = require('../support_files/lslib_utils.js');
const { pak } = getFormats();


// i think we should separate out the functions here if possible- maybe put some of them in helper_functions?
const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod', async function () {
const { rootModPath, modDestPath, lslibPath, autoLaunchOnPack } = getConfig();
const modName = await getModName()

const modsDirPath = path.normalize(rootModPath + "\\Mods");
const metaPath = path.normalize(modsDirPath + "\\" + modName + "\\meta.lsx");

// Check if BG3 is running
const isRunning = await isGameRunning();
Expand Down Expand Up @@ -119,7 +122,7 @@ const packModCommand = vscode.commands.registerCommand('bg3-mod-helper.packMod',
fs.rmSync(vscodeDirPath, { recursive: true }); // Delete .vscode directory
}
// send the directory to the convert() function, and let it know it's a pak
convert(rootModPath, pak);
convert(rootModPath, pak, modName);

if (settingsContent) {
if (!fs.existsSync(vscodeDirPath)) {
Expand Down
6 changes: 2 additions & 4 deletions commands/rotationTool.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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 rotationToolCommand = vscode.commands.registerCommand('bg3-mod-helper.rotationTool', function () {
Expand Down
10 changes: 7 additions & 3 deletions commands/versionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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 { getModName } = require('../support_files/helper_functions.js');


const bg3mh_logger = CREATE_LOGGER();

let versionGeneratorCommand = vscode.commands.registerCommand('bg3-mod-helper.versionGenerator', function () {
Expand Down Expand Up @@ -34,6 +34,10 @@ let versionGeneratorCommand = vscode.commands.registerCommand('bg3-mod-helper.ve

async function addToMeta(version) {
bg3mh_logger.info('Updating Version64 in meta.lsx');
const { rootModPath } = getConfig();
const modName = await getModName();
const modsDirPath = path.normalize(rootModPath + "\\Mods");
const metaPath = path.normalize(modsDirPath + "\\" + modName + "\\meta.lsx");
if (!fs.existsSync(metaPath)) {
vscode.window.showErrorMessage(`Meta file not found at ${metaPath}`);
return;
Expand Down
2 changes: 1 addition & 1 deletion commands/xmlToLoca.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { convert } = require('../support_files/conversion_junction.js');
const { getFormats } = require('../support_files/lslib_utils.js');
const { loca, xml } = getFormats();
const { getConfig } = require('../support_files/config');
const { modName, rootModPath, } = getConfig();
const { rootModPath } = getConfig();


const xmlToLocaCommand = vscode.commands.registerCommand('bg3-mod-helper.xmlToLoca', async function () {
Expand Down
3 changes: 1 addition & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ function activate(context) {
hoverEnabled: config.get('hover.enabled'),
maxCacheSize: config.get('maxCacheSize'),
rootModPath: config.get('rootModPath'),
modName: path.basename(config.get('rootModPath')),
modDestPath: config.get('modDestPath'),
lslibPath: config.get('lslibPath'),
autoLaunchOnPack: config.get('autoLaunchOnPack'),
Expand Down Expand Up @@ -210,4 +209,4 @@ function deactivate() {}
module.exports = {
activate,
deactivate
};
};
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.

2 changes: 1 addition & 1 deletion 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.50",
"version": "2.1.51",
"icon": "media/marketplace_icon.png",
"engines": {
"vscode": "^1.86.0"
Expand Down
2 changes: 1 addition & 1 deletion support_files/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function getConfig() {
hoverEnabled: config.get('hover.enabled'),
maxCacheSize: config.get('maxCacheSize'),
rootModPath: path.normalize(config.get('rootModPath')),
modName: path.basename(config.get('rootModPath')),
modDestPath: path.normalize(config.get('modDestPath')),
lslibPath: path.normalize(config.get('lslibPath')),
autoLaunchOnPack: config.get('autoLaunchOnPack'),
launchContinueGame: config.get('launchContinueGame'),
addHandlesToAllLocas: config.get('addHandlesToAllLocas'),
excludedFiles: normalizeExcludedFiles(config.get('excludedFiles'))
};
}
Expand Down
6 changes: 3 additions & 3 deletions support_files/conversion_junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils');
const bg3mh_logger = CREATE_LOGGER();

const { getConfig } = require('./config.js');
const { rootModPath, modName, modDestPath } = getConfig();
const { rootModPath } = getConfig();

const { isLoca, processLoca, getLocaOutputPath } = require('./loca_convert');
const { isLsf, processLsf, getLsfOutputPath } = require('./lsf_convert');
Expand Down Expand Up @@ -42,7 +42,7 @@ function getDynamicPath(filePath) {
}


function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath))) {
function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPath)), modName_ = '') {
if (targetExt === "empty") {
return;
}
Expand All @@ -66,7 +66,7 @@ function convert(convertPath, targetExt = path.extname(getDynamicPath(convertPat
// changed these back, hope that's okay
convert(rootModPath, xml);
convert(rootModPath, lsx);
processPak(rootModPath);
processPak(rootModPath, modName_);
}
else if (Array.isArray(convertPath)) {
for (let i = 0; i < convertPath.length; i++) {
Expand Down
32 changes: 31 additions & 1 deletion support_files/helper_functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const vscode = require('vscode');
const path = require('path');
const { getConfig } = require('./config');
const fs = require('fs');

const { CREATE_LOGGER } = require('./log_utils');
var bg3mh_logger = CREATE_LOGGER();
Expand Down Expand Up @@ -63,4 +65,32 @@ async function findInstancesInWorkspace(word, currentFilePath, maxFilesToShow) {
return instances;
}

module.exports = { insertText, findInstancesInWorkspace, getFullPath };
async function getModName() {
const { rootModPath } = getConfig();
const modsDirPath = path.join(rootModPath, 'Mods');

try {
if (!fs.existsSync(modsDirPath)) {
vscode.window.showErrorMessage('Mods directory does not exist.');
return '';
}

const files = fs.readdirSync(modsDirPath);
const directories = files.filter(file =>
fs.statSync(path.join(modsDirPath, file)).isDirectory()
);

if (directories.length === 0) {
return '';
} else if (directories.length === 1) {
return directories[0];
} else {
return '';
}
} catch (error) {
vscode.window.showErrorMessage(`Error reading directories in ${modsDirPath}: ${error}`);
return '';
}
}

module.exports = { insertText, findInstancesInWorkspace, getFullPath, getModName };
13 changes: 7 additions & 6 deletions support_files/pack_mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ const { CREATE_LOGGER, raiseError, raiseInfo } = require('./log_utils');
var bg3mh_logger = CREATE_LOGGER();

const { getConfig } = require('./config.js');
const { rootModPath, modName, modDestPath } = getConfig();
const { rootModPath, modDestPath } = getConfig();
const rootParentPath = path.dirname(rootModPath);

const temp_folder = "\\temp_folder";
const temp_path = path.join(rootParentPath, temp_folder);
const modFinalDestPath = path.join(modDestPath, modName + pak);
const modTempDestPath = path.join(temp_path, modName + pak);



function prepareTempDir(movedPak = false) {
Expand All @@ -39,15 +38,17 @@ function prepareTempDir(movedPak = false) {


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

const modFinalDestPath = path.join(modDestPath, modName_ + pak);
const modTempDestPath = path.join(temp_path, modName_ + pak);
try {
await Packager.CreatePackage(modTempDestPath, modPath, build);

raiseInfo(modName + pak + " packed", false);
vscode.window.showInformationMessage(`${modName + pak} packed`);
raiseInfo(modName_ + pak + " packed", false);
vscode.window.showInformationMessage(`${modName_ + pak} packed`);

// move files to chosen path and [in progress] clean up the empty directory
moveFileAcrossDevices(modTempDestPath, modFinalDestPath);
Expand Down

0 comments on commit 50fdcf3

Please sign in to comment.