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