From 02c2b49b4a85704d7c16a91e55d24d5af64808ee Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 13:41:42 +0200 Subject: Add multiple item support to savegame + fix missing includes --- inc/Inventory.inc | 2 +- inc/Item.inc | 3 ++- 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 @@ 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]); -- cgit v1.2.3-54-g00ecf