Complete the Crafting Table view/controller
* Add output box to the crafting table view * Add remaining crafting patterns to all MC 1.7.10 recipes * Add all crafting patterns to Buildcraft 6.2.6 * Disable mods which don't have patterns yet * Add the Url constants for computing urls from templates * Add the `findItemDisplay` to ModPack (along with tests) and remove all replace all uses of `getPathSlugs` with it
This commit is contained in:
@@ -7,12 +7,14 @@ All rights reserved.
|
||||
|
||||
exports.DefaultBookUrls = DefaultBookUrls = [
|
||||
'/data/minecraft/recipes.json'
|
||||
'/data/applied_energetics/recipes.json'
|
||||
'/data/buildcraft/recipes.json'
|
||||
'/data/gravisuite/recipes.json'
|
||||
'/data/industrial_craft/recipes.json'
|
||||
'/data/more_blocks/recipes.json'
|
||||
'/data/thermal_expansion/recipes.json'
|
||||
|
||||
# Disabled until shaped crafting can be added -- aminer 2015-01-09
|
||||
# '/data/applied_energetics/recipes.json'
|
||||
# '/data/gravisuite/recipes.json'
|
||||
# '/data/industrial_craft/recipes.json'
|
||||
# '/data/more_blocks/recipes.json'
|
||||
# '/data/thermal_expansion/recipes.json'
|
||||
]
|
||||
|
||||
exports.Duration = Duration = {}
|
||||
@@ -31,7 +33,9 @@ Event.load.failed = 'load:failed' # controller, error message
|
||||
Event.load.finished = 'load:finished' # controller
|
||||
Event.remove = 'remove' # collection, item...
|
||||
|
||||
exports.ImageUrl = _.template "/data/<%= modSlug %>/images/<%= itemSlug %>.png"
|
||||
exports.Url = Url = {}
|
||||
Url.itemIcon = _.template "/data/<%= modSlug %>/images/<%= itemSlug %>.png"
|
||||
Url.item = _.template "/item/<%= encodeURIComponent(itemName) %>"
|
||||
|
||||
exports.Key = Key = {}
|
||||
Key.Return = 13
|
||||
|
||||
@@ -7,15 +7,11 @@ All rights reserved.
|
||||
|
||||
BaseController = require './base_controller'
|
||||
ImageLoader = require './image_loader'
|
||||
{ImageUrl} = require '../constants'
|
||||
util = require 'util'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class CraftingGridController extends BaseController
|
||||
|
||||
@EMPTY_IMAGE = '/images/empty.png'
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.model? then throw new Error 'options.model is required'
|
||||
options.imageLoader ?= new ImageLoader default:'/images/unknown.png'
|
||||
@@ -39,14 +35,14 @@ module.exports = class CraftingGridController extends BaseController
|
||||
|
||||
slot.a.addClass 'empty'
|
||||
slot.a.removeAttr 'href'
|
||||
slot.img.attr 'src', CraftingGridController.EMPTY_IMAGE
|
||||
slot.img.attr 'src', '/images/empty.png'
|
||||
slot.img.removeAttr 'alt'
|
||||
|
||||
itemData = @model.getItemDataAt index
|
||||
if itemData?
|
||||
display = @model.getItemDisplayAt index
|
||||
if display?
|
||||
slot.a.removeClass 'empty'
|
||||
slot.a.attr 'href', "/items/#{encodeURIComponent(itemData.name)}"
|
||||
logger.debug "item data: #{util.inspect(itemData)}"
|
||||
@_imageLoader.load ImageUrl(itemData), slot.img
|
||||
slot.img.attr 'alt', itemData.name
|
||||
slot.a.attr 'href', display.itemUrl
|
||||
@_imageLoader.load display.iconUrl, slot.img
|
||||
slot.img.attr 'alt', display.itemName
|
||||
|
||||
super
|
||||
|
||||
@@ -5,8 +5,9 @@ Copyright (c) 2014-2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
BaseController = require './base_controller'
|
||||
BaseController = require './base_controller'
|
||||
CraftingGridController = require './crafting_grid_controller'
|
||||
ImageLoader = require './image_loader'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -14,9 +15,14 @@ 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 default:'/images/unknown.png'
|
||||
options.templateName = 'crafting_table'
|
||||
super options
|
||||
|
||||
@imageLoader = options.imageLoader
|
||||
@modPack = options.modPack
|
||||
|
||||
# Event Methods ################################################################################
|
||||
|
||||
onNextClicked: ->
|
||||
@@ -30,9 +36,13 @@ module.exports = class CraftingTableController extends BaseController
|
||||
onDidRender: ->
|
||||
@gridController = @addChild CraftingGridController, '.view__crafting_grid', model:@model.grid
|
||||
|
||||
@$next = @$('.next')
|
||||
@$prev = @$('.prev')
|
||||
@$tool = @$('.tool p')
|
||||
@$multiplier = @$('.multiplier')
|
||||
@$next = @$('.next')
|
||||
@$outputImg = @$('.output img')
|
||||
@$outputLink = @$('.output a')
|
||||
@$outputQuantity = @$('.quantity')
|
||||
@$prev = @$('.prev')
|
||||
@$tool = @$('.tool p')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@@ -45,6 +55,25 @@ module.exports = class CraftingTableController extends BaseController
|
||||
|
||||
@$tool.html @model.toolNames
|
||||
|
||||
@$outputImg.attr 'src', '/images/empty.png'
|
||||
@$outputImg.removeAttr 'alt'
|
||||
@$outputLink.removeAttr 'href'
|
||||
@$outputQuantity.html ''
|
||||
|
||||
outputStack = @model.output
|
||||
if outputStack?
|
||||
display = @modPack.findItemDisplay outputStack.itemSlug
|
||||
@$outputLink.attr 'href', display.itemUrl
|
||||
@$outputImg.attr 'alt', display.itemName
|
||||
@$outputQuantity.html outputStack.quantity if outputStack.quantity > 1
|
||||
|
||||
@imageLoader.load display.iconUrl, @$outputImg
|
||||
|
||||
if @model.multiplier > 1
|
||||
@$multiplier.html "×#{@model.multiplier}"
|
||||
else
|
||||
@$multiplier.html ''
|
||||
|
||||
super
|
||||
|
||||
# Backbone.View Overrides ######################################################################
|
||||
|
||||
@@ -36,32 +36,32 @@ module.exports = class ItemPageController extends BaseController
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
options =
|
||||
@haveController = @addChild InventoryController, '.have',
|
||||
editable: true,
|
||||
imageLoader: @imageLoader
|
||||
model: @model.plan.have,
|
||||
modPack: @model.modPack,
|
||||
title: 'Items you have'
|
||||
@haveController = @addChild InventoryController, '.have', options
|
||||
|
||||
options =
|
||||
@wantController = @addChild InventoryController, '.want',
|
||||
editable: true
|
||||
icon: '/images/fishing_rod.png',
|
||||
imageLoader: @imageLoader
|
||||
model: @model.plan.want,
|
||||
modPack: @model.modPack,
|
||||
title: 'Items you want'
|
||||
@wantController = @addChild InventoryController, '.want', options
|
||||
|
||||
options =
|
||||
@needController = @addChild InventoryController, '.need',
|
||||
editable: false
|
||||
icon: '/images/boots.png',
|
||||
imageLoader: @imageLoader
|
||||
model: @model.plan.need,
|
||||
modPack: @model.modPack,
|
||||
title: "Items you'll need"
|
||||
@needController = @addChild InventoryController, '.need', options
|
||||
|
||||
@craftingTableController = @addChild CraftingTableController, '.view__crafting_table', model:@model.table
|
||||
@craftingTableController = @addChild CraftingTableController, '.view__crafting_table',
|
||||
model: @model.table
|
||||
modPack: @model.modPack
|
||||
|
||||
@modPackController = @addChild ModPackController, '.view__mod_pack', model:@model.modPack
|
||||
super
|
||||
|
||||
@@ -6,7 +6,6 @@ All rights reserved.
|
||||
###
|
||||
|
||||
BaseController = require './base_controller'
|
||||
{ImageUrl} = require '../constants'
|
||||
ImageLoader = require './image_loader'
|
||||
|
||||
########################################################################################################################
|
||||
@@ -32,24 +31,9 @@ module.exports = class StackController extends BaseController
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
{itemName, itemSlug, modSlug} = @_gatherData()
|
||||
imageUrl = ImageUrl itemSlug:itemSlug, modSlug:modSlug
|
||||
display = @modPack.findItemDisplay @model.itemSlug
|
||||
|
||||
@$nameField.html itemName
|
||||
@$nameField.html display.itemName
|
||||
@$quantityField.html @model.quantity
|
||||
@_imageLoader.load imageUrl, @$image
|
||||
@_imageLoader.load display.iconUrl, @$image
|
||||
super
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_gatherData: ->
|
||||
itemSlug = @model.itemSlug
|
||||
item = @modPack.findItem @model.itemSlug
|
||||
if item?
|
||||
itemName = item.name
|
||||
modSlug = item.modVersion.slug
|
||||
else
|
||||
itemName = @modPack.findName @model.itemSlug
|
||||
modSlug = 'minecraft'
|
||||
|
||||
return itemName:itemName, itemSlug:itemSlug, modSlug:modSlug
|
||||
|
||||
@@ -14,9 +14,10 @@ CraftingGuideRouter = require './crafting_guide_router'
|
||||
if typeof(global) is 'undefined'
|
||||
window.global = window
|
||||
|
||||
global.views = views
|
||||
global.logger = new Logger level:Logger.TRACE
|
||||
global.router = new CraftingGuideRouter
|
||||
global.util = require 'util'
|
||||
global.views = views
|
||||
|
||||
logger.info "CraftingGuide is ready"
|
||||
Backbone.history.start pushState:true
|
||||
|
||||
@@ -6,7 +6,6 @@ All rights reserved.
|
||||
###
|
||||
|
||||
BaseModel = require './base_model'
|
||||
util = require 'util'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -23,19 +22,12 @@ module.exports = class CraftingGrid extends BaseModel
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
getItemDataAt: (index)->
|
||||
getItemDisplayAt: (index)->
|
||||
if index >= @slotCount then throw new Error "index (#{index}) must be less than #{@slotCount}"
|
||||
return null unless @recipe?
|
||||
|
||||
logger.debug "recipe: #{@recipe}"
|
||||
|
||||
itemSlug = @recipe.getItemSlugAt index
|
||||
return null unless itemSlug?
|
||||
|
||||
item = @modPack.findItem itemSlug
|
||||
if item?
|
||||
itemData = item.pathSlugs
|
||||
itemData.name = item.name
|
||||
return itemData
|
||||
else
|
||||
return modSlug:'minecraft', itemSlug:itemSlug, name:@modPack.findName(itemSlug)
|
||||
itemDisplay = @modPack.findItemDisplay itemSlug
|
||||
return itemDisplay
|
||||
|
||||
@@ -26,6 +26,8 @@ module.exports = class CraftingTable extends BaseModel
|
||||
hasNextStep: { get:@hasNextStep }
|
||||
hasPrevStep: { get:@hasPrevStep }
|
||||
hasSteps: { get:@hasSteps }
|
||||
multiplier: { get:@getMultiplier }
|
||||
output: { get:@getOutput }
|
||||
step: { get:@getStep, set:@setStep }
|
||||
toolNames: { get:@getToolNames }
|
||||
}
|
||||
@@ -46,6 +48,19 @@ module.exports = class CraftingTable extends BaseModel
|
||||
hasPrevStep: ->
|
||||
return @_step > 0
|
||||
|
||||
hasSteps: ->
|
||||
return @_steps.length > 0
|
||||
|
||||
getMultiplier: ->
|
||||
step = @_steps[@_step]
|
||||
return unless step?
|
||||
return step.multiplier
|
||||
|
||||
getOutput: ->
|
||||
step = @_steps[@_step]
|
||||
return unless step?
|
||||
return step.recipe.output[0]
|
||||
|
||||
getStep: ->
|
||||
return @_step
|
||||
|
||||
@@ -58,9 +73,6 @@ module.exports = class CraftingTable extends BaseModel
|
||||
|
||||
return this
|
||||
|
||||
hasSteps: ->
|
||||
return @_steps.length > 0
|
||||
|
||||
getToolNames: ->
|
||||
recipe = @_steps[@_step]?.recipe
|
||||
return '' unless recipe?
|
||||
|
||||
@@ -25,8 +25,6 @@ module.exports = class Item extends BaseModel
|
||||
|
||||
Object.defineProperty @prototype, 'isCraftable', get:-> @recipes.length > 0
|
||||
|
||||
Object.defineProperty @prototype, 'pathSlugs', get:-> @getPathSlugs()
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
addRecipe: (recipe)->
|
||||
@@ -40,9 +38,6 @@ module.exports = class Item extends BaseModel
|
||||
return if this.name < that.name then -1 else +1
|
||||
return 0
|
||||
|
||||
getPathSlugs: ->
|
||||
return modSlug:@modVersion.slug, itemSlug:@slug
|
||||
|
||||
# Object Overrides #############################################################################
|
||||
|
||||
toString: ->
|
||||
|
||||
@@ -9,7 +9,7 @@ BaseModel = require './base_model'
|
||||
{Event} = require '../constants'
|
||||
ModVersionParser = require './mod_version_parser'
|
||||
{RequiredMods} = require '../constants'
|
||||
util = require 'util'
|
||||
{Url} = require '../constants'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -59,6 +59,22 @@ module.exports = class ModPack extends BaseModel
|
||||
|
||||
return slug
|
||||
|
||||
findItemDisplay: (slug)->
|
||||
result = {}
|
||||
item = @findItem slug, includeDisabled:true
|
||||
if item?
|
||||
result.modSlug = item.modVersion.slug
|
||||
result.itemSlug = item.slug
|
||||
result.itemName = item.name
|
||||
else
|
||||
result.modSlug = _.slugify RequiredMods[0]
|
||||
result.itemSlug = slug
|
||||
result.itemName = @findName slug, includeDisabled:true
|
||||
|
||||
result.iconUrl = Url.itemIcon result
|
||||
result.itemUrl = Url.item result
|
||||
return result
|
||||
|
||||
gatherRecipeNames: (options={})->
|
||||
options.includeDisabled ?= false
|
||||
|
||||
@@ -110,6 +126,7 @@ module.exports = class ModPack extends BaseModel
|
||||
onModVersionLoaded: (url, data, status, xhr)->
|
||||
try
|
||||
modVersion = @loadModVersionData data
|
||||
modVersion.enabled = true
|
||||
|
||||
logger.info "loaded ModVersion from #{url}: #{modVersion}"
|
||||
@trigger Event.load.succeeded, this, modVersion
|
||||
|
||||
@@ -10,7 +10,6 @@ Logger = require '../logger'
|
||||
ModVersion = require './mod_version'
|
||||
Recipe = require './recipe'
|
||||
Stack = require './stack'
|
||||
util = require 'util'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
|
||||
Reference in New Issue
Block a user