aboutsummaryrefslogtreecommitdiffstats
path: root/js/savegame.js
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-09 22:06:30 +0200
committerpiernov <piernov@piernov.org>2016-05-09 22:06:30 +0200
commitf10c51f07a755d75a583f85316efbcd3bd1e4b6d (patch)
tree87419a11e12f5b7433459fcb5cb9da5211dcbd9e /js/savegame.js
parent54635d17eef27eb2546d69599e4107b242509ced (diff)
parent2f32bc3153b7f2c2561e4603f912573921e6449f (diff)
downloadcandybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.gz
candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.bz2
candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.xz
candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.zip
Merge branch 'alexichi' of ssh://piernov.org/srv/git/candybox into alexichi
Diffstat (limited to 'js/savegame.js')
-rw-r--r--js/savegame.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/js/savegame.js b/js/savegame.js
new file mode 100644
index 0000000..98d973b
--- /dev/null
+++ b/js/savegame.js
@@ -0,0 +1,66 @@
+function listSaves() {
+ sendRequest("craftmine.php", "op=listSaves", function(ret) {
+ var tmphtml=""
+ for(var i=0; i<ret.length; i++) {
+ tmphtml += "<div class=\"input-group\">";
+ tmphtml += "<span class=\"input-group-addon\">";
+ tmphtml += "<input name=\"saveRadio\" value=\"" + i + "\" type=\"radio\" />";
+ tmphtml += "</span>";
+ tmphtml += "<input class=\"form-control\" type=\"text\" value=\"" + ret[i] + "\" readonly=\"readonly\" />";
+
+ tmphtml += "</div>"
+ }
+ 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.parentNode.childNodes.item(1).value;
+ }
+ 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(ret) {
+ listSaves();
+ });
+}
+
+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) {
+ listSaves();
+ }, true);
+}