diff --git a/src/css/main.scss b/src/css/main.scss index b998226c0..7cc287e20 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -33,6 +33,8 @@ $color-footer-text: white; $color-gray-faint: #F2F2F2; $color-gray-light: #CCCCCC; $color-gray-medium: #A6A6A6; +$color-gray-dark: #8B8B8B; +$color-gray-shadow: #444444; $color-table-background: white; $color-toolbar-background: rgba(255, 255, 255, 0.75); diff --git a/src/css/templates/crafting_grid.scss b/src/css/templates/crafting_grid.scss index 5667af762..7bf4669b8 100644 --- a/src/css/templates/crafting_grid.scss +++ b/src/css/templates/crafting_grid.scss @@ -6,12 +6,15 @@ All rights reserved. */ .view__crafting_grid { + border: 0.4em solid $color-gray-medium; img { position: relative; height:4.8em; width: 4.8em; } td { - border: 1px solid $color-gray-light; + background: $color-gray-dark; + border: 0.1em solid $color-gray-light; + padding: 0.1em; } } \ No newline at end of file diff --git a/src/css/templates/crafting_table.scss b/src/css/templates/crafting_table.scss index 8f7b676f2..05cbcb53d 100644 --- a/src/css/templates/crafting_table.scss +++ b/src/css/templates/crafting_table.scss @@ -39,6 +39,34 @@ All rights reserved. } } + .output { + position: absolute; top: 50%; right: 16.5%; height: 5.3em; width: 5.3em; + @include transform(translate(-50%, -50%)); + + background: $color-gray-medium; + border: 0.4em solid $color-gray-medium; + padding: 0.1em; + + a { + position: absolute; top: 50%; left: 50%; height: 4.8em; width: 4.8em; + @include transform(translate(-50%, -50%)); + } + + .multiplier { + position: absolute; bottom: -3em; left: 0; right: 0; height: 1.5em; + font-family: PressStart; + font-size: $font-size-large; + text-align: center; + } + + .quantity { + position: absolute; right: 0; bottom: 0; + color: white; + font-family: PressStart; + font-size: $font-size-large; + } + } + .next { background: url('/images/arrow-right-disabled.png'); position: absolute; top: 50%; right: 1em; height: 8em; width: 4em; diff --git a/src/data/buildcraft/images/land_mark.png b/src/data/buildcraft/images/landmark.png similarity index 100% rename from src/data/buildcraft/images/land_mark.png rename to src/data/buildcraft/images/landmark.png diff --git a/src/data/buildcraft/recipes.json b/src/data/buildcraft/recipes.json index 0d18f0936..49e96cd85 100644 --- a/src/data/buildcraft/recipes.json +++ b/src/data/buildcraft/recipes.json @@ -7,347 +7,435 @@ { "output": "Advanced Crafting Table", "input": [[6, "Obsidian"], "Chest", "Crafting Table", "Redstone Chipset"], + "pattern": "020 010 030", "tools": "Crafting Table" }, { "output": "Architect Table", "input": [[2, "Dandelion Yellow"], [2, "Diamond Gear"], [2, "Ink Sac"], "Blueprint", "Crafting Table", "Landmark"], + "pattern": "252 040 131", "tools": "Crafting Table" }, { "output": "Assembly Table", "input": [[6, "Obsidian"], "Diamond", "Diamond Gear", "Redstone"], + "pattern": "030 010 020", "tools": "Crafting Table" }, { "output": "Auto Workbench", "input": [[4, "Wooden Gear"], "Crafting Table"], + "pattern": ".0. 010 .0.", "tools": "Crafting Table" }, { "output": "Basic Gate", "input": ["Red Pipe Wire", "Redstone Chipset"], + "pattern": "... .1. .0.", "tools": ["Assembly Table", "Laser"] }, { "output": [[8, "Blue Pipe Wire"]], "input": ["Iron Ingot", "Lapis Lazuli", "Redstone"], + "pattern": ".2. .1. .0.", "tools": ["Assembly Table", "Laser"] }, { "output": "Blueprint", "input": [[8, "Paper"], "Lapis Lazuli"], + "pattern": "000 010 000", "tools": "Crafting Table" }, { "output": "Blueprint Library", "input": [[8, "Blueprint"], "Bookshelf"], + "pattern": "000 010 000", "tools": "Crafting Table" }, { "output": "Builder", "input": [[2, "Dandelion Yellow"], [2, "Diamond Gear"], [2, "Ink Sac"], "Chest", "Crafting Table", "Landmark"], + "pattern": "252 040 131", "tools": "Crafting Table" }, { "output": "Charging Table", "input": [[6, "Obsidian"], "Gold Gear", "Redstone", "Redstone Chipset"], + "pattern": "020 030 010", "tools": "Crafting Table" }, { "output": "Chute", "input": [[5, "Iron Ingot"], "Chest", "Cobblestone Gear"], + "pattern": "010 020 .0.", "tools": "Crafting Table" }, { "output": "Cobblestone Fluid Pipe", - "input": ["Cobblestone Transport Pipe", "Pipe Sealant"] + "input": ["Cobblestone Transport Pipe", "Pipe Sealant"], + "pattern": "... .0. .1." }, { "output": "Cobblestone Gear", "input": [[4, "Cobblestone"], "Wooden Gear"], + "pattern": ".0. 010 .0.", "tools": "Crafting Table" }, { "output": "Cobblestone Kinesis Pipe", - "input": ["Cobblestone Transport Pipe", "Redstone"] + "input": ["Cobblestone Transport Pipe", "Redstone"], + "pattern": "... .0. .1." }, { "output": [[8, "Cobblestone Transport Pipe"]], "input": [[2, "Cobblestone"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Combustion Engine", "input": [[3, "Iron Ingot"], [2, "Iron Gear"], "Glass", "Piston"], + "pattern": "000 .2. 131", "tools": "Crafting Table" }, { "output": [[8, "Daizuli Transport Pipe"]], "input": ["Block of Lapis Lazuli", "Diamond", "Glass"], + "pattern": "... 021 ...", "tools": "Crafting Table" }, { "output": "Diamond AND Gate", "input": ["Blue Pipe Wire", "Diamond Chipset", "Green Pipe Wire", "Red Pipe Wire", "Yellow Pipe Wire"], + "pattern": "1.. 34. 02.", "tools": ["Assembly Table", "Laser"] }, { "output": "Diamond Chipset", "input": ["Diamond", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Diamond Fluid Pipe", - "input": ["Diamond Transport Pipe", "Pipe Sealant"] + "input": ["Diamond Transport Pipe", "Pipe Sealant"], + "pattern": "... .0. .1." }, { "output": "Diamond Gear", "input": [[4, "Diamond"], "Gold Gear"], + "pattern": ".0. 010 .0.", "tools": "Crafting Table" }, { "output": "Diamond Kinesis Pipe", - "input": ["Diamond Transport Pipe", "Redstone"] + "input": ["Diamond Transport Pipe", "Redstone"], + "pattern": "... .0. .1." }, { "output": "Diamond OR Gate", "input": ["Blue Pipe Wire", "Diamond Chipset", "Green Pipe Wire", "Red Pipe Wire", "Yellow Pipe Wire"], + "pattern": "1.. 34. 02.", "tools": ["Assembly Table", "Laser"] }, { "output": "Diamond Transport Pipe", "input": [[2, "Diamond"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Docking Station", "input": [[3, "Iron Ingot"], "Gold Chipset"], + "pattern": "... .0. 010", "tools": "Crafting Table" }, { "output": "Emerald Chipset", "input": ["Emerald", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Emerald Fluid Pipe", - "input": ["Emerald Transport Pipe", "Pipe Sealant"] + "input": ["Emerald Transport Pipe", "Pipe Sealant"], + "pattern": "... .0. .1." }, { "output": "Emerald Kinesis Pipe", - "input": ["Emerald Transport Pipe", "Redstone"] + "input": ["Emerald Transport Pipe", "Redstone"], + "pattern": "... .1. .0." }, { "output": [[8, "Emerald Transport Pipe"]], "input": [[2, "Emerald"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": [[8, "Emzuli Transport Pipe"]], "input": ["Block of Lapis Lazuli", "Emerald", "Glass"], + "pattern": "... 021 ...", "tools": "Crafting Table" }, { "output": "Facade", "input": [[3, "Structure Pipe"], "source block"], + "pattern": "... .1. 000", "tools": ["Assembly Table", "Laser"] }, { "output": "Filler", "input": [[2, "Dandelion Yellow"], [2, "Gold Gear"], [2, "Ink Sac"], "Chest", "Crafting Table", "Landmark"], + "pattern": "252 040 131", "tools": "Crafting Table" }, { "output": "Filtered Buffer", "input": [[6, "Oak Wood Planks"], "Chest", "Diamond Transport Pipe", "Piston"], + "pattern": "020 010 030", "tools": "Crafting Table" }, { "output": "Flood Gate", "input": [[4, "Iron Ingot"], [3, "Iron Bars"], "Iron Gear", "Tank"], + "pattern": "020 131 010", "tools": "Crafting Table" }, { "output": "Gate Copier", - "input": ["Redstone Chipset", "Wrench"] + "input": ["Redstone Chipset", "Wrench"], + "pattern": "... .0. .1." }, { "output": "Gold AND Gate", "input": ["Blue Pipe Wire", "Gold Chipset", "Red Pipe Wire"], + "pattern": "1.. 20. ...", "tools": ["Assembly Table", "Laser"] }, { "output": "Gold Chipset", "input": ["Gold Ingot", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Gold Gear", "input": [[4, "Gold Ingot"], "Iron Gear"], + "pattern": ".0. 010 .0.", "tools": "Crafting Table" }, { "output": "Gold OR Gate", "input": ["Blue Pipe Wire", "Gold Chipset", "Red Pipe Wire"], + "pattern": "1.. 20. ...", "tools": ["Assembly Table", "Laser"] }, { "output": "Golden Fluid Pipe", - "input": ["Golden Transport Pipe", "Pipe Sealant"] + "input": ["Golden Transport Pipe", "Pipe Sealant"], + "pattern": "... .0. .1." }, { "output": "Golden Kinesis Pipe", - "input": ["Golden Transport Pipe", "Redstone"] + "input": ["Golden Transport Pipe", "Redstone"], + "pattern": "... .0. .1." }, { "output": [[8, "Golden Transport Pipe"]], "input": [[2, "Gold Ingot"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": [[8, "Green Pipe Wire"]], "input": ["Cactus Green", "Iron Ingot", "Redstone"], + "pattern": ".0. .2. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Integration Table", "input": [[6, "Obsidian"], "Diamond Gear", "Redstone", "Redstone Chipset"], + "pattern": "020 030 010", "tools": "Crafting Table" }, { "output": "Iron AND Gate", "input": ["Iron Chipset", "Red Pipe Wire"], + "pattern": "0.. 1.. ...", "tools": ["Assembly Table", "Laser"] }, { "output": "Iron Chipset", "input": ["Iron Ingot", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Iron Fluid Pipe", - "input": ["Iron Transport Pipe", "Pipe Sealant"] + "input": ["Iron Transport Pipe", "Pipe Sealant"], + "pattern": "... .0. .1." }, { "output": "Iron Gear", "input": [[4, "Iron Ingot"], "Cobblestone Gear"], + "pattern": ".0. 010 .0.", "tools": "Crafting Table" }, { "output": "Iron Kinesis Pipe", - "input": ["Iron Transport Pipe", "Redstone"] + "input": ["Iron Transport Pipe", "Redstone"], + "pattern": "... .0. .1." }, { "output": "Iron OR Gate", "input": ["Iron Chipset", "Red Pipe Wire"], + "pattern": "0.. 1.. ...", "tools": ["Assembly Table", "Laser"] }, { "output": [[8, "Iron Transport Pipe"]], "input": [[2, "Iron Ingot"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Landmark", "input": ["Lapis Lazuli", "Redstone Torch"], + "pattern": "... .0. .1.", "tools": "Crafting Table" }, { "output": "Laser", "input": [[5, "Redstone"], [2, "Diamond"], [2, "Obsidian"]], + "pattern": "200 110 200", "tools": "Crafting Table" }, { "output": [[8, "Lazuli Transport Pipe"]], "input": [[2, "Block of Lapis Lazuli"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Mining Well", "input": [[6, "Iron Ingot"], "Iron Gear", "Iron Pickaxe", "Redstone"], + "pattern": "030 010 020", "tools": "Crafting Table" }, { "output": [[8, "Obsidian Transport Pipe"]], "input": [[2, "Obsidian"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Path Mark", - "input": ["Cactus Green", "Redstone Torch"] + "input": ["Cactus Green", "Redstone Torch"], + "pattern": "... .0. .1." }, { "output": [[6, "Pipe Facade"]], "input": [[3, "Support Pipe"], "Stone"], + "pattern": "... .1. 000", "tools": ["Assembly Table", "Laser"] }, { "output": "Pipe Plug", "input": "Support Pipe", + "pattern": "... .0. ...", "tools": ["Assembly Table", "Laser"] }, { "output": "Pipe Sealant", - "input": "Cactus Green" + "input": "Cactus Green", + "pattern": "... .0. ..." }, { "output": "Pulsating Chipset", "input": ["Ender Pearl", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Pump", - "input": ["Mining Well", "Tank"] + "input": ["Mining Well", "Tank"], + "pattern": "... .1. .0." }, { "output": "Quarry", "input": [[3, "Iron Gear"], [2, "Diamond Gear"], [2, "Gold Gear"], "Diamond Pickaxe", "Redstone"], + "pattern": "040 202 131", "tools": "Crafting Table" }, { "output": "Quartz Chipset", "input": ["Nether Quartz", "Redstone"], + "pattern": "... .0. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Quartz Kinesis Pipe", - "input": ["Quartz Transport Pipe", "Redstone"] + "input": ["Quartz Transport Pipe", "Redstone"], + "pattern": "... .0. .1." }, { "output": [[8, "Quartz Transport Pipe"]], "input": [[2, "Block of Quartz"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": [[8, "Red Pipe Wire"]], "input": ["Iron Ingot", "Redstone", "Rose Red"], + "pattern": ".2. .1. .0.", "tools": ["Assembly Table", "Laser"] }, { "output": "Redstone Chipset", "input": "Redstone", + "pattern": "... .0. ...", "tools": ["Assembly Table", "Laser"] }, { "output": "Redstone Comp Chipset", "input": ["Redstone", "Redstone Comparator"], + "pattern": "... .1. .0.", "tools": ["Assembly Table", "Laser"] }, { "output": "Redstone Engine", "input": [[3, "Oak Wood Planks"], [2, "Wooden Gear"], "Glass", "Piston"], + "pattern": "000 .2. 131", "tools": "Crafting Table" }, { "output": "Refinery", "input": [[3, "Tank"], [2, "Redstone Torch"], "Diamond Gear"], + "pattern": "... 101 020", "tools": "Crafting Table" }, { "output": "Requester", "input": [[4, "Iron Ingot"], [2, "Iron Gear"], "Chest", "Piston", "Redstone"], + "pattern": "030 121 040", "tools": "Crafting Table" }, { "output": "Sandstone Fluid Pipe", - "input": ["Pipe Sealant", "Sandstone Transport Pipe"] + "input": ["Pipe Sealant", "Sandstone Transport Pipe"], + "pattern": "... .1. .0." }, { "output": [[8, "Sandstone Transport Pipe"]], "input": [[2, "Sandstone"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Stirling Engine", "input": [[3, "Cobblestone"], [2, "Cobblestone Gear"], "Glass", "Piston"], + "pattern": "000 .2. 131", "tools": "Crafting Table" }, { "output": "Stone Fluid Pipe", - "input": ["Pipe Sealant", "Stone Transport Pipe"] + "input": ["Pipe Sealant", "Stone Transport Pipe"], + "pattern": "... .1. .0." }, { "output": "Stone Kinesis Pipe", - "input": ["Redstone", "Stone Transport Pipe"] + "input": ["Redstone", "Stone Transport Pipe"], + "pattern": "... .1. .0." }, { "output": [[8, "Stone Pipe"]], "input": [[2, "Stone"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": [[8, "Stripes Transport Pipe"]], "input": [[2, "Gold Gear"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Support Pipe", - "input": ["Cobblestone Transport Pipe", "Gravel"] + "input": ["Cobblestone Transport Pipe", "Gravel"], + "pattern": "... .1. .0." }, { "output": "Tank", "input": [[8, "Glass"]], + "pattern": "000 0.0 000", "tools": "Crafting Table" }, { "output": "Template", "input": [[8, "Paper"], "Ink Sac"], + "pattern": "000 010 000", "tools": "Crafting Table" }, { "output": "Void Fluid Pipe", - "input": ["Pipe Sealant", "Void Transport Pipe"] + "input": ["Pipe Sealant", "Void Transport Pipe"], + "pattern": "... .1. .0." }, { "output": [[8, "Void Transport Pipe"]], "input": ["Glass", "Ink Sac", "Redstone"], + "pattern": "... 102 ...", "tools": "Crafting Table" }, { "output": "Wooden Fluid Pipe", - "input": ["Pipe Sealant", "Wooden Transport Pipe"] + "input": ["Pipe Sealant", "Wooden Transport Pipe"], + "pattern": "... .1. .0." }, { "output": "Wooden Gear", "input": [[4, "Stick"]], + "pattern": ".0. 0.0 .0.", "tools": "Crafting Table" }, { "output": "Wooden Kinesis Pipe", - "input": ["Redstone", "Wooden Transport Pipe"] - }, { - "output": "Wooden Kinesis Pipe", - "input": ["Redstone", "Wooden Transport Pipe"] + "input": ["Redstone", "Wooden Transport Pipe"], + "pattern": "... .1. .0." }, { "output": [[8, "Wooden Transport Pipe"]], "input": [[2, "Oak Wood Planks"], "Glass"], + "pattern": "... 010 ...", "tools": "Crafting Table" }, { "output": "Wrench", "input": [[3, "Iron Ingot"], "Cobblestone Gear"], + "pattern": "0.0 .1. .0.", "tools": "Crafting Table" }, { "output": [[8, "Yellow Pipe Wire"]], "input": ["Dandelion Yellow", "Iron Ingot", "Redstone"], + "pattern": ".0. .2. .1.", "tools": ["Assembly Table", "Laser"] }, { "output": "Zone Planner", "input": [[4, "Iron Ingot"], [2, "Gold Gear"], "Diamond Gear", "Empty Map", "Redstone"], + "pattern": "040 131 020", "tools": "Crafting Table" } ] diff --git a/src/scripts/constants.coffee b/src/scripts/constants.coffee index b5267506d..3ff229006 100644 --- a/src/scripts/constants.coffee +++ b/src/scripts/constants.coffee @@ -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 diff --git a/src/scripts/controllers/crafting_grid_controller.coffee b/src/scripts/controllers/crafting_grid_controller.coffee index 97f48bcbc..f726b8a50 100644 --- a/src/scripts/controllers/crafting_grid_controller.coffee +++ b/src/scripts/controllers/crafting_grid_controller.coffee @@ -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 diff --git a/src/scripts/controllers/crafting_table_controller.coffee b/src/scripts/controllers/crafting_table_controller.coffee index 4bdc97b33..ba40b2405 100644 --- a/src/scripts/controllers/crafting_table_controller.coffee +++ b/src/scripts/controllers/crafting_table_controller.coffee @@ -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 ###################################################################### diff --git a/src/scripts/controllers/item_page_controller.coffee b/src/scripts/controllers/item_page_controller.coffee index 62f9b6211..5650d94ed 100644 --- a/src/scripts/controllers/item_page_controller.coffee +++ b/src/scripts/controllers/item_page_controller.coffee @@ -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 diff --git a/src/scripts/controllers/stack_controller.coffee b/src/scripts/controllers/stack_controller.coffee index 759b4e9e4..1b71144ca 100644 --- a/src/scripts/controllers/stack_controller.coffee +++ b/src/scripts/controllers/stack_controller.coffee @@ -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 diff --git a/src/scripts/main.coffee b/src/scripts/main.coffee index 22e0a36b6..316d3a8d9 100644 --- a/src/scripts/main.coffee +++ b/src/scripts/main.coffee @@ -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 diff --git a/src/scripts/models/crafting_grid.coffee b/src/scripts/models/crafting_grid.coffee index 42be1f37a..9426bf177 100644 --- a/src/scripts/models/crafting_grid.coffee +++ b/src/scripts/models/crafting_grid.coffee @@ -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 diff --git a/src/scripts/models/crafting_table.coffee b/src/scripts/models/crafting_table.coffee index aa037278b..673d66c04 100644 --- a/src/scripts/models/crafting_table.coffee +++ b/src/scripts/models/crafting_table.coffee @@ -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? diff --git a/src/scripts/models/item.coffee b/src/scripts/models/item.coffee index 1c2b6f566..1216ff91b 100644 --- a/src/scripts/models/item.coffee +++ b/src/scripts/models/item.coffee @@ -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: -> diff --git a/src/scripts/models/mod_pack.coffee b/src/scripts/models/mod_pack.coffee index 653911f5c..467a68b15 100644 --- a/src/scripts/models/mod_pack.coffee +++ b/src/scripts/models/mod_pack.coffee @@ -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 diff --git a/src/scripts/models/mod_version_parser.coffee b/src/scripts/models/mod_version_parser.coffee index d25fa8842..3be60ec38 100644 --- a/src/scripts/models/mod_version_parser.coffee +++ b/src/scripts/models/mod_version_parser.coffee @@ -10,7 +10,6 @@ Logger = require '../logger' ModVersion = require './mod_version' Recipe = require './recipe' Stack = require './stack' -util = require 'util' ######################################################################################################################## diff --git a/src/templates/crafting_table.jade b/src/templates/crafting_table.jade index acf877173..17cee0eaa 100644 --- a/src/templates/crafting_table.jade +++ b/src/templates/crafting_table.jade @@ -16,5 +16,7 @@ table.view__crafting_grid .tool: p .output - + a: img + p.quantity + p.multiplier .next diff --git a/test/crafting_plan.test.coffee b/test/crafting_plan.test.coffee index 7b6c5b386..1d350a3c0 100644 --- a/test/crafting_plan.test.coffee +++ b/test/crafting_plan.test.coffee @@ -32,7 +32,7 @@ describe 'CraftingPlan', -> ] } - plan = new CraftingPlan modPack + plan = new CraftingPlan modPack:modPack describe 'craft', -> diff --git a/test/mod_pack.test.coffee b/test/mod_pack.test.coffee index f23419a0d..4bb01e43d 100644 --- a/test/mod_pack.test.coffee +++ b/test/mod_pack.test.coffee @@ -21,6 +21,7 @@ describe 'ModPack', -> minecraft = new ModVersion name:'Minecraft', version:'1.7.10' minecraft.addItem new Item name:'Wool' minecraft.addItem new Item name:'Bed', recipes:[''] + minecraft.registerSlug 'iron_chestplate', 'Iron Chestplate' buildcraft = new ModVersion name:'Buildcraft', version:'4.0' buildcraft.addItem new Item name:'Stone Gear', recipes:[''] @@ -70,6 +71,34 @@ describe 'ModPack', -> item = modPack.findItemByName 'Stone Gear', includeDisabled:true item.name.should.equal 'Stone Gear' + describe 'findItemDisplay', -> + + it 'returns all data for a regular Minecraft item', -> + display = modPack.findItemDisplay 'bed' + display.iconUrl.should.equal '/data/minecraft/images/bed.png' + display.itemUrl.should.equal '/item/Bed' + display.itemName.should.equal 'Bed' + display.modSlug.should.equal 'minecraft' + + it 'returns all data for an item in an enabled mod', -> + buildcraft.enabled = true + display = modPack.findItemDisplay 'stone_gear' + display.iconUrl.should.equal '/data/buildcraft/images/stone_gear.png' + display.itemUrl.should.equal '/item/Stone%20Gear' + display.itemName.should.equal 'Stone Gear' + display.modSlug.should.equal 'buildcraft' + + it 'returns data even for a disabled mod', -> + display = modPack.findItemDisplay 'stone_gear' + display.itemName.should.equal 'Stone Gear' + + it 'assumes an unfound item is from Minecraft', -> + display = modPack.findItemDisplay 'iron_chestplate' + display.iconUrl.should.equal '/data/minecraft/images/iron_chestplate.png' + display.itemUrl.should.equal '/item/Iron%20Chestplate' + display.itemName.should.equal 'Iron Chestplate' + display.modSlug.should.equal 'minecraft' + describe 'gatherRecipeNames', -> it 'finds all registered item names', ->