aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-08 13:44:08 +0200
committerpiernov <piernov@piernov.org>2016-05-08 13:44:08 +0200
commit2de30b863b6f78c10a1fed54d229dabea7383b97 (patch)
treedcf6cf9077234d5130d5339663594442602a8dea
parentf52c46918efa0725affc490fd325977516be1870 (diff)
parent14ee8b1962fe3ce332e0de5fb96ae3f342187f94 (diff)
downloadcandybox-2de30b863b6f78c10a1fed54d229dabea7383b97.tar.gz
candybox-2de30b863b6f78c10a1fed54d229dabea7383b97.tar.bz2
candybox-2de30b863b6f78c10a1fed54d229dabea7383b97.tar.xz
candybox-2de30b863b6f78c10a1fed54d229dabea7383b97.zip
Merge branch 'feat/savegame' into piernov
-rw-r--r--inc/Inventory.inc2
-rw-r--r--inc/Item.inc3
-rw-r--r--inc/savegame.inc7
-rw-r--r--js/savegame.js9
4 files changed, 14 insertions, 7 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 747c4db..751f728 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -65,7 +65,7 @@ class Inventory {
public function addToXML($root) {
foreach($this->items as $item)
- $item->addToXML($root);
+ $item[0]->addToXML($root, $item[1]);
}
}
diff --git a/inc/Item.inc b/inc/Item.inc
index 8e90998..907872e 100644
--- a/inc/Item.inc
+++ b/inc/Item.inc
@@ -13,12 +13,13 @@ class Item {
$this->desc = $desc;
}
- function addToXML($root) {
+ function addToXML($root, $count) {
$item = $root->addChild("item");
$item->addChild("name", $this->name);
$item->addChild("cost", $this->cost);
$item->addChild("icon", $this->icon);
$item->addChild("desc", $this->desc);
+ $item->addChild("count", $count);
}
public static function fromXML($xml) {
diff --git a/inc/savegame.inc b/inc/savegame.inc
index 8772585..6d92af2 100644
--- a/inc/savegame.inc
+++ b/inc/savegame.inc
@@ -1,6 +1,8 @@
<?php
require_once("inc/messages.inc");
+require_once("inc/Inventory.inc");
+require_once("inc/Item.inc");
define("SAVEDIR", "data/save");
@@ -63,7 +65,10 @@ function parseSave($xml, &$table) { // Passing $table by reference
if(is_numeric($v)) $v = +$v; // If it is in fact a number, treat it that way using PHP unary '+' coercion
$table[$k] = $v;
} elseif($k == "inventory") { // Special case for inventory: objects need to be created
- foreach($v as $item) Inventory::addItem(Item::fromXML($item));
+ foreach($v as $item) {
+ for($i=0; $i<+$item->count; $i++) // Add the right count of items to Inventory
+ Inventory::addItem(Item::fromXML($item));
+ }
} else { // If nested array
$table[$k] = array();
parseSave($v, $table[$k]);
diff --git a/js/savegame.js b/js/savegame.js
index c069b5c..98d973b 100644
--- a/js/savegame.js
+++ b/js/savegame.js
@@ -10,7 +10,6 @@ function listSaves() {
tmphtml += "</div>"
}
- console.log(tmphtml);
document.getElementById("listsaves").innerHTML = tmphtml;
});
}
@@ -18,7 +17,7 @@ function listSaves() {
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;
+ if (radios[i].checked) return radios[i].parentNode.parentNode.childNodes.item(1).value;
}
return -1;
}
@@ -42,7 +41,9 @@ function deleteSave() {
}
function saveGame() {
- sendRequest("craftmine.php", "op=saveGame");
+ sendRequest("craftmine.php", "op=saveGame", function(ret) {
+ listSaves();
+ });
}
function downGame() {
@@ -60,6 +61,6 @@ function uploadSave() {
form.append("savefile", selectedFile.files[0]);
sendRequest("upload.php", form, function(ret) {
- console.log(ret);
+ listSaves();
}, true);
}