Recipe component can show multiblock recipes
This commit is contained in:
@@ -48,11 +48,8 @@ module.exports = class ItemPage extends Observable
|
|||||||
return @_findItemsWithMatchingRecipes (recipe)=>
|
return @_findItemsWithMatchingRecipes (recipe)=>
|
||||||
recipe.computeQuantityRequired @item
|
recipe.computeQuantityRequired @item
|
||||||
|
|
||||||
findMultiblockRecipes: ->
|
|
||||||
return (recipe for recipeId, recipe of @item.recipes when recipes.depth > 1)
|
|
||||||
|
|
||||||
findRecipes: ->
|
findRecipes: ->
|
||||||
return (recipe for recipeId, recipe of @item.recipes when recipe.depth is 1)
|
return (recipe for recipeId, recipe of @item.recipes)
|
||||||
|
|
||||||
findSimilarItems: ->
|
findSimilarItems: ->
|
||||||
group = @mod.itemGroups[@item.groupName]
|
group = @mod.itemGroups[@item.groupName]
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
#
|
||||||
|
# Crafting Guide - recipe_display.coffee
|
||||||
|
#
|
||||||
|
# Copyright © 2014-2017 by Redwood Labs
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
|
||||||
|
_ = require "../../../common/underscore"
|
||||||
|
c = require "../../../common/constants"
|
||||||
|
{Inventory} = require("crafting-guide-common").models
|
||||||
|
{Observable} = require("crafting-guide-common").util
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
|
||||||
|
module.exports = class RecipeDisplay extends Observable
|
||||||
|
|
||||||
|
constructor: (options={})->
|
||||||
|
if not options.recipe? then throw new Error "options.recipe is required"
|
||||||
|
options.multiplier ?= 1
|
||||||
|
super
|
||||||
|
|
||||||
|
@_layerInventories = []
|
||||||
|
|
||||||
|
@recipe = options.recipe
|
||||||
|
@multiplier = options.multiplier
|
||||||
|
|
||||||
|
# Class Methods ################################################################################
|
||||||
|
|
||||||
|
@::RECIPE_TYPE =
|
||||||
|
CRAFTING_TABLE: "crafting_table"
|
||||||
|
MULTIBLOCK: "multiblock"
|
||||||
|
|
||||||
|
@::ALL_RECIPE_TYPES = (value for key, value of @::RECIPE_TYPE)
|
||||||
|
|
||||||
|
# Properties ###################################################################################
|
||||||
|
|
||||||
|
Object.defineProperties @prototype,
|
||||||
|
|
||||||
|
depth:
|
||||||
|
get: -> return @recipe.depth
|
||||||
|
set: -> throw new Error "depth cannot be assigned"
|
||||||
|
|
||||||
|
height:
|
||||||
|
get: -> return @recipe.height
|
||||||
|
set: -> throw new Error "height cannot be assigned"
|
||||||
|
|
||||||
|
multiplier:
|
||||||
|
get: -> return @_multiplier
|
||||||
|
set: (multiplier)->
|
||||||
|
if not _.isNumber(multiplier) then multiplier = 1
|
||||||
|
@triggerPropertyChange "multiplier", @_multiplier, multiplier
|
||||||
|
|
||||||
|
recipe:
|
||||||
|
get: -> return @_recipe
|
||||||
|
set: (recipe)->
|
||||||
|
return if recipe is @_recipe
|
||||||
|
if not recipe? then throw new Error "recipe is required"
|
||||||
|
if @_recipe? then throw new Error "recipe cannot be reassigned"
|
||||||
|
@_recipe = recipe
|
||||||
|
@_computeType()
|
||||||
|
|
||||||
|
tools:
|
||||||
|
get: -> return @recipe.tools
|
||||||
|
set: -> throw new Error "tools cannot be assigned"
|
||||||
|
|
||||||
|
type:
|
||||||
|
get: -> return @_type
|
||||||
|
set: -> throw new Error "type cannot be assigned"
|
||||||
|
|
||||||
|
width:
|
||||||
|
get: -> return @recipe.width
|
||||||
|
set: -> throw new Error "width cannot be assigned"
|
||||||
|
|
||||||
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
|
getInputAt: (x, y, z)->
|
||||||
|
return @recipe.getInputAt x, y, z
|
||||||
|
|
||||||
|
getInventory: (z)->
|
||||||
|
if not z?
|
||||||
|
return @_fullInventory ?= @_createFullInventory()
|
||||||
|
else
|
||||||
|
return @_layerInventories[z] ?= @_addLayerInventory z
|
||||||
|
|
||||||
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
|
_addLayerInventory: (z, inventory=null)->
|
||||||
|
inventory ?= new Inventory
|
||||||
|
for x in [0..@recipe.width]
|
||||||
|
for y in [0..@recipe.height]
|
||||||
|
stack = @recipe.getInputAt x, y, z
|
||||||
|
continue unless stack?
|
||||||
|
inventory.add stack.item, stack.quantity
|
||||||
|
return inventory
|
||||||
|
|
||||||
|
_computeType: ->
|
||||||
|
if not @recipe?
|
||||||
|
type = null
|
||||||
|
else if @recipe.depth > 1
|
||||||
|
type = @RECIPE_TYPE.MULTIBLOCK
|
||||||
|
else
|
||||||
|
type = @RECIPE_TYPE.CRAFTING_TABLE
|
||||||
|
@triggerPropertyChange "type", @_type, type
|
||||||
|
|
||||||
|
_createFullInventory: (inventory=null)->
|
||||||
|
inventory ?= new Inventory()
|
||||||
|
for z in [0..@recipe.depth]
|
||||||
|
@_addLayerInventory z, inventory
|
||||||
|
return inventory
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
BaseController = require "../../../base_controller"
|
BaseController = require "../../../base_controller"
|
||||||
CraftingGridController = require "../../crafting_grid/crafting_grid_controller"
|
CraftingGridController = require "../../crafting_grid/crafting_grid_controller"
|
||||||
ItemDisplay = require "../../../../models/site/item_display"
|
ItemDisplay = require "../../../../models/site/item_display"
|
||||||
|
RecipeDisplay = require "../../../../models/site/recipe_display"
|
||||||
SlotController = require "../../slot/slot_controller"
|
SlotController = require "../../slot/slot_controller"
|
||||||
{StringBuilder} = require("crafting-guide-common").util
|
{StringBuilder} = require("crafting-guide-common").util
|
||||||
|
|
||||||
@@ -24,21 +25,14 @@ module.exports = class CraftingTableController extends BaseController
|
|||||||
|
|
||||||
@_imageLoader = options.imageLoader
|
@_imageLoader = options.imageLoader
|
||||||
@_modPack = options.modPack
|
@_modPack = options.modPack
|
||||||
@_multiplier = options.multiplier
|
|
||||||
@_router = options.router
|
@_router = options.router
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@_gridController = @addChild CraftingGridController, ".view__crafting_grid",
|
options = modPack:@_modPack, imageLoader:@_imageLoader, router:@_router
|
||||||
modPack: @_modPack
|
@_gridController = @addChild CraftingGridController, ".view__crafting_grid", options
|
||||||
imageLoader: @_imageLoader
|
@_outputSlotController = @addChild SlotController, ".output .view__slot", options
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@_outputSlotController = @addChild SlotController, ".output .view__slot",
|
|
||||||
imageLoader: @_imageLoader
|
|
||||||
modPack: @_modPack
|
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@$multiplier = @$(".multiplier")
|
@$multiplier = @$(".multiplier")
|
||||||
@$outputImg = @$(".output img")
|
@$outputImg = @$(".output img")
|
||||||
@@ -47,32 +41,19 @@ module.exports = class CraftingTableController extends BaseController
|
|||||||
@$toolContainer = @$(".tool")
|
@$toolContainer = @$(".tool")
|
||||||
super
|
super
|
||||||
|
|
||||||
|
onWillChangeModel: (oldModel, newModel)->
|
||||||
|
if not newModel? then throw new Error "model is required"
|
||||||
|
if newModel.constructor isnt RecipeDisplay then throw new Error "model must be a RecipeDisplay"
|
||||||
|
return super oldModel, newModel
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
@_gridController.model = @model
|
@_gridController.model = @model.recipe
|
||||||
@_outputSlotController.model = @model?.output
|
@_outputSlotController.model = @model?.recipe.output
|
||||||
|
|
||||||
@_refreshMultiplier()
|
@_refreshMultiplier()
|
||||||
@_refreshTools()
|
@_refreshTools()
|
||||||
super
|
super
|
||||||
|
|
||||||
# Property Methods #############################################################################
|
|
||||||
|
|
||||||
Object.defineProperties @prototype,
|
|
||||||
multiplier:
|
|
||||||
get: ->
|
|
||||||
@_multiplier ?= 1
|
|
||||||
return @_multiplier
|
|
||||||
|
|
||||||
set: (newMultiplier)->
|
|
||||||
oldMultiplier = @_multiplier
|
|
||||||
return if newMultiplier is oldMultiplier
|
|
||||||
|
|
||||||
@_multiplier = newMultiplier
|
|
||||||
@_refreshMultiplier()
|
|
||||||
|
|
||||||
@trigger "change:multiplier", this, oldMultiplier, newMultiplier
|
|
||||||
@trigger "change", this
|
|
||||||
|
|
||||||
# Backbone.View Methods ########################################################################
|
# Backbone.View Methods ########################################################################
|
||||||
|
|
||||||
events: ->
|
events: ->
|
||||||
@@ -82,8 +63,8 @@ module.exports = class CraftingTableController extends BaseController
|
|||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_refreshMultiplier: ->
|
_refreshMultiplier: ->
|
||||||
if @multiplier > 1
|
if @model.multiplier > 1
|
||||||
@$multiplier.html "x#{@multiplier}"
|
@$multiplier.html "x#{@model.multiplier}"
|
||||||
else
|
else
|
||||||
@$multiplier.html ""
|
@$multiplier.html ""
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -5,8 +5,8 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
BaseController = require "../../../base_controller"
|
BaseController = require "../../../../base_controller"
|
||||||
ItemDisplay = require "../../../../models/site/item_display"
|
ItemDisplay = require "../../../../../models/site/item_display"
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ module.exports = class MultiblockController extends BaseController
|
|||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
if not options.imageLoader? then throw new Error "options.imageLoader is required"
|
if not options.imageLoader? then throw new Error "options.imageLoader is required"
|
||||||
if not options.modPack? then throw new Error "options.modPack is required"
|
if not options.modPack? then throw new Error "options.modPack is required"
|
||||||
options.templateName = "item_page/multiblock_viewer/multiblock"
|
options.templateName = "common/recipe/multiblock_viewer/multiblock"
|
||||||
super options
|
super options
|
||||||
|
|
||||||
@_currentLayer = 0
|
@_currentLayer = 0
|
||||||
+16
-24
@@ -5,10 +5,10 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
BaseController = require "../../base_controller"
|
BaseController = require "../../../base_controller"
|
||||||
InventoryController = require "../../common/inventory/inventory_controller"
|
InventoryController = require "../../inventory/inventory_controller"
|
||||||
MultiblockController = require "./multiblock/multiblock_controller"
|
MultiblockController = require "./multiblock/multiblock_controller"
|
||||||
MultiblockDisplay = require "../../../models/site/multiblock_display"
|
RecipeDisplay = require "../../../../models/site/recipe_display"
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ module.exports = class MultiblockViewerController extends BaseController
|
|||||||
if not options.imageLoader? then throw new Error "options.imageLoader is required"
|
if not options.imageLoader? then throw new Error "options.imageLoader is required"
|
||||||
if not options.modPack? then throw new Error "options.modPack is required"
|
if not options.modPack? then throw new Error "options.modPack is required"
|
||||||
if not options.router? then throw new Error "options.router is required"
|
if not options.router? then throw new Error "options.router is required"
|
||||||
options.templateName = "item_page/multiblock_viewer"
|
options.templateName = "common/recipe/multiblock_viewer"
|
||||||
super options
|
super options
|
||||||
|
|
||||||
@_imageLoader = options.imageLoader
|
@_imageLoader = options.imageLoader
|
||||||
@@ -51,22 +51,14 @@ module.exports = class MultiblockViewerController extends BaseController
|
|||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@completeInventoryController = @addChild InventoryController, ".view__inventory.complete",
|
baseOptions = imageLoader:@_imageLoader, modPack:@_modPack, router:@_router
|
||||||
editable: false
|
|
||||||
imageLoader: @_imageLoader
|
|
||||||
modPack: @_modPack
|
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@layerInventoryController = @addChild InventoryController, ".view__inventory.layer",
|
options = _.extend {editable:false}, baseOptions
|
||||||
editable: false
|
@completeInventoryController = @addChild InventoryController, ".view__inventory.complete", options
|
||||||
imageLoader: @_imageLoader
|
@layerInventoryController = @addChild InventoryController, ".view__inventory.layer", options
|
||||||
modPack: @_modPack
|
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@multiblockController = @addChild MultiblockController, ".view__multiblock",
|
options = _.extend {onHovering:(itemDisplay)=> @onBlockHovered(itemDisplay)}, baseOptions
|
||||||
imageLoader: @_imageLoader
|
@multiblockController = @addChild MultiblockController, ".view__multiblock", options
|
||||||
modPack: @_modPack
|
|
||||||
onHovering: (itemDisplay)=> @onBlockHovered(itemDisplay)
|
|
||||||
|
|
||||||
@$backButton = @$(".button.back")
|
@$backButton = @$(".button.back")
|
||||||
@$nextButton = @$(".button.next")
|
@$nextButton = @$(".button.next")
|
||||||
@@ -75,14 +67,14 @@ module.exports = class MultiblockViewerController extends BaseController
|
|||||||
super
|
super
|
||||||
|
|
||||||
onWillChangeModel: (oldModel, newModel)->
|
onWillChangeModel: (oldModel, newModel)->
|
||||||
@_display = new MultiblockDisplay newModel
|
if not newModel? then throw new Error "model is required"
|
||||||
super oldModel, newModel
|
if newModel.constructor isnt RecipeDisplay then throw new Error "model must be a RecipeDisplay"
|
||||||
|
return super oldModel, newModel
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
if @model? and @_display?
|
@completeInventoryController.model = @model.getInventory()
|
||||||
@completeInventoryController.model = @_display.getInventory()
|
@layerInventoryController.model = @model.getInventory @multiblockController.currentLayer
|
||||||
@layerInventoryController.model = @_display.getInventory @multiblockController.currentLayer
|
@multiblockController.model = @model
|
||||||
@multiblockController.model = @model
|
|
||||||
|
|
||||||
if @multiblockController.hasBackLayer()
|
if @multiblockController.hasBackLayer()
|
||||||
@$backButton.removeClass "disabled"
|
@$backButton.removeClass "disabled"
|
||||||
@@ -5,8 +5,10 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
BaseController = require "../../base_controller"
|
BaseController = require "../../base_controller"
|
||||||
CraftingTableController = require "./crafting_table/crafting_table_controller"
|
CraftingTableController = require "./crafting_table/crafting_table_controller"
|
||||||
|
MultiblockViewerController = require "./multiblock_viewer/multiblock_viewer_controller"
|
||||||
|
RecipeDisplay = require "../../../models/site/recipe_display"
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -21,73 +23,38 @@ module.exports = class RecipeController extends BaseController
|
|||||||
|
|
||||||
@_imageLoader = options.imageLoader
|
@_imageLoader = options.imageLoader
|
||||||
@_modPack = options.modPack
|
@_modPack = options.modPack
|
||||||
@_multiplier = options.multiplier
|
|
||||||
@_router = options.router
|
@_router = options.router
|
||||||
|
|
||||||
# Class Members ################################################################################
|
|
||||||
|
|
||||||
@::RECIPE_TYPE =
|
|
||||||
CRAFTING_TABLE:
|
|
||||||
css: "crafting_table"
|
|
||||||
Controller: CraftingTableController
|
|
||||||
|
|
||||||
@::ALL_RECIPE_TYPES = (value for key, value of @::RECIPE_TYPE)
|
|
||||||
|
|
||||||
# Properties ###################################################################################
|
|
||||||
|
|
||||||
Object.defineProperties @prototype,
|
|
||||||
multiplier:
|
|
||||||
get: ->
|
|
||||||
@_multiplier ?= 1
|
|
||||||
return @_multiplier
|
|
||||||
|
|
||||||
set: (newMultiplier)->
|
|
||||||
oldMultiplier = @_multiplier
|
|
||||||
return if newMultiplier is oldMultiplier
|
|
||||||
|
|
||||||
@_multiplier = newMultiplier
|
|
||||||
|
|
||||||
@trigger "change:multiplier", this, oldMultiplier, newMultiplier
|
|
||||||
@trigger "change", this
|
|
||||||
|
|
||||||
recipeType:
|
|
||||||
get: -> return @_recipeType
|
|
||||||
set: -> throw new Error "recipeType cannot be assigned"
|
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onWillChangeModel: (oldModel, newModel)->
|
onWillChangeModel: (oldModel, newModel)->
|
||||||
@_recomputeRecipeType(newModel)
|
if not newModel? then throw new Error "model is required"
|
||||||
|
if newModel.constructor isnt RecipeDisplay then throw new Error "model must be a RecipeDisplay"
|
||||||
return super oldModel, newModel
|
return super oldModel, newModel
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
|
return unless @model?
|
||||||
@_refreshRecipeType()
|
@_refreshRecipeType()
|
||||||
|
super
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_recomputeRecipeType: (recipe)->
|
_lookupControllerFor: (recipeType)->
|
||||||
oldRecipeType = @_recipeType
|
if recipeType is RecipeDisplay::RECIPE_TYPE.CRAFTING_TABLE then return CraftingTableController
|
||||||
|
if recipeType is RecipeDisplay::RECIPE_TYPE.MULTIBLOCK then return MultiblockViewerController
|
||||||
if not recipe?
|
|
||||||
newRecipeType = null
|
|
||||||
else
|
|
||||||
newRecipeType = @RECIPE_TYPE.CRAFTING_TABLE
|
|
||||||
|
|
||||||
return unless newRecipeType isnt oldRecipeType
|
|
||||||
|
|
||||||
@_recipeType = newRecipeType
|
|
||||||
@trigger "change:recipeType", this, oldRecipeType, newRecipeType
|
|
||||||
|
|
||||||
_refreshRecipeType: ->
|
_refreshRecipeType: ->
|
||||||
return if @_renderedRecipeType is @recipeType
|
return if @_renderedRecipeType is @model.type
|
||||||
@_renderedRecipeType = @recipeType
|
@_renderedRecipeType = @model.type
|
||||||
|
|
||||||
if @_typeController?
|
if @_typeController?
|
||||||
@_typeController.remove()
|
@_typeController.remove()
|
||||||
@_typeController = null
|
@_typeController = null
|
||||||
|
|
||||||
return unless @recipeType?
|
return unless @_renderedRecipeType?
|
||||||
|
|
||||||
@$el.append "<div class=\"view__#{@recipeType.css}\"></div>"
|
TypeController = @_lookupControllerFor @model.type
|
||||||
|
|
||||||
|
@$el.append "<div class=\"view__#{@model.type}\"></div>"
|
||||||
options = imageLoader:@_imageLoader, model:@model, modPack:@_modPack, router:@_router
|
options = imageLoader:@_imageLoader, model:@model, modPack:@_modPack, router:@_router
|
||||||
@_typeController = @addChild @recipeType.Controller, ".view__#{@recipeType.css}", options
|
@_typeController = @addChild TypeController, ".view__#{@model.type}", options
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
|
|
||||||
.view__step
|
.view__step
|
||||||
h3
|
h3
|
||||||
.main_content
|
.view__recipe
|
||||||
.view__inventory
|
|
||||||
.view__recipe
|
|
||||||
.buttons
|
.buttons
|
||||||
a.button.tool: .bezel: p <span class="full">show plan for </span>tools
|
a.button.tool: .bezel: p <span class="full">show plan for </span>tools
|
||||||
.button.complete: .bezel: p complete<span class="full"> step</span>
|
.button.complete: .bezel: p complete<span class="full"> step</span>
|
||||||
|
|||||||
@@ -25,24 +25,7 @@
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main_content {
|
& > .buttons {
|
||||||
display: flex;
|
|
||||||
|
|
||||||
.view__inventory {
|
|
||||||
flex: 50%;
|
|
||||||
margin-left: $size-margin-large;
|
|
||||||
|
|
||||||
.buttons {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.view__recipe {
|
|
||||||
flex: 50%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttons {
|
|
||||||
margin-top: $size-margin-large;
|
margin-top: $size-margin-large;
|
||||||
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
BaseController = require '../../base_controller'
|
BaseController = require "../../base_controller"
|
||||||
{Inventory} = require("crafting-guide-common").models
|
{Inventory} = require("crafting-guide-common").models
|
||||||
{CraftingPlanStep} = require("crafting-guide-common").crafting
|
{CraftingPlanStep} = require("crafting-guide-common").crafting
|
||||||
InventoryController = require '../../common/inventory/inventory_controller'
|
InventoryController = require "../../common/inventory/inventory_controller"
|
||||||
RecipeController = require '../../common/recipe/recipe_controller'
|
RecipeController = require "../../common/recipe/recipe_controller"
|
||||||
|
RecipeDisplay = require "../../../models/site/recipe_display"
|
||||||
|
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
@@ -19,9 +20,9 @@ module.exports = class StepController extends BaseController
|
|||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
if options.model?.constructor isnt CraftingPlanStep
|
if options.model?.constructor isnt CraftingPlanStep
|
||||||
throw new Error "options.model must be a CraftingPlanStep"
|
throw new Error "options.model must be a CraftingPlanStep"
|
||||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
if not options.modPack? then throw new Error "options.modPack is required"
|
||||||
if not options.imageLoader? then throw new Error 'options.imageLoader is required'
|
if not options.imageLoader? then throw new Error "options.imageLoader is required"
|
||||||
options.templateName = 'craft_page/step'
|
options.templateName = "craft_page/step"
|
||||||
super options
|
super options
|
||||||
|
|
||||||
@_imageLoader = options.imageLoader
|
@_imageLoader = options.imageLoader
|
||||||
@@ -36,57 +37,45 @@ module.exports = class StepController extends BaseController
|
|||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
markComplete: (targetInventory)->
|
markComplete: (targetInventory)->
|
||||||
@$el.addClass 'complete'
|
@$el.addClass "complete"
|
||||||
@$completeButton.addClass 'disabled'
|
@$completeButton.addClass "disabled"
|
||||||
@model.completeInto targetInventory
|
@model.completeInto targetInventory
|
||||||
|
|
||||||
# Event Methods ################################################################################
|
# Event Methods ################################################################################
|
||||||
|
|
||||||
onCompleteButtonClicked: (event)->
|
onCompleteButtonClicked: (event)->
|
||||||
return false if @$completeButton.hasClass 'disabled'
|
return false if @$completeButton.hasClass "disabled"
|
||||||
tracker.trackEvent c.tracking.category.craft, 'mark-complete', null, @model.count
|
tracker.trackEvent c.tracking.category.craft, "mark-complete", null, @model.count
|
||||||
@onComplete this
|
@onComplete this
|
||||||
|
|
||||||
onShowToolPlan: (event)->
|
onShowToolPlan: (event)->
|
||||||
return false if @$toolButton.hasClass 'disabled'
|
return false if @$toolButton.hasClass "disabled"
|
||||||
tracker.trackEvent c.tracking.category.navigate, 'show-tool-plan', @$toolButton.attr 'target'
|
tracker.trackEvent c.tracking.category.navigate, "show-tool-plan", @$toolButton.attr "target"
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@inventoryController = @addChild InventoryController, '.view__inventory',
|
options = imageLoader:@_imageLoader, modPack:@_modPack, router:@_router
|
||||||
editable: false
|
@recipeController = @addChild RecipeController, ".view__recipe", options
|
||||||
imageLoader: @_imageLoader
|
|
||||||
model: @model.inputInventory
|
|
||||||
modPack: @_modPack
|
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@recipeController = @addChild RecipeController, '.view__recipe',
|
@$completeButton = @$(".button.complete")
|
||||||
imageLoader: @_imageLoader
|
@$header = @$("h3")
|
||||||
model: @model.recipe
|
@$toolButton = @$(".button.tool")
|
||||||
modPack: @_modPack
|
@$toolButtonLabel = @$(".button.tool p")
|
||||||
router: @_router
|
|
||||||
|
|
||||||
@$completeButton = @$('.button.complete')
|
|
||||||
@$header = @$('h3')
|
|
||||||
@$toolButton = @$('.button.tool')
|
|
||||||
@$toolButtonLabel = @$('.button.tool p')
|
|
||||||
super
|
super
|
||||||
|
|
||||||
onWillChangeModel: (oldModel, newModel)->
|
onWillChangeModel: (oldModel, newModel)->
|
||||||
if not newModel? then throw new Error 'model cannot be null'
|
if not newModel? then throw new Error "model cannot be null"
|
||||||
if @rendered
|
if @rendered
|
||||||
@$el.removeClass 'complete'
|
@$el.removeClass "complete"
|
||||||
@$completeButton.removeClass 'disabled'
|
@$completeButton.removeClass "disabled"
|
||||||
return super
|
return super
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
@$header.html "#{@model.number}. #{@model.recipe.output.item.displayName}"
|
@$header.html "#{@model.number}. #{@model.recipe.output.item.displayName}"
|
||||||
|
|
||||||
@inventoryController.model = @model.inputInventory
|
@recipeController.model = new RecipeDisplay recipe:@model.recipe, multiplier:@model.count
|
||||||
@recipeController.model = @model.recipe
|
|
||||||
@recipeController.multiplier = @model.count
|
|
||||||
|
|
||||||
@_refreshCompleteButton()
|
@_refreshCompleteButton()
|
||||||
@_refreshToolButton()
|
@_refreshToolButton()
|
||||||
@@ -97,8 +86,8 @@ module.exports = class StepController extends BaseController
|
|||||||
|
|
||||||
events: ->
|
events: ->
|
||||||
return _.extend super,
|
return _.extend super,
|
||||||
'click .button.complete': 'onCompleteButtonClicked'
|
"click .button.complete": "onCompleteButtonClicked"
|
||||||
'click .button.tool': 'onShowToolPlan'
|
"click .button.tool": "onShowToolPlan"
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
@@ -108,16 +97,16 @@ module.exports = class StepController extends BaseController
|
|||||||
inventory.add item
|
inventory.add item
|
||||||
|
|
||||||
inventoryText = inventory.toUrlString()
|
inventoryText = inventory.toUrlString()
|
||||||
@$toolButton.attr 'href', "/craft/#{inventoryText}"
|
@$toolButton.attr "href", "/craft/#{inventoryText}"
|
||||||
@$toolButton.attr 'target', inventoryText
|
@$toolButton.attr "target", inventoryText
|
||||||
|
|
||||||
if @canAddTools this
|
if @canAddTools this
|
||||||
@$toolButton.removeClass 'disabled'
|
@$toolButton.removeClass "disabled"
|
||||||
else
|
else
|
||||||
@$toolButton.addClass 'disabled'
|
@$toolButton.addClass "disabled"
|
||||||
|
|
||||||
_refreshCompleteButton: ->
|
_refreshCompleteButton: ->
|
||||||
if @canComplete this
|
if @canComplete this
|
||||||
@$completeButton.removeClass 'disabled'
|
@$completeButton.removeClass "disabled"
|
||||||
else
|
else
|
||||||
@$completeButton.addClass 'disabled'
|
@$completeButton.addClass "disabled"
|
||||||
|
|||||||
@@ -24,11 +24,6 @@
|
|||||||
|
|
||||||
section.description.view__markdown_section
|
section.description.view__markdown_section
|
||||||
|
|
||||||
section.multiblock
|
|
||||||
h2 Multiblock Construction
|
|
||||||
.panel
|
|
||||||
.view__multiblock_viewer
|
|
||||||
|
|
||||||
section.recipes
|
section.recipes
|
||||||
h2 Recipes
|
h2 Recipes
|
||||||
.panel
|
.panel
|
||||||
@@ -43,4 +38,4 @@
|
|||||||
|
|
||||||
section.view__item_group.usedAsToolToMake
|
section.view__item_group.usedAsToolToMake
|
||||||
|
|
||||||
section.view__item_group.similar
|
section.view__item_group.similar
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ ItemDisplay = require "../../models/site/item_display"
|
|||||||
ItemGroupController = require "../common/item_group/item_group_controller"
|
ItemGroupController = require "../common/item_group/item_group_controller"
|
||||||
ItemPage = require "../../models/site/item_page"
|
ItemPage = require "../../models/site/item_page"
|
||||||
MarkdownSectionController = require "../common/markdown_section/markdown_section_controller"
|
MarkdownSectionController = require "../common/markdown_section/markdown_section_controller"
|
||||||
MultiblockViewerController = require "./multiblock_viewer/multiblock_viewer_controller"
|
|
||||||
PageController = require "../page_controller"
|
PageController = require "../page_controller"
|
||||||
RecipeDetailController = require "./recipe_detail/recipe_detail_controller"
|
RecipeController = require "../common/recipe/recipe_controller"
|
||||||
|
RecipeDisplay = require "../../models/site/recipe_display"
|
||||||
VideoController = require "../common/video/video_controller"
|
VideoController = require "../common/video/video_controller"
|
||||||
w = require "when"
|
w = require "when"
|
||||||
|
|
||||||
@@ -79,7 +79,6 @@ module.exports = class ItemPageController extends PageController
|
|||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
options = imageLoader:@_imageLoader, modPack:@_modPack, router:@_router, show:false
|
options = imageLoader:@_imageLoader, modPack:@_modPack, router:@_router, show:false
|
||||||
@_multiblockController = @addChild MultiblockViewerController, '.view__multiblock_viewer', options
|
|
||||||
@_similarItemsController = @addChild ItemGroupController, '.view__item_group.similar', options
|
@_similarItemsController = @addChild ItemGroupController, '.view__item_group.similar', options
|
||||||
@_usedAsToolToMakeController = @addChild ItemGroupController, '.view__item_group.usedAsToolToMake ', options
|
@_usedAsToolToMakeController = @addChild ItemGroupController, '.view__item_group.usedAsToolToMake ', options
|
||||||
@_usedToMakeController = @addChild ItemGroupController, '.view__item_group.usedToMake', options
|
@_usedToMakeController = @addChild ItemGroupController, '.view__item_group.usedToMake', options
|
||||||
@@ -140,7 +139,6 @@ module.exports = class ItemPageController extends PageController
|
|||||||
|
|
||||||
@_refreshSourceMod()
|
@_refreshSourceMod()
|
||||||
@_refreshDescription()
|
@_refreshDescription()
|
||||||
@_refreshMultiblock()
|
|
||||||
@_refreshRecipes()
|
@_refreshRecipes()
|
||||||
@_refreshSimilarItems()
|
@_refreshSimilarItems()
|
||||||
@_refreshUsedAsToolToMake()
|
@_refreshUsedAsToolToMake()
|
||||||
@@ -221,13 +219,6 @@ module.exports = class ItemPageController extends PageController
|
|||||||
@_descriptionController.model = @model.item.detail.description
|
@_descriptionController.model = @model.item.detail.description
|
||||||
@_descriptionController.resetToDefaultState()
|
@_descriptionController.resetToDefaultState()
|
||||||
|
|
||||||
_refreshMultiblock: ->
|
|
||||||
if @model.item.isMultiblock
|
|
||||||
@_multiblockController.model = @model.item.getMultiblockRecipe()
|
|
||||||
@show @$multiblockSection
|
|
||||||
else
|
|
||||||
@hide @$multiblockSection
|
|
||||||
|
|
||||||
_refreshRecipes: ->
|
_refreshRecipes: ->
|
||||||
@_recipeControllers ?= []
|
@_recipeControllers ?= []
|
||||||
index = 0
|
index = 0
|
||||||
@@ -239,16 +230,16 @@ module.exports = class ItemPageController extends PageController
|
|||||||
for recipe in recipes
|
for recipe in recipes
|
||||||
controller = @_recipeControllers[index]
|
controller = @_recipeControllers[index]
|
||||||
if not controller?
|
if not controller?
|
||||||
controller = new RecipeDetailController
|
controller = new RecipeController
|
||||||
imageLoader: @_imageLoader
|
imageLoader: @_imageLoader
|
||||||
modPack: @_modPack
|
modPack: @_modPack
|
||||||
model: recipe
|
model: new RecipeDisplay recipe:recipe
|
||||||
router: @_router
|
router: @_router
|
||||||
@_recipeControllers.push controller
|
@_recipeControllers.push controller
|
||||||
@$recipeContainer.append controller.$el
|
@$recipeContainer.append controller.$el
|
||||||
controller.render()
|
controller.render()
|
||||||
else
|
else
|
||||||
controller.model = recipe
|
controller.model = new RecipeDisplay recipe:recipe
|
||||||
index++
|
index++
|
||||||
|
|
||||||
@show @$recipesSection
|
@show @$recipesSection
|
||||||
|
|||||||
Reference in New Issue
Block a user