aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Inventory.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Inventory.inc')
-rw-r--r--inc/Inventory.inc39
1 files changed, 37 insertions, 2 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 2be48f8..dd65ee5 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -1,17 +1,40 @@
<?php
-
+/**
+ * Represent the player's Inventory.
+ * Implemented as a singleton in the session.
+ *
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
class Inventory {
-
+ /**
+ * Arrays of array with Item and Item's count
+ */
public $items = array();
+ /**
+ * Checks if the Inventory was already created in the session
+ *
+ * @return boolean true if Inventory was already created, false otherwise
+ */
public static function created() {
return !empty($_SESSION["inventory"]);
}
+ /**
+ * Returns the Inventory's content from the session.
+ *
+ * @return array array of Items and number
public static function sendContent() {
return self::get()->items;
}
+ /**
+ * Returns the Inventory from the session.
+ * Implements the singleton pattern.
+ *
+ * @return Inventory the Inventory object
+ */
public static function get() {
if(!self::created()) {
$_SESSION["inventory"] = new Inventory();
@@ -19,6 +42,12 @@ class Inventory {
return $_SESSION["inventory"];
}
+ /**
+ * Adds an Item object to the Inventory, incrementing the Item's count if it was already present.
+ *
+ * @param Item $item Item to add to the Inventory
+ * @return array Item and Item's count
+ */
private function _addItem($item) {
foreach($this->items as $k => $object){
if($object[0] == $item){
@@ -31,6 +60,12 @@ class Inventory {
return $tab;
}
+ /**
+ * Adds an Item object to the singleton's Inventory from session.
+ *
+ * @param Item $item Item to add to the Inventory
+ * @return array Item and Item's count
+ */
public static function addItem($item) {
$inv = self::get();
$tab = $inv->_addItem($item);