diff options
author | piernov <piernov@piernov.org> | 2016-05-08 13:44:29 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-08 13:44:29 +0200 |
commit | 90e9e78500e09447cc3c26d129348eb3f0d2433d (patch) | |
tree | ae732ae51a8f7d1fab6f611b3a7e8ec287c3fae8 /inc | |
parent | 3795b462a30a1942f5ebac3105e72824acbd1a87 (diff) | |
parent | 2de30b863b6f78c10a1fed54d229dabea7383b97 (diff) | |
download | candybox-90e9e78500e09447cc3c26d129348eb3f0d2433d.tar.gz candybox-90e9e78500e09447cc3c26d129348eb3f0d2433d.tar.bz2 candybox-90e9e78500e09447cc3c26d129348eb3f0d2433d.tar.xz candybox-90e9e78500e09447cc3c26d129348eb3f0d2433d.zip |
Merge branch 'piernov' into alexichi
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Inventory.inc | 2 | ||||
-rw-r--r-- | inc/Item.inc | 3 | ||||
-rw-r--r-- | inc/savegame.inc | 7 |
3 files changed, 9 insertions, 3 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]); |