-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
76 lines (67 loc) · 3.07 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { ipcRenderer } = require('electron');
const path = require('path');
const fs = require('fs');
ipcRenderer.on('update-progress', (event, progress) => {
const progressBar = document.getElementById('progressBar');
const progressStatus = document.getElementById('progressStatus');
progressBar.value = progress.value;
progressStatus.innerText = progress.message;
});
ipcRenderer.on('update-check-reply', (event, message) => {
alert(message);
});
document.getElementById('createModButton').addEventListener('click', function() {
const modName = document.getElementById('modName').value;
const authorName = document.getElementById('authorName').value;
const textureFile = document.getElementById('textureFile').files[0];
const includeBaseUniform = document.querySelector('input[name="baseUniform"]').checked;
const includeIndepUniform = document.querySelector('input[name="indepUniform"]').checked;
const includeCoveralls = document.querySelector('input[name="civCoveralls"]').checked;
const includeAssaultPack = document.querySelector('input[name="assaultPack"]').checked;
const includeCarrierRig = document.querySelector('input[name="carrierRig"]').checked;
const includeSpecialCarrierRig = document.querySelector('input[name="carrierRigSpecial"]').checked;
const includeHelmet = document.querySelector('input[name="helmetBlufor"]').checked;
const blendedNormals = document.querySelector('input[name="blendUniform"]').checked;
// Check for missing inputs
if (!modName) {
alert('Please provide a Mod Name.');
return;
}
if (!authorName) {
alert('Please provide an Author Name.');
return;
}
if (!textureFile) {
alert('Please upload a texture file.');
return;
}
// Show loading bar
document.getElementById('progressBar').style.display = 'block';
document.getElementById('progressStatus').style.display = 'block';
document.getElementById('createModButton').disabled = true;
// Copy the image file to the texture folder
const destinationPath = path.join(__dirname, 'texture/texture.png');
fs.copyFileSync(textureFile.path, destinationPath);
let addons = [];
if (includeBaseUniform) addons.push('baseUniform');
if (includeIndepUniform) addons.push('indepUniform');
if (includeAssaultPack) addons.push('assaultPack');
if (includeSpecialCarrierRig) addons.push('carrierRigSpecial');
if (includeCarrierRig) addons.push('carrierRig');
if (includeHelmet) addons.push('helmetBlufor');
if (includeCoveralls) addons.push('civCoveralls');
ipcRenderer.send('create-mod', { className: modName, author: authorName, options: { blendedNormals, addons } });
ipcRenderer.on('create-mod-reply', (event, response) => {
if (response === 'success') {
alert('Mod created successfully!');
} else {
// Handle error
console.error(response);
alert(`Error creating mod: \n\n${response}`);
}
// Hide loading bar
document.getElementById('progressBar').style.display = 'none';
document.getElementById('progressStatus').style.display = 'none';
document.getElementById('createModButton').disabled = false;
});
});