From f5681a84aa1002d0e6ca6b1ac1924a3871eb0e63 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Sat, 10 Jan 2015 02:16:38 -0800 Subject: [PATCH] Fix default patterns to not be recorded --- src/data/thermal_expansion/recipes.json | 2 +- src/scripts/constants.coffee | 2 +- src/scripts/models/item.coffee | 2 + src/scripts/models/mod_version_parser.coffee | 2 +- src/scripts/models/recipe.coffee | 46 ++++++++++++++------ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/data/thermal_expansion/recipes.json b/src/data/thermal_expansion/recipes.json index 47ddb09d3..f9395df7c 100644 --- a/src/data/thermal_expansion/recipes.json +++ b/src/data/thermal_expansion/recipes.json @@ -176,7 +176,7 @@ "tools": "Crafting Table" }, { "output": "Sawmill", - "input": [[2, "Copper Ingot"], [2, "Oak Plank"], "Iron Axe", "Machine Frame", "Redstone Reception Coil"], + "input": [[2, "Copper Ingot"], [2, "Oak Wood Planks], "Iron Axe", "Machine Frame", "Redstone Reception Coil"], "tools": "Crafting Table" }, { "output": "Schematic", diff --git a/src/scripts/constants.coffee b/src/scripts/constants.coffee index 3ff229006..bc60781dd 100644 --- a/src/scripts/constants.coffee +++ b/src/scripts/constants.coffee @@ -8,11 +8,11 @@ All rights reserved. exports.DefaultBookUrls = DefaultBookUrls = [ '/data/minecraft/recipes.json' '/data/buildcraft/recipes.json' + '/data/ic2_classic/recipes.json' # Disabled until shaped crafting can be added -- aminer 2015-01-09 # '/data/applied_energetics/recipes.json' # '/data/gravisuite/recipes.json' - # '/data/industrial_craft/recipes.json' # '/data/more_blocks/recipes.json' # '/data/thermal_expansion/recipes.json' ] diff --git a/src/scripts/models/item.coffee b/src/scripts/models/item.coffee index 1216ff91b..3d841c243 100644 --- a/src/scripts/models/item.coffee +++ b/src/scripts/models/item.coffee @@ -34,6 +34,8 @@ module.exports = class Item extends BaseModel @recipes.push recipe compareTo: (that)-> + if this.slug isnt that.slug + return if this.slug < that.slug then -1 else +1 if this.name isnt that.name return if this.name < that.name then -1 else +1 return 0 diff --git a/src/scripts/models/mod_version_parser.coffee b/src/scripts/models/mod_version_parser.coffee index 3be60ec38..0d3e16fa3 100644 --- a/src/scripts/models/mod_version_parser.coffee +++ b/src/scripts/models/mod_version_parser.coffee @@ -203,7 +203,7 @@ module.exports.V1 = class V1 result.push ' "input": ' @_unparseStackList recipe.input, result - if recipe.pattern is recipe._computeShapelessPattern(recipe.input) + if recipe.pattern? result.push ',\n' result.push ' "pattern": "' result.push recipe.pattern diff --git a/src/scripts/models/recipe.coffee b/src/scripts/models/recipe.coffee index 11f79c993..a882e1f40 100644 --- a/src/scripts/models/recipe.coffee +++ b/src/scripts/models/recipe.coffee @@ -16,7 +16,7 @@ module.exports = class Recipe extends BaseModel if not attributes.input? then throw new Error 'attributes.input is required' if not attributes.output? then throw new Error 'attributes.output is required' - attributes.pattern = @_parsePattern attributes.pattern, attributes.input + attributes.pattern = @_parsePattern attributes.pattern attributes.tools ?= [] super attributes, options @@ -25,8 +25,10 @@ module.exports = class Recipe extends BaseModel # Public Methods ############################################################################### getItemSlugAt: (index)-> + pattern = if @pattern? then @pattern else @_computeDefaultPattern() + trueIndex = 0:0, 1:1, 2:2, 3:4, 4:5, 5:6, 6:8, 7:9, 8:10 - patternDigit = @pattern[trueIndex[index]] + patternDigit = pattern[trueIndex[index]] return null unless patternDigit? return null unless patternDigit.match /[0-9]/ @@ -85,24 +87,40 @@ module.exports = class Recipe extends BaseModel # Private Methods ############################################################################## - _parsePattern: (pattern, input)-> - pattern ?= '' + _parsePattern: (pattern)-> + return unless pattern? + pattern = pattern.replace /\ /g, '' + return if pattern.length is 0 - if pattern.length > 0 - pattern = pattern.replace /[^0-9]/g, '.' - else - pattern = @_computeShapelessPattern input + pattern = pattern.replace /[^0-9]/g, '.' + array = pattern.split '' + array = array[0...9] + while array.length isnt 9 + array.push '.' + + pattern = array.join '' pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3' return pattern - _computeShapelessPattern: (input)-> - result = '728506314' + _computeDefaultPattern: -> + itemCount = @input.length + slotCount = _.reduce @input, ((total, stack)-> total + stack.quantity), 0 - total = _.reduce input, ((total, stack)-> total + stack.quantity), 0 + return '... .0. ...' if itemCount is 1 and slotCount is 1 + return '00. 00. ...' if itemCount is 1 and slotCount is 4 + return '000 000 000' if itemCount is 1 and slotCount is 9 - for i in [total...9] - result = result.replace "#{i}", '.' + result = ['.', '.', '.', '.', '.', '.', '.', '.', '.'] + indexes = [4, 7, 1, 3, 5, 6, 8, 0, 2] - return result + for i in [0...@input.length] + stack = @input[i] + for j in [0...stack.quantity] + index = indexes.shift() + result[index] = "#{i}" + + pattern = result.join '' + pattern = pattern.replace /(...)(...)(...)/, '$1 $2 $3' + return pattern