Prune invalid recipes
This commit is contained in:
@@ -57,6 +57,12 @@ module.exports = class CraftingNode
|
||||
leave = visitor['onLeaveOtherNode']
|
||||
if leave? then leave.call visitor, this
|
||||
|
||||
pruneInvalidChildren: ->
|
||||
@_pruneInvalidChildren()
|
||||
|
||||
removeChild: (index)->
|
||||
@_children.splice index, 1
|
||||
|
||||
rotateChildren: ->
|
||||
@_children.push @_children.shift()
|
||||
@_rotations += 1
|
||||
@@ -120,3 +126,9 @@ module.exports = class CraftingNode
|
||||
# explored for having a useful crafting plan.
|
||||
_checkValidity: ->
|
||||
throw new Error "#{@constructor.name} must override the _checkValidity method"
|
||||
|
||||
# Subclasses may override this method to remove any children determined to be invalid and therefore unable to be
|
||||
# of any use in finding legitimate crafting plans.
|
||||
_pruneInvalidChildren: ->
|
||||
for child in @children
|
||||
child.pruneInvalidChildren()
|
||||
|
||||
@@ -80,7 +80,9 @@ module.exports = class Craftsman extends BaseModel
|
||||
@stageCount = 0
|
||||
logger.warning => "Craftsman could not complete a crafting plan."
|
||||
else if not @_planBuilder?
|
||||
@_graphBuilder.pruneInvalidNodes()
|
||||
logger.debug => "Craftsman finished computing graph:\n#{@_graphBuilder.rootNode}"
|
||||
|
||||
@_planBuilder = new PlanBuilder @_graphBuilder.rootNode, @_modPack, have:@_have, want:@_want
|
||||
@stage = @STAGE.PLANNING
|
||||
@stageCount = 0
|
||||
|
||||
@@ -40,6 +40,9 @@ module.exports = class GraphBuilder
|
||||
node.expand @_queue
|
||||
@_stepCount += 1
|
||||
|
||||
pruneInvalidNodes: ->
|
||||
@_rootNode.pruneInvalidChildren()
|
||||
|
||||
reset: ->
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
@@ -74,6 +74,16 @@ module.exports = class ItemNode extends CraftingNode
|
||||
return true if child.valid
|
||||
return false
|
||||
|
||||
_pruneInvalidChildren: ->
|
||||
index = 0
|
||||
while index < @children.length
|
||||
child = @children[index]
|
||||
if child.valid
|
||||
child.pruneInvalidChildren()
|
||||
index++
|
||||
else
|
||||
@removeChild index
|
||||
|
||||
# Object Overrides #############################################################################
|
||||
|
||||
toString: (options={})->
|
||||
|
||||
Reference in New Issue
Block a user