-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun-generator.js
36 lines (31 loc) · 1.35 KB
/
gun-generator.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
function generate() {
// Get inputs
const gunNameInput = document.getElementById("gunNameInput");
const amountOfBulletsToShootInput = document.getElementById("amountOfBulletsToShootInput");
const bulletsThatAreUsedInput = document.getElementById("bulletsThatAreUsedInput");
const damageInput = document.getElementById("damageInput");
const holdToShootInput = document.getElementById("holdToShootInput");
const delayInput = document.getElementById("delayInput");
const shootBackwardsInput = document.getElementById("shootBackwardsInput");
const imageInput = document.getElementById("imageInput");
// Create object with values
var obj = new Object();
obj.GunName = gunNameInput.value;
obj.AmountOfBulletsToShoot = amountOfBulletsToShootInput.value;
obj.BulletsThatAreUsed = bulletsThatAreUsedInput.value;
obj.Damage = damageInput.value;
obj.HoldToShoot = holdToShootInput.checked;
obj.ShootBackwards = shootBackwardsInput.checked;
obj.Delay = delayInput.value;
// Create JSON
var jsonString = JSON.stringify(obj);
// Create Zip
var zip = new JSZip();
zip.file("gun.json", jsonString);
zip.file("image.png", imageInput.files[0])
// Download the Zip
zip.generateAsync({type: "blob"})
.then(function(content) {
saveAs(content, gunNameInput.value + ".zip");
});
}