File size: 1,244 Bytes
913928f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Author: Peter Dragicevic [peter@petschko.org]
 * Authors-Website: http://petschko.org/
 * Date: 14.07.2017
 * Time: 22:06
 */

/**
 * Creates a new ZIP Object
 *
 * @constructor - ZIP
 */
function ZIP() {
	this.files = [];
}

/**
 * Removes all references from the ZIP-Object
 */
ZIP.prototype.dispose = function() {
	for(var i = 0; i < this.files.length; i++) {
		this.files[i].dispose();
	}

	// Remove all Files from the List
	this.files = [];
};

/**
 * Adds a new File to the ZIP-File
 *
 * @param {RPGFile} rpgFile - RPG-File to add
 */
ZIP.prototype.addFile = function(rpgFile) {
	this.files.push(rpgFile);
};

/**
 * Turns all Files into a ZIP-File and Download it
 */
ZIP.prototype.save = function() {
	if(this.files.length < 1)
		return;

	var jsZip = new JSZip();

	// Add all Files to the ZIP
	var addedFiles = 0;
	for(var i = 0; i < this.files.length; i++) {
		if(this.files[i].content !== null) {
			jsZip.file(this.files[i].name + '.' + this.files[i].extension, this.files[i].content);
			addedFiles++;
		}
	}

	// Download ZIP
	if(addedFiles > 0) {
		jsZip.generateAsync({type: 'blob'}).then(function(blob) {
			saveAs(blob, 'RPG-Files.zip');
			blob = null;
		});
	} else
		alert(lang.strings['error.zip.emptyZip']);
};