aboutsummaryrefslogtreecommitdiffstats
path: root/js/savegame.js
blob: d5a9ba11fecffa6fa982e7b40f6ff9851adb2c83 (plain)
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
function listSaves() {
	sendRequest("craftmine.php", "op=listSaves", function(ret) {
		var tmphtml=""
		for(var i=0; i<ret.length; i++) {
			tmphtml += "<label class=\"radio\"><input name=\"saveRadio\" value=\"" + i + "\" type=\"radio\" />" + ret[i] + "</label>\n";
		}
		console.log(tmphtml);
		document.getElementById("listsaves").innerHTML = tmphtml;
	});
}

function getCheckedSave() {
	var radios = document.getElementsByName('saveRadio');
	for (var i = 0, length = radios.length; i < length; i++) {
		if (radios[i].checked) return radios[i].parentNode.textContent;
	}
	return -1;
}

function loadSave() {
	sendRequest("craftmine.php", "op=loadSave&filename="+getCheckedSave(), function(ret) {
		initCraftMine();
	});
}

function downloadSave() {
	var filename = getCheckedSave();
	if(filename == -1) downGame();
	else window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank");
}

function deleteSave() {
	sendRequest("craftmine.php", "op=deleteSave&filename="+getCheckedSave(), function(ret) {
		listSaves();
	});
}

function saveGame() {
	sendRequest("craftmine.php", "op=saveGame");
}

function downGame() {
	window.open("craftmine.php?op=downSave", "_blank");
}

function uploadSave() {
	var selectedFile = document.getElementById("selectedFile");
	if(selectedFile.files[0].size > 2000000) {
		showError("File is too big.");
		return;
	}

	var form = new FormData(); // Doesn't work with IE < 10 (and Opera Mini), but, as always, who cares?
	form.append("savefile", selectedFile.files[0]);

	sendRequest("upload.php", form, function(ret) {
		console.log(ret);
	}, true);
}