@@ -44,7 +44,7 @@ module.exports = class SimpleInventory
|
|||||||
@_itemSlugs = []
|
@_itemSlugs = []
|
||||||
|
|
||||||
clone: ->
|
clone: ->
|
||||||
inventory = new Inventory
|
inventory = new SimpleInventory
|
||||||
inventory.addInventory this
|
inventory.addInventory this
|
||||||
return inventory
|
return inventory
|
||||||
|
|
||||||
@@ -130,9 +130,9 @@ module.exports = class SimpleInventory
|
|||||||
parse: (data)->
|
parse: (data)->
|
||||||
return this if not data? or data.length is 0
|
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
|
for stackText in stacks
|
||||||
stackParts = stackText.split Inventory.Delimiters.Item
|
stackParts = stackText.split SimpleInventory.Delimiters.Item
|
||||||
if stackParts.length is 2
|
if stackParts.length is 2
|
||||||
quantity = parseInt stackParts[0], 10
|
quantity = parseInt stackParts[0], 10
|
||||||
itemSlug = ItemSlug.slugify stackParts[1]
|
itemSlug = ItemSlug.slugify stackParts[1]
|
||||||
|
|||||||
@@ -18,19 +18,19 @@
|
|||||||
p.
|
p.
|
||||||
Not sure what you'd like to make? Try one of these:
|
Not sure what you'd like to make? Try one of these:
|
||||||
.items
|
.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")
|
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")
|
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")
|
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")
|
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")
|
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")
|
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")
|
img(src="/data/thermal_expansion/items/tesseract/icon.png")
|
||||||
|
|
||||||
section.want
|
section.want
|
||||||
|
|||||||
@@ -11,12 +11,15 @@ Craftsman = require '../../models/crafting/craftsman'
|
|||||||
CraftsmanWorkingController = require './craftsman_working/craftsman_working_controller'
|
CraftsmanWorkingController = require './craftsman_working/craftsman_working_controller'
|
||||||
InventoryController = require '../common/inventory/inventory_controller'
|
InventoryController = require '../common/inventory/inventory_controller'
|
||||||
PageController = require '../page_controller'
|
PageController = require '../page_controller'
|
||||||
|
SimpleInventory = require '../../models/crafting/simple_inventory'
|
||||||
StepController = require './step/step_controller'
|
StepController = require './step/step_controller'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
module.exports = class CraftPageController extends PageController
|
module.exports = class CraftPageController extends PageController
|
||||||
|
|
||||||
|
@::SCROLL_BUFFER = 8 # px
|
||||||
|
|
||||||
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'
|
||||||
@@ -48,6 +51,21 @@ module.exports = class CraftPageController extends PageController
|
|||||||
@model.craftsman.want.remove itemSlug
|
@model.craftsman.want.remove itemSlug
|
||||||
@onWantInventoryChanged()
|
@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: ->
|
onWantInventoryChanged: ->
|
||||||
text = @model.craftsman.want.unparse()
|
text = @model.craftsman.want.unparse()
|
||||||
url = c.url.crafting inventoryText:text
|
url = c.url.crafting inventoryText:text
|
||||||
@@ -96,7 +114,7 @@ module.exports = class CraftPageController extends PageController
|
|||||||
|
|
||||||
@_workingSectionController = @addChild CraftsmanWorkingController, '.view__craftsman_working',
|
@_workingSectionController = @addChild CraftsmanWorkingController, '.view__craftsman_working',
|
||||||
model: @model.craftsman
|
model: @model.craftsman
|
||||||
@_workingSectionController.on c.event.click, -> window.scrollTo 0, 0
|
@_workingSectionController.on c.event.click, => @_scrollTo @$workingSection
|
||||||
|
|
||||||
@$haveSection = @$('section.have')
|
@$haveSection = @$('section.have')
|
||||||
@$instructionsSection = @$('section.instructions')
|
@$instructionsSection = @$('section.instructions')
|
||||||
@@ -118,6 +136,11 @@ module.exports = class CraftPageController extends PageController
|
|||||||
@model.craftsman.have.on c.event.change, => @onHaveInventoryChanged()
|
@model.craftsman.have.on c.event.change, => @onHaveInventoryChanged()
|
||||||
|
|
||||||
@model.craftsman.want.on c.event.change, => @refresh()
|
@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
|
super
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
@@ -132,7 +155,7 @@ module.exports = class CraftPageController extends PageController
|
|||||||
|
|
||||||
events: ->
|
events: ->
|
||||||
return _.extend super,
|
return _.extend super,
|
||||||
'click .instructions a': 'routeLinkClick'
|
'click .instructions a': 'onSampleClicked'
|
||||||
|
|
||||||
# Private Methods ################################################################################
|
# Private Methods ################################################################################
|
||||||
|
|
||||||
@@ -219,3 +242,28 @@ module.exports = class CraftPageController extends PageController
|
|||||||
|
|
||||||
while @_stepControllers.length > index
|
while @_stepControllers.length > index
|
||||||
@_stepControllers.pop().remove()
|
@_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)
|
||||||
|
|||||||
@@ -90,12 +90,12 @@ module.exports = class CraftsmanWorkingController extends BaseController
|
|||||||
@show @$message
|
@show @$message
|
||||||
@$message.html message
|
@$message.html message
|
||||||
|
|
||||||
if waiting?
|
|
||||||
@show @$waiting
|
|
||||||
|
|
||||||
if outdated?
|
if outdated?
|
||||||
@show @$outdated
|
@show @$outdated
|
||||||
|
|
||||||
|
if waiting?
|
||||||
|
@show @$waiting
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
# Backbone.View Overrides ######################################################################
|
# Backbone.View Overrides ######################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user