Read recipes from json

This commit is contained in:
Intyre
2016-01-25 20:40:26 +01:00
parent e2a400dd6b
commit c7c78b1159
3 changed files with 13726 additions and 672 deletions

View File

@ -42,32 +42,17 @@ class ShapedRecipe implements Recipe{
/**
* @param Item $result
* @param string[] $shape
* @param int $height
* @param int $width
*
* @throws \Exception
*/
public function __construct(Item $result, ...$shape){
if(count($shape) === 0){
throw new \InvalidArgumentException("Must provide a shape");
}
if(count($shape) > 3){
throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
}
foreach($shape as $y => $row){
if(strlen($row) === 0 or strlen($row) > 3){
public function __construct(Item $result, $height, $width){
for($h =0; $h < $height; $h++){
if(strlen($width) === 0 or strlen($width) > 3){
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row));
}
$this->ingredients[] = array_fill(0, strlen($row), null);
$len = strlen($row);
for($i = 0; $i < $len; ++$i){
$this->shape[$row{$i}] = null;
if(!isset($this->shapeItems[$row{$i}])){
$this->shapeItems[$row{$i}] = [new Vector2($i, $y)];
}else{
$this->shapeItems[$row{$i}][] = new Vector2($i, $y);
}
}
$this->ingredients[] = array_fill(0, $width, null);
}
$this->output = clone $result;
@ -97,6 +82,11 @@ class ShapedRecipe implements Recipe{
$this->id = $id;
}
public function addIngredient($x, $y, Item $item){
$this->ingredients[$y][$x] = clone $item;
return $this;
}
/**
* @param string $key
* @param Item $item