Skip to content

Commit

Permalink
getting things ready for getting serious again
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostboats committed Oct 2, 2024
1 parent da570bc commit 22e3430
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 39 deletions.
2 changes: 1 addition & 1 deletion commands/insertHandleUUID.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let handleReplaceDisposable = vscode.commands.registerCommand('bg3-mod-helper.ge
let documentsToSave = new Set();

// Search across all text files in the workspace
const files = await vscode.workspace.findFiles('**/*.{txt,lsx,lsj,xml}');
const files = await vscode.workspace.findFiles('**/*.{txt,lsx,lsj,xml,json}');
for (const file of files) {
const textDoc = await vscode.workspace.openTextDocument(file);
const text = textDoc.getText();
Expand Down
7 changes: 4 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AutoCompleteProvider = require('./autocomplete/autoCompleteProvider');
const setupFunctionDescriptionHoverProvider = require('./hovers/functionDescriptions');
const { setupUuidsHandlesHoverProvider, registerTextEditCommand }= require('./hovers/uuidsHandlesCollector');

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


function setCommands() {
Expand Down Expand Up @@ -218,7 +218,8 @@ function aSimpleDataProvider() {
},
getChildren: (element) => {
if (!element) {
return Promise.resolve([
const version = getVersionNumber()
return getVersionNumber().then(version => [
// ideas for more dropdown menus: image utilities, generators, debug
{ label: 'Pack/Unpacking Tool (Click arrow for quick actions, or text to open the tool[tool is in development])', id: 'packer' },
{ label: 'Conversion Tool (Click arrow for quick actions, or text to open the tool)', command: 'bg3-mod-helper.openConverter', id: 'conversion' },
Expand All @@ -229,7 +230,7 @@ function aSimpleDataProvider() {
{ label: 'Atlas Generator (Supply a folder of icons to make an atlas and its corresponding .dds with those icons, as well as its merged.lsx)', command: 'bg3-mod-helper.createAtlas' },
{ label: 'BBCode/Markdown Editor ', command: 'bg3-mod-helper.textEditorTool'},
{ label: 'Convert Video to GIF', command: 'bg3-mod-helper.convertVideoToGif' },
{ label: 'Version Generator', command: 'bg3-mod-helper.versionGenerator' },
{ label: `Ver. Generator (${version})`, command: 'bg3-mod-helper.versionGenerator' },
{ label: 'Merge Xmls', command: 'bg3-mod-helper.xmlMerger' },
{ label: 'Add/Remove Symlink (in development)', command: 'bg3-mod-helper.symlinker' },
{ label: 'Rotation Tool (in development)', command: 'bg3-mod-helper.rotationTool' },
Expand Down
7 changes: 6 additions & 1 deletion hovers/uuidsHandlesCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function escapeHtml(str) {
}

function setupUuidsHandlesHoverProvider() {
return vscode.languages.registerHoverProvider({ scheme: 'file' }, {
return vscode.languages.registerHoverProvider('*', {
provideHover(document, position, token) {
const { hoverEnabled, maxFilesToShow, maxCacheSize } = getConfig();
if (!hoverEnabled) return;
Expand Down Expand Up @@ -49,13 +49,18 @@ function setupUuidsHandlesHoverProvider() {
const normalizedPath = relativePath.replace(/\\/g, '/').toLowerCase();
console.log(relativePath)
console.log(normalizedPath)
const extension = path.extname(relativePath).toLowerCase();
// Check if the file is within the Localization folder
if (normalizedPath.includes('localization/')) {
// Process as a localization-related file
const contentMatch = lineContent.match(/<content[^>]*>(.*?)<\/content>/);
let highlightedLineContent = contentMatch ? escapeHtml(contentMatch[1]) : '';
const commandUri = `command:extension.editText?${encodeURIComponent(JSON.stringify({ word: highlightedLineContent, range: { lineNum, path: relativePath } }))}`;
currentLine = `Loca Content: ***[${highlightedLineContent}](${commandUri})***\nFile: [${relativePath}](command:extension.openFileAtLine?${encodeURIComponent(JSON.stringify({ relativePath, lineNum }))})\n---\n`;
} else if (extension === '.json') {
// Process as a JSON file
let highlightedLineContent = escapeHtml(lineContent.trim());
currentLine = `JSON Line: ${highlightedLineContent} \nFile: [**${relativePath}**](${openFileCommandUri}) \n--- \n`;
} else {
let modifiedLineContent = lineContent.replace(/^<\/?|\/?>$/g, '');
let highlightedLineContent = modifiedLineContent.replace(/(id="[^"]*")/g, '**$1**');
Expand Down
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.2.58",
"version": "2.2.59",
"icon": "media/marketplace_icon.png",
"engines": {
"vscode": "^1.86.0"
Expand Down
50 changes: 39 additions & 11 deletions support_files/helper_functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const vscode = require('vscode');
const path = require('path');
const fs = require('fs');
const { getConfig, getModName } = require('../support_files/config');

const { CREATE_LOGGER, raiseInfo } = require('./log_utils');
var bg3mh_logger = CREATE_LOGGER();
Expand All @@ -16,7 +17,6 @@ function insertText(text) {
}
}


function getFullPath(relativePath) {
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
// Get the path of the first workspace folder
Expand All @@ -35,18 +35,18 @@ function getFullPath(relativePath) {
// Function to find instances in workspace
async function findInstancesInWorkspace(word, currentFilePath, maxFilesToShow) {
bg3mh_logger.debug('‾‾findInstanceInWorkspace‾‾');
bg3mh_logger.debug('word: ',word,'\ncurrentFilePath: ',currentFilePath,'\nmaxFilesToShow: ',maxFilesToShow);
bg3mh_logger.debug('word: ', word, '\ncurrentFilePath: ', currentFilePath, '\nmaxFilesToShow: ', maxFilesToShow);
let instances = [];
const workspaceFolder = vscode.workspace.workspaceFolders[0];
const workspacePath = workspaceFolder.uri.fsPath;

let searchPath = new vscode.RelativePattern(workspacePath, '{**/*.lsx,**/*.lsj,**/*.xml,**/*.txt}');
let searchPath = new vscode.RelativePattern(workspacePath, '{**/*.lsx,**/*.lsj,**/*.xml,**/*.txt,**/*.txt}');
const excludePattern = '**/*.lsf,**/node_modules/**,**/*.loca';
const files = await vscode.workspace.findFiles(searchPath, excludePattern);

for (const file of files) {
if (file.fsPath === currentFilePath) continue;

const relativePath = vscode.workspace.asRelativePath(file.fsPath);
const document = await vscode.workspace.openTextDocument(file);

Expand All @@ -60,14 +60,42 @@ async function findInstancesInWorkspace(word, currentFilePath, maxFilesToShow) {
}
if (instances.length >= maxFilesToShow) break;
}
bg3mh_logger.debug('Found Instances:\n',instances)
bg3mh_logger.debug('__findInstanceInWorkspace__')
bg3mh_logger.debug('Found Instances:\n', instances);
bg3mh_logger.debug('__findInstanceInWorkspace__');
return instances;
}

async function getVersionNumber() {
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('Version unable to be displayed in data provider, could not find meta.lsx.');
return 'N/A';
}

try {
let content = fs.readFileSync(metaPath, 'utf8');

const regex = /<attribute id="Version64" type="int64" value="([^"]*)"\s*\/>/;
const match = content.match(regex);
const version = BigInt(match[1]);
const major = Number((version >> BigInt(55)) & BigInt(0xFF));
const minor = Number((version >> BigInt(47)) & BigInt(0xFF));
const revision = Number((version >> BigInt(31)) & BigInt(0xFFFF));
const build = Number(version & BigInt(0x7FFFFFFF));
return `${major}.${minor}.${revision}.${build}`;
} catch (error) {
vscode.window.showErrorMessage("Error reading meta.lsx: " + error.message);
return 'N/A';
}
}

module.exports = {
insertText,
findInstancesInWorkspace,
getFullPath
};
module.exports = {
insertText,
findInstancesInWorkspace,
getFullPath,
getVersionNumber
};
23 changes: 3 additions & 20 deletions support_files/release_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,15 @@ function generateReleaseNotes(version) {
version: version,
features: [
{
title: "Release Page Created",
title: "Changes",
details: [
"On launch of newly downloaded version of extension, launch release notes page showing newest updates, like this one :)"
]
},
{
title: "Mod Setting Changes [IMPORTANT]",
details: [
"Choose to launch via directx or vulkan in the settings",
"Setting added to close the existing bg3 instance when you pack and play for quicker launch if you forgot to close. By default it is off.",
"If you have a unique mod destination path, the prompt will now only appear one time per session to avoid having to confirm each time on pack"
]
},
{
title: "Zipping Fixes",
details: [
"Zipped files appear in correct location now (your set mod destination)",
"Pak file is deleted now if zip is made"
"I DONT REMEMBER, SORRY I DIDNT HAVE MY COMPUTER FOR OVER A MONTH AND FORGOT WHAT I DID"
]
},
{
title: "Minor Changes",
details: [
"Atlas Fix if .lsx file doenst exist yet",
"Generate and Replace Handle option added when highlighting a handle and rightclicking",
"Generate Handle will now correctly save the xml files it adds it to",
"Json files will now be recognized for handle hovers (MCM stuff)"
]
},
{
Expand Down

0 comments on commit 22e3430

Please sign in to comment.