60 public function __construct(array $shape, array $ingredients, array $results){
61 $this->height = count($shape);
62 if($this->height > 3 || $this->height <= 0){
63 throw new \InvalidArgumentException(
"Shaped recipes may only have 1, 2 or 3 rows, not $this->height");
66 $shape = array_values($shape);
68 $this->width = strlen($shape[0]);
69 if($this->width > 3 || $this->width <= 0){
70 throw new \InvalidArgumentException(
"Shaped recipes may only have 1, 2 or 3 columns, not $this->width");
73 foreach($shape as $y => $row){
74 if(strlen($row) !== $this->width){
75 throw new \InvalidArgumentException(
"Shaped recipe rows must all have the same length (expected $this->width, got " . strlen($row) .
")");
78 for($x = 0; $x < $this->width; ++$x){
79 if($row[$x] !==
' ' && !isset($ingredients[$row[$x]])){
80 throw new \InvalidArgumentException(
"No item specified for symbol '" . $row[$x] .
"'");
85 $this->shape = $shape;
87 foreach($ingredients as $char => $i){
88 if(!str_contains(implode($this->shape), $char)){
89 throw new \InvalidArgumentException(
"Symbol '$char' does not appear in the recipe shape");
92 $this->ingredientList[$char] = clone $i;
95 $this->results = Utils::cloneObjectArray($results);