Skip to content

Commit

Permalink
Merge pull request #35 from ghostboats/version_generatorv1
Browse files Browse the repository at this point in the history
fixed?
  • Loading branch information
ghostboats authored May 9, 2024
2 parents af5cb8a + 7189f78 commit e54fbb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 74 deletions.
89 changes: 18 additions & 71 deletions commands/openConverter.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
const { convert } = require('../support_files/conversion_junction.js');
const vscode = require('vscode');

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

var lsxFiles;
var lsfFiles;
var xmlFiles;
var locaFiles;


async function refreshFiles() {
lsxFiles = await vscode.workspace.findFiles('**/*.lsx');
// added extra files that should be shown in the lsf panel of the webview
lsfFiles = await vscode.workspace.findFiles('**/*.{lsf,lsfx,lsc,lsj,lsbc,lsbs}');
xmlFiles = await vscode.workspace.findFiles('**/*.xml');
locaFiles = await vscode.workspace.findFiles('**/*.loca');
}


const { convert } = require('../support_files/conversion_junction.js');
let openConverterCommand = vscode.commands.registerCommand('bg3-mod-helper.openConverter', async function () {
bg3mh_logger.info('‾‾openConverterCommand‾‾');
console.log('‾‾openConverterCommand‾‾');
const panel = vscode.window.createWebviewPanel(
'converterView',
'Converter',
vscode.ViewColumn.One,
{ enableScripts: true }
);

await refreshFiles();
const lsxFiles = await vscode.workspace.findFiles("**/*.lsx");
const lsfFiles = await vscode.workspace.findFiles("**/*.{lsf,lsfx,lsj,lsb,lsbs,lsbc}");
const xmlFiles = await vscode.workspace.findFiles("**/*.xml");
const locaFiles = await vscode.workspace.findFiles("**/*.loca");

panel.webview.html = getWebviewContent(lsxFiles, lsfFiles, xmlFiles, locaFiles);
panel.webview.onDidReceiveMessage(
async message => {
bg3mh_logger.info('Received message:', message);
(message) => {
console.log('Received message:', message);
try {
switch (message.command) {
case 'convertSelected':
case 'convertAll':
const pathsString = message.paths.join(", ");
const result = convert(message.paths, "arr");
vscode.window.showInformationMessage(`Converting files: ${pathsString}`);
console.log(message.paths);

convert(message.paths, "arr");
panel.webview.postMessage({ command: 'alert', text: 'Conversion successful!' });
await refreshFileList(panel);
break;
}
} catch (err) {
panel.webview.postMessage({ command: 'alert', text: 'Error during conversion: ' + err.message });
raiseError("Error during message processing: " + err, false);
console.error('Error during message processing:', err);
}
}
);
bg3mh_logger.info('__openConverterCommand__');

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

function normalizePath(path) {
Expand All @@ -60,20 +47,6 @@ function normalizePath(path) {
return path;
}

async function refreshFileList(panel) {

await refreshFiles();

panel.webview.postMessage({
command: 'updateFiles',
lsxFiles: lsxFiles.map(file => file.path),
lsfFiles: lsfFiles.map(file => file.path),
xmlFiles: xmlFiles.map(file => file.path),
locaFiles: locaFiles.map(file => file.path)
});
}


function getWebviewContent(lsxFiles, lsfFiles, xmlFiles, locaFiles) {
const makeListItems = files => files.map(file =>
`<div class='file-item' data-path="${normalizePath(file.path)}" onclick='selectFile(this)'>${file.path.split('/').pop()}</div>`
Expand Down Expand Up @@ -173,7 +146,7 @@ function clearSelections(filesList) {
function convertSelected() {
let selectedFiles = Array.from(document.querySelectorAll('.file-item.selected'));
let filePaths = selectedFiles.map(file => file.getAttribute('data-path'));
bg3mh_logger.info('Attempting to convert selected files with paths:', filePaths);
console.log('Attempting to convert selected files with paths:', filePaths);
vscode.postMessage({
command: 'convertSelected',
paths: filePaths
Expand All @@ -183,42 +156,16 @@ function convertSelected() {
function convertAll() {
let allFiles = Array.from(document.querySelectorAll('.file-item'));
let filePaths = allFiles.map(file => file.getAttribute('data-path'));
bg3mh_logger.info('Attempting to convert all files with paths:', filePaths);
console.log('Attempting to convert all files with paths:', filePaths);
vscode.postMessage({
command: 'convertAll',
paths: filePaths
});
}
</script>
</body>
</html>
`;
}

module.exports = openConverterCommand;


//add this in html once we figure out the syntax stuff, hopoefully it helps update the window upon conversion. Its to add listener to update webview for new files
/*
window.addEventListener('message', event => {
const message = event.data;
switch (message.command) {
case 'updateFiles':
updateFileList('lsxFilesList', message.lsxFiles);
updateFileList('lsfFilesList', message.lsfFiles);
updateFileList('xmlFilesList', message.xmlFiles);
updateFileList('locaFilesList', message.locaFiles);
break;
}
});
function updateFileList(elementId, files) {
const fileList = document.getElementById(elementId);
fileList.innerHTML = files.map(file =>
<div class='file-item' data-path='${file}' onclick='selectFile(this)'>${file.split('/').pop()}</div>
).join('');
}
*/
module.exports = openConverterCommand;
4 changes: 1 addition & 3 deletions commands/versionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ function getWebviewContent() {
const build = document.getElementById('build').value;
const version = createVersion64(major, minor, revision, build);
document.getElementById('version').value = version;
// Save current state
vscode.setState({ major, minor, revision, build, version });
}
Expand Down Expand Up @@ -281,7 +279,7 @@ function getWebviewContent() {
});
});
// Restore saved state if available
// Restore ssaved set if possible
const state = vscode.getState();
if (state) {
document.getElementById('major').value = state.major;
Expand Down

0 comments on commit e54fbb8

Please sign in to comment.