73 public function __construct(array $shape, array $ingredients, array $results){
74 $this->height = count($shape);
75 if($this->height > 3 || $this->height <= 0){
76 throw new \InvalidArgumentException(
"Shaped recipes may only have 1, 2 or 3 rows, not $this->height");
79 $shape = array_values($shape);
81 $this->width = strlen($shape[0]);
82 if($this->width > 3 || $this->width <= 0){
83 throw new \InvalidArgumentException(
"Shaped recipes may only have 1, 2 or 3 columns, not $this->width");
86 foreach($shape as $y => $row){
87 if(strlen($row) !== $this->width){
88 throw new \InvalidArgumentException(
"Shaped recipe rows must all have the same length (expected $this->width, got " . strlen($row) .
")");
91 for($x = 0; $x < $this->width; ++$x){
92 if($row[$x] !==
' ' && !isset($ingredients[$row[$x]])){
93 throw new \InvalidArgumentException(
"No item specified for symbol '" . $row[$x] .
"'");
98 $this->shape = $shape;
100 foreach(Utils::stringifyKeys($ingredients) as $char => $i){
101 if(!str_contains(implode($this->shape), $char)){
102 throw new \InvalidArgumentException(
"Symbol '$char' does not appear in the recipe shape");
105 $this->ingredientList[$char] = clone $i;
108 $this->results = Utils::cloneObjectArray($results);