Inventory: Added includeEmpty parameter to getContents()

This commit is contained in:
Dylan K. Taylor
2018-01-22 21:08:40 +00:00
parent 2fb580db26
commit 1de7c5b114
3 changed files with 15 additions and 12 deletions

View File

@ -93,10 +93,20 @@ abstract class BaseInventory implements Inventory{
}
/**
* @param bool $includeEmpty
*
* @return Item[]
*/
public function getContents() : array{
return array_filter($this->slots->toArray(), function(Item $item = null){ return $item !== null; });
public function getContents(bool $includeEmpty = false) : array{
$contents = [];
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
$item = $this->getItem($i);
if($includeEmpty or !$item->isNull()){
$contents[$i] = $item;
}
}
return $contents;
}
/**