From 818a88625577b4422f82af6fda3718b43b84fb6d Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 15:09:55 +0200 Subject: Items feature support on save/load game --- inc/Item.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/Item.inc b/inc/Item.inc index f01b709..8eebbf8 100644 --- a/inc/Item.inc +++ b/inc/Item.inc @@ -32,11 +32,18 @@ class Item { $item->addChild("cost", $this->cost); $item->addChild("icon", $this->icon); $item->addChild("desc", $this->desc); + $xmlfeat = $item->addChild("feat"); + foreach($this->feat as $k => $v) + $xmlfeat->addChild($k, $v); $item->addChild("count", $count); } public static function fromXML($xml) { - return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc); + $feats = array(); + foreach($xml->feat[0] as $k => $v) + $feats[(string)$k] = (string)$v; + + return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc, $feats); } } -- cgit v1.2.3-54-g00ecf