diff --git a/src/client/models/crafting/simple_inventory.coffee b/src/client/models/crafting/simple_inventory.coffee index 052c85b8a..8c4704d78 100644 --- a/src/client/models/crafting/simple_inventory.coffee +++ b/src/client/models/crafting/simple_inventory.coffee @@ -44,7 +44,7 @@ module.exports = class SimpleInventory @_itemSlugs = [] clone: -> - inventory = new Inventory + inventory = new SimpleInventory inventory.addInventory this return inventory @@ -130,9 +130,9 @@ module.exports = class SimpleInventory parse: (data)-> return this if not data? or data.length is 0 - stacks = data.split Inventory.Delimiters.Stack + stacks = data.split SimpleInventory.Delimiters.Stack for stackText in stacks - stackParts = stackText.split Inventory.Delimiters.Item + stackParts = stackText.split SimpleInventory.Delimiters.Item if stackParts.length is 2 quantity = parseInt stackParts[0], 10 itemSlug = ItemSlug.slugify stackParts[1] diff --git a/src/client/site/craft_page/craft_page.jade b/src/client/site/craft_page/craft_page.jade index 5c38856e8..b7c14052d 100644 --- a/src/client/site/craft_page/craft_page.jade +++ b/src/client/site/craft_page/craft_page.jade @@ -18,19 +18,19 @@ p. Not sure what you'd like to make? Try one of these: .items - a(href="/craft/potion_of_strength_ii_1_30") + a(href="/" data-slug="potion_of_strength_ii_1_30") img(src="/data/minecraft/items/potion_of_strength_ii_1_30/icon.png") - a(href="/craft/quarry") + a(href="/" data-slug="quarry") img(src="/data/buildcraft/items/quarry/icon.png") - a(href="/craft/quantumsuit_bodyarmor:quantumsuit_boots:quantumsuit_helmet:quantumsuit_leggings") + a(href="/" data-slug="quantumsuit_bodyarmor:quantumsuit_boots:quantumsuit_helmet:quantumsuit_leggings") img(src="/data/ic2_classic/items/quantumsuit_helmet/icon.png") - a(href="/craft/solar_panel_vi") + a(href="/" data-slug="solar_panel_vi") img(src="/data/solar_flux/items/solar_panel_vi/icon.png") - a(href="/craft/crystal_chest") + a(href="/" data-slug="crystal_chest") img(src="/data/iron_chests/items/crystal_chest/icon.png") - a(href="/craft/digital_miner") + a(href="/" data-slug="digital_miner") img(src="/data/mekanism/items/digital_miner/icon.png") - a(href="/craft/2.tesseract") + a(href="/" data-slug="2.tesseract") img(src="/data/thermal_expansion/items/tesseract/icon.png") section.want diff --git a/src/client/site/craft_page/craft_page_controller.coffee b/src/client/site/craft_page/craft_page_controller.coffee index d2fe37551..6aebfa35e 100644 --- a/src/client/site/craft_page/craft_page_controller.coffee +++ b/src/client/site/craft_page/craft_page_controller.coffee @@ -11,12 +11,15 @@ Craftsman = require '../../models/crafting/craftsman' CraftsmanWorkingController = require './craftsman_working/craftsman_working_controller' InventoryController = require '../common/inventory/inventory_controller' PageController = require '../page_controller' +SimpleInventory = require '../../models/crafting/simple_inventory' StepController = require './step/step_controller' ######################################################################################################################## module.exports = class CraftPageController extends PageController + @::SCROLL_BUFFER = 8 # px + constructor: (options={})-> if not options.imageLoader? then throw new Error 'options.imageLoader is required' if not options.modPack? then throw new Error 'options.modPack is required' @@ -48,6 +51,21 @@ module.exports = class CraftPageController extends PageController @model.craftsman.want.remove itemSlug @onWantInventoryChanged() + onSampleClicked: (event)-> + $el = $(event.target) + while $el.length > 0 + inventoryText = $el.attr 'data-slug' + break if inventoryText + $el = $el.parent() + + if inventoryText? + sampleInventory = new SimpleInventory + sampleInventory.parse inventoryText + @model.craftsman.want.addInventory sampleInventory + @_scrollTo @$workingSection + + return false + onWantInventoryChanged: -> text = @model.craftsman.want.unparse() url = c.url.crafting inventoryText:text @@ -96,7 +114,7 @@ module.exports = class CraftPageController extends PageController @_workingSectionController = @addChild CraftsmanWorkingController, '.view__craftsman_working', model: @model.craftsman - @_workingSectionController.on c.event.click, -> window.scrollTo 0, 0 + @_workingSectionController.on c.event.click, => @_scrollTo @$workingSection @$haveSection = @$('section.have') @$instructionsSection = @$('section.instructions') @@ -118,6 +136,11 @@ module.exports = class CraftPageController extends PageController @model.craftsman.have.on c.event.change, => @onHaveInventoryChanged() @model.craftsman.want.on c.event.change, => @refresh() + + @model.craftsman.on c.event.change + ":stage", => + return unless @model.craftsman.stage is Craftsman::STAGE.COMPLETE + @_scrollTo @$needSection + super refresh: -> @@ -132,7 +155,7 @@ module.exports = class CraftPageController extends PageController events: -> return _.extend super, - 'click .instructions a': 'routeLinkClick' + 'click .instructions a': 'onSampleClicked' # Private Methods ################################################################################ @@ -219,3 +242,28 @@ module.exports = class CraftPageController extends PageController while @_stepControllers.length > index @_stepControllers.pop().remove() + + _scrollTo: ($targetEl)-> + @_$scrollTarget = $targetEl + + if @_scrollTimer? + clearTimeout @_scrollTimer + + @_scrollTimer = setTimeout(=> + $el = @_$scrollTarget + @_scrollTimer = null + + minScrollPosition = $el.offset().top + $el.height() - $(window).height() - @SCROLL_BUFFER + maxScrollPosition = $el.offset().top + @SCROLL_BUFFER + scrollPosition = $(window).scrollTop() + + scrollTarget = scrollPosition + if scrollPosition > maxScrollPosition + scrollTarget = maxScrollPosition + else if scrollPosition < minScrollPosition + scrollTarget = minScrollPosition + else + return + + $('html, body').animate {scrollTop:scrollTarget}, c.duration.normal + , c.duration.slow) diff --git a/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee b/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee index 43ebe57b4..08bc905af 100644 --- a/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee +++ b/src/client/site/craft_page/craftsman_working/craftsman_working_controller.coffee @@ -90,12 +90,12 @@ module.exports = class CraftsmanWorkingController extends BaseController @show @$message @$message.html message - if waiting? - @show @$waiting - if outdated? @show @$outdated + if waiting? + @show @$waiting + super # Backbone.View Overrides ######################################################################