Files
website/src/scripts/controllers/crafting_table_controller.coffee
T
Andrew Miner 96617a755e First real version of item detail page
* Split the InventoryTable view/controller out from the existing
  inventory view/controller. This is a simpler component which only
  includes the table itself, and not the scrollbox, panel or header
  used on the crafting page.
* Create the FullRecipe view/controller to represent the expanded
  version of a recipe shown on the item page (as compared to the
  terser version on the crafting page).
* Rename the existing Recipe view/controller to MinimalRecipe to
  avoid confusing the two.
* Refactor the CSS for the Stack view/controller so that it can be
  shared between the Inventory and InventoryTable views.
* Incorporate all these new controllers into the item page and hook
  up the necessary model logic to drive them.
2015-02-08 22:54:12 -08:00

94 lines
3.3 KiB
CoffeeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
###
Crafting Guide - crafting_table_controller.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
{Duration} = require '../constants'
ImageLoader = require './image_loader'
InventoryParser = require '../models/inventory_parser'
MinimalRecipeController = require './minimal_recipe_controller'
########################################################################################################################
module.exports = class CraftingTableController extends BaseController
constructor: (options={})->
if not options.model? then throw new Error 'options.model is required'
if not options.modPack? then throw new Error 'options.modPack is required'
options.imageLoader ?= new ImageLoader defaultUrl:'/images/unknown.png'
options.templateName = 'crafting_table'
super options
@_imageLoader = options.imageLoader
@_modPack = options.modPack
# Event Methods ################################################################################
onNextClicked: ->
@model.stepIndex += 1
onPrevClicked: ->
@model.stepIndex -= 1
onReportProblem: ->
parser = new InventoryParser @_modPack
itemList = parser.unparse @model.plan.want
toolsMessage = if @model.plan.includingTools then '(including tools)' else ''
message = "When I was on step #{@model.stepIndex + 1} of making:
\n\n#{itemList}#{toolsMessage}\n\nI noticed that...\n"
global.feedbackController.enterFeedback message
# BaseController Overrides #####################################################################
onDidRender: ->
@recipeController = @addChild MinimalRecipeController, '.view__minimal_recipe', imageLoader:@_imageLoader, modPack:@_modPack
@$next = @$('.next')
@$prev = @$('.prev')
@$problemControl = @$('.problem')
@$title = @$('h2 p')
@$tool = @$('.tool p')
@$multiplier = $('<p class="multiplier"></p>')
@$('.output').append @$multiplier
@defaultTitle = @$title.html()
super
refresh: ->
@$prev.removeClass 'enabled'
@$next.removeClass 'enabled'
if @model.hasSteps
if @model.hasPrevStep then @$prev.addClass 'enabled'
if @model.hasNextStep then @$next.addClass 'enabled'
@$title.html "Step #{@model.stepIndex + 1} of #{@model.stepCount}"
else
@$title.html @defaultTitle
currentStep = @model.currentStep
@recipeController.model = currentStep?.recipe
if currentStep?.multiplier > 1
@$multiplier.html "×#{currentStep.multiplier}"
else
@$multiplier.html ''
if not (@model.hasSteps and global.feedbackController?)
@$problemControl.hide duration:Duration.fast
else
@$problemControl.show duration:Duration.normal
super
# Backbone.View Overrides ######################################################################
events: ->
return _.extend super,
'click .next': 'onNextClicked'
'click .prev': 'onPrevClicked'
'click .problem a': 'onReportProblem'