4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 dragonblocks.Recipe = class{
25 if(! obj || ! obj.result || ! obj.recipe instanceof Array || ! obj.recipe[0] instanceof Array)
27 this.recipe = obj.recipe;
28 this.result = obj.result;
29 this.height = this.recipe.length;
30 this.width = this.recipe[0].length;
31 dragonblocks.recipes.push(this);
34 if(craftfield.width < this.width || craftfield.height < this.height)
36 for(let ydiff = 0; ydiff <= craftfield.height - this.height; ydiff++){
37 for(let xdiff = 0; xdiff <= craftfield.width - this.width; xdiff++){
39 for(let y = 0; y < craftfield.height; y++){
40 for(let x = 0; x < craftfield.width; x++){
41 if(! this.recipe[y - ydiff] || ! this.recipe[y - ydiff][x - xdiff]){
42 if(craftfield.list[y * craftfield.width + x].item)
45 else if(! dragonblocks.itemMatch(craftfield.list[y * craftfield.width + x].item, this.recipe[y - ydiff][x - xdiff]))
56 dragonblocks.recipes = [];
57 dragonblocks.registerRecipe = function(obj){
58 new dragonblocks.Recipe(obj);