wip
This commit is contained in:
@@ -32,45 +32,39 @@ module.exports = class CraftPageController extends PageController
|
||||
@modPack = options.modPack
|
||||
@storage = options.storage
|
||||
|
||||
@model.plan.on Event.change, => @tryRefresh()
|
||||
@model.craftsman.on Event.change, => @tryRefresh()
|
||||
|
||||
# Event Methods ################################################################################
|
||||
|
||||
onCraftTool: (itemSlug)->
|
||||
# TODO: implement this
|
||||
|
||||
onHaveInventoryChanged: ->
|
||||
@storage.store 'crafting-plan:have', @model.plan.have.unparse()
|
||||
@storage.store 'crafting-plan:have', @model.craftsman.have.unparse()
|
||||
|
||||
onMoveNeedToHave: (itemSlug)->
|
||||
quantity = @model.plan.need.quantityOf itemSlug
|
||||
@model.plan.have.add itemSlug, quantity
|
||||
quantity = @model.craftsman.need.quantityOf itemSlug
|
||||
@model.craftsman.have.add itemSlug, quantity
|
||||
@onHaveInventoryChanged()
|
||||
|
||||
onRemoveFromHaveInventory: (itemSlug)->
|
||||
@model.plan.have.remove itemSlug
|
||||
@model.craftsman.have.remove itemSlug
|
||||
@onHaveInventoryChanged()
|
||||
|
||||
onRemoveFromWant: (itemSlug)->
|
||||
@model.plan.want.remove itemSlug
|
||||
@model.craftsman.want.remove itemSlug
|
||||
@onWantInventoryChange()
|
||||
|
||||
onStopUsingTool: (itemSlug)->
|
||||
# TODO: implement this
|
||||
|
||||
onStepComplete: (stepController)->
|
||||
step = stepController.model
|
||||
for stack in step.recipe.output
|
||||
@model.plan.have.add stack.itemSlug, stack.quantity * step.multiplier
|
||||
@model.craftsman.have.add stack.itemSlug, stack.quantity * step.multiplier
|
||||
@onHaveInventoryChanged()
|
||||
|
||||
onWantInventoryChange: ->
|
||||
text = @model.plan.want.unparse()
|
||||
text = @model.craftsman.want.unparse()
|
||||
url = Url.crafting inventoryText:text
|
||||
router.navigate url
|
||||
|
||||
if @model.plan.want.isEmpty
|
||||
@model.plan.have.clear()
|
||||
if @model.craftsman.want.isEmpty
|
||||
@model.craftsman.have.clear()
|
||||
@onHaveInventoryChanged()
|
||||
|
||||
# PageController Overrides #####################################################################
|
||||
@@ -89,24 +83,15 @@ module.exports = class CraftPageController extends PageController
|
||||
@wantInventoryController = @addChild InventoryController, '.want .view__inventory',
|
||||
imageLoader: @imageLoader
|
||||
isAcceptable: (item)=> item.isCraftable
|
||||
model: @model.plan.want
|
||||
model: @model.craftsman.want
|
||||
modPack: @modPack
|
||||
firstButtonType: 'remove'
|
||||
@wantInventoryController.on Event.button.first, (c, s)=> @onRemoveFromWant(s)
|
||||
@wantInventoryController.on Event.change, (c)=> @onWantInventoryChange()
|
||||
|
||||
# @toolsInUseController = @addChild InventoryController, '.tools .view__inventory',
|
||||
# imageLoader: @imageLoader
|
||||
# model: @model.plan.toolsInUse
|
||||
# modPack: @modPack
|
||||
# firstButtonType: 'down'
|
||||
# secondButtonType: 'up'
|
||||
# @toolsInUseController.on Event.button.first, (c, s)=> @onStopUsingTool(s)
|
||||
# @toolsInUseController.of Event.button.second, (c, s)=> @onCraftTool(s)
|
||||
|
||||
@haveInventoryController = @addChild InventoryController, '.have .view__inventory',
|
||||
imageLoader: @imageLoader
|
||||
model: @model.plan.have
|
||||
model: @model.craftsman.have
|
||||
modPack: @modPack
|
||||
firstButtonType: 'down'
|
||||
@haveInventoryController.on Event.button.first, (c, s)=>
|
||||
@@ -116,7 +101,7 @@ module.exports = class CraftPageController extends PageController
|
||||
@needInventoryController = @addChild InventoryController, '.need .view__inventory',
|
||||
editable: false
|
||||
imageLoader: @imageLoader
|
||||
model: @model.plan.need
|
||||
model: null
|
||||
modPack: @modPack
|
||||
firstButtonType: 'up'
|
||||
@needInventoryController.on Event.button.first, (c, s)=> @onMoveNeedToHave(s)
|
||||
@@ -131,11 +116,12 @@ module.exports = class CraftPageController extends PageController
|
||||
super
|
||||
|
||||
onWillRender: ->
|
||||
@model.plan.have.clear()
|
||||
@model.plan.have.parse @storage.load('crafting-plan:have')
|
||||
@model.craftsman.have.clear()
|
||||
@model.craftsman.have.parse @storage.load('crafting-plan:have')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@needInventoryController.model = @model.craftsman.plan?.need
|
||||
@_refreshSectionVisibility()
|
||||
@_refreshSteps()
|
||||
@adsenseController.fillAdPositions()
|
||||
@@ -150,10 +136,10 @@ module.exports = class CraftPageController extends PageController
|
||||
# Private Methods ################################################################################
|
||||
|
||||
_isStepCompletable: (controller)->
|
||||
return not @model.plan.want.hasAtLeast controller.model.outputItemSlug
|
||||
return not @model.craftsman.want.hasAtLeast controller.model.outputItemSlug
|
||||
|
||||
_refreshSectionVisibility: ->
|
||||
if @model.plan.want.isEmpty
|
||||
if @model.craftsman.want.isEmpty
|
||||
for $el in [@$toolsSection, @$ingredientsSection, @$stepsSection]
|
||||
@hide $el
|
||||
@show @$instructionsSection
|
||||
@@ -163,10 +149,11 @@ module.exports = class CraftPageController extends PageController
|
||||
@hide @$instructionsSection
|
||||
|
||||
_refreshSteps: ->
|
||||
steps = @model.craftsman.plan?.steps or []
|
||||
@_stepControllers ?= []
|
||||
index = 0
|
||||
|
||||
for step in @model.plan.steps
|
||||
for step in steps
|
||||
controller = @_stepControllers[index]
|
||||
if not controller?
|
||||
controller = new StepController
|
||||
|
||||
Reference in New Issue
Block a user