diff options
author | piernov <piernov@piernov.org> | 2016-05-09 14:05:50 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-09 14:05:50 +0200 |
commit | 1e52affe15fb13e920f8942de998073238be6d01 (patch) | |
tree | b0737eb2c9f26be6700f99d00d003e4cf6b05d7b /inc | |
parent | 9f28616dfd1cc425c5013937bab729217b7be2e6 (diff) | |
download | candybox-1e52affe15fb13e920f8942de998073238be6d01.tar.gz candybox-1e52affe15fb13e920f8942de998073238be6d01.tar.bz2 candybox-1e52affe15fb13e920f8942de998073238be6d01.tar.xz candybox-1e52affe15fb13e920f8942de998073238be6d01.zip |
Finish Inventory PHPDocphpdoc
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Inventory.inc | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 73d82c8..58cf709 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -8,9 +8,9 @@ * @author Pierre-Emmanuel Novac */ class Inventory { - /** - * Arrays of array with Item and Item's count - */ + /** + * @var array Arrays of array with Item object and Item's count as int + */ public $items = array(); /** @@ -74,6 +74,12 @@ class Inventory { return $tab; } + /** + * Removes an Item object from the Inventory, not taking into account the Item's count. + * + * @param Item $item Item to remove from the Inventory + * @return void + */ private function _removeItem($item) { foreach($this->items as $k => $object) { if($object[0] == $item) { @@ -83,11 +89,23 @@ class Inventory { } } + /** + * Removes an Item object to the singleton's Inventory from session, not taking into account the Item's count. + * + * @param Item $item Item to remove from the Inventory + * @return void + */ public static function removeItem($item) { $inv = self::get(); $inv->_removeItem($item); } + /** + * Consumes an Item object from the Inventory, decrementing the Item's count and removing it if count reaches 0. + * + * @param Item $item Item to consume from the Inventory + * @return array|false Item and updated Item's count, false if it was not found + */ private function _useItem($item) { foreach($this->items as $k => $object){ if($object[0] == $item) { @@ -103,12 +121,24 @@ class Inventory { return false; } + /** + * Consumes an Item object to the singleton's Inventory from session, decrementing the Item's count and removing it if count reaches 0. + * + * @param Item $item Item to consume from the Inventory + * @return array|false Item and updated Item's count, false if it was not found + */ public static function useItem($item) { $inv = self::get(); $it = $inv->_useItem($item); return $it; } + /** + * Generates an XML tree describing the Inventory + * + * @param SimpleXMLElement $root root XML element to add the Inventory's Items to + * @return void + */ public function addToXML($root) { foreach($this->items as $item) $item[0]->addToXML($root, $item[1]); |