From f51082a1cb69fb9dbf6054e5f0140cee22ade59c Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Wed, 7 Jan 2015 08:31:53 -0800 Subject: [PATCH] Add ability to craft multipl items at once * Remove the old crafting table view * Complete UI/UX of the inventory view --- src/css/main.scss | 2 +- src/css/templates/item_page.scss | 4 +- src/images/boots.png | Bin 0 -> 317 bytes src/images/chest_front.png | Bin 1411 -> 489 bytes src/images/fishing_rod.png | Bin 0 -> 275 bytes .../controllers/item_page_controller.coffee | 34 ++++++++--- src/scripts/models/crafting_plan.coffee | 57 +++++++++++------- src/scripts/models/crafting_table.coffee | 2 + src/scripts/models/item_page.coffee | 8 +-- src/templates/item_page.jade | 2 +- 10 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 src/images/boots.png create mode 100644 src/images/fishing_rod.png diff --git a/src/css/main.scss b/src/css/main.scss index 16ec412a7..17e8466a3 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -180,7 +180,7 @@ label { .view__header { background: $color-brick-light url('/images/stone_brick_light.png'); position: relative; height: 10em; - margin: 5em 0 2em 0; + margin-top: 5em; h1 { position: relative; top: -3em; left: -3em; } diff --git a/src/css/templates/item_page.scss b/src/css/templates/item_page.scss index 87a135f0f..209ffe659 100644 --- a/src/css/templates/item_page.scss +++ b/src/css/templates/item_page.scss @@ -6,8 +6,10 @@ All rights reserved. */ .view__item_page { + & > div { display: inline-block; + margin-top: 2em; padding: 0 2em; position: relative; vertical-align: top; @@ -15,5 +17,5 @@ All rights reserved. .view__inventory { width: 50%; height: 26em; } - .view__crafting_table, .view__mod_pack { margin-top: 2em; width: 100%; } + .view__mod_pack { margin-top: 2em; width: 100%; } } diff --git a/src/images/boots.png b/src/images/boots.png new file mode 100644 index 0000000000000000000000000000000000000000..d6d18eca894b15206f5e52f24901b71c8f16f073 GIT binary patch literal 317 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEU}W)haSW-r^>*e#-WCM`*VN6v z0WF;2+D2jrPipBjS?!V1Z0fe%@qA`Z3TKwt$Gy^#b0>)ZJK=O0XaWPn0b#?fthct^ z^`6&nILrF=(+b;KR)q&IneJ_!Ie(ewpM5&r68(=OOb^Px>i)T83Xe7eBgc+)>>0b( zS)X~a|GGL8#{%{%hUY&o72dPUPSAmYNuYs&MFFVDf#E;vzQyMmu9xmDUB9mITxTJN zW6$q>;-Amnl@?%Rxxn0Ky#D;t(r4%G7GHkxYZrS)TcW_@J9`;{X4o#!X}0_loA5Gr z?!Ua(Jk{?bfyN!EoN>o4;r6ygO-pC$AC205eb0Hj1`Y+V9~c(=Wa$4I?S1ExY(7Z9 M)78&qol`;+08om6+yDRo literal 0 HcmV?d00001 diff --git a/src/images/chest_front.png b/src/images/chest_front.png index 72973f7db960060173013934bd045c33427563d4..3e1782e43c0ba92233d79f68cd7ea4709fa523bc 100644 GIT binary patch literal 489 zcmVi5QX~`ElSg%Z5pkysfuo_g@P4a>7s~#AgLgT;=-b(D?wBQK}GNdL~-FuYBwiG z$&j0^cfz*{lj*nUT+W@`T5BG(m%~)Jp6RU20h4+Y7U~|zsi=zn@HLzTPsdIw@8>?a z-FLx5uL8Iy!{2_Mxqxe?Dh^Oldqr294e)kS2K=$a{mvNZw(^N^4fmJe{x#15Dr&DN z57X7bWGb(xbuiraz=!a#H1~NqEQ9BxS|T%57pSPcq8uPN1S~bGsRX_Y?t~}sOF-(w zzstDA0#H$VMR}M8yA9Cassnz{MC(4d6rRrFIJoFe1F0t?PQ8j+CE96*fDhrvsG3TD zqXeRMK9Rv@5t#J6-i!GaN>tQZQR#9g!NHap~PhAU?O4C zM_M{?xK>dW{X0x1fA*}4G-;_O!IwJ~Rnd_shZ1R7m36t574E|UMNCgBYL#f#P$C`v zSqDoRG7cr;EmTFV73Ct6MXpqDQo{#3*WC0%prR@|66Hgc35c3kN<^-442bLfatyzp fa0)<0trh(Sy2`LtvI!&I00000NkvXXu0mjfrfS`O literal 1411 zcmV-}1$_F6P)4Tx062|}Ro!pfR1`m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b?5DZJbd`o z138APLX^M*YYJ$9qLUFY0` R-}L|h002ovPDHLkV1hAnu^9jW diff --git a/src/images/fishing_rod.png b/src/images/fishing_rod.png new file mode 100644 index 0000000000000000000000000000000000000000..1c858c8d85b31753ed9d0478b0c107e78fb10ec1 GIT binary patch literal 275 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=w>(`OLn>~)y|t0I*+76b;MbMR z%*m`LSn@8V^rlSJIk3wwmrKWm;r1T=Sl6%dg;tEQ>PnXaoHz>efSNCqJ$(Ln)|tKg zRhStV8n$uQ-`}1B6b>*yaO==jc_#*jIXnvCKR&;jd{WmEC_aUE!`DQR%1sRa_C5hA zG&^un-vG$ipnu?=Hy@CZ$|&=9;iC_0`56wJWGM2^lR17 - @model.table.name = params.name if params.name? - @model.table.quantity = params.quantity if params.quantity? + return unless params.name? + + item = @model.modPack.findItemByName params.name + return unless item? and item.isCraftable + + quantity = if params.quantity? then parseInt(params.quantity) else 1 + @model.want.add item.slug, quantity # BaseController Overrides ##################################################################### onDidRender: -> - options = model:@model.table.have, modPack:@model.modPack, editable:true - @haveController = @addChild InventoryController, '.view__inventory.have', options + options = + editable: true, + model: @model.plan.have, + modPack: @model.modPack, + title: 'Items you have' + @haveController = @addChild InventoryController, '.have', options + + options = + editable: true + icon: '/images/fishing_rod.png', + model: @model.plan.want, + modPack: @model.modPack, + title: 'Items you want' + @wantController = @addChild InventoryController, '.want', options options = editable: false - icon: '/images/workbench_top.png', - model: @model.table.want, + icon: '/images/boots.png', + model: @model.plan.need, modPack: @model.modPack, - title: 'Items to Craft' - @wantController = @addChild InventoryController, '.view__inventory.want', options + title: "Items you'll need" + @needController = @addChild InventoryController, '.need', options @modPackController = @addChild ModPackController, '.view__mod_pack', model:@model.modPack - @tableController = @addChild CraftingTableController, '.view__crafting_table', model:@model.table super diff --git a/src/scripts/models/crafting_plan.coffee b/src/scripts/models/crafting_plan.coffee index 577d65fcf..a3dad62ad 100644 --- a/src/scripts/models/crafting_plan.coffee +++ b/src/scripts/models/crafting_plan.coffee @@ -14,41 +14,57 @@ module.exports = class CraftingPlan constructor: (@modPack, includingTools)-> if not @modPack then throw new Error 'modPack is required' @includingTools = if includingTools then true else false + + @have = new Inventory + @want = new Inventory + @need = new Inventory + @result = new Inventory + + @have.on 'change', => @craft() + @want.on 'change', => @craft() + @clear() # Public Methods ############################################################################### clear: -> - @make = new Inventory - @need = new Inventory - @result = new Inventory - @steps = [] - @_expected = new Inventory - @_pending = null + @steps = [] + @_expected = new Inventory + @_pending = null + + @need.clear() + @result.clear() return this - craft: (name, quantity=1, have=null)-> - logger.trace "craft(#{name}, #{quantity}, #{have})" - - item = @modPack.findItemByName name - if not item? then throw new Error "cannot find an item named: #{name}" - + craft: -> + logger.trace "starting crafting plan for: #{@want} starting with #{@have}" @clear() - @result.addInventory(have) if have? + return if @want.isEmpty - @_expected.add item.slug, quantity - @_pending = @_expected.clone() + @want.each (stack)=> + @_expected = @want.clone() + @_pending = @want.clone() + @result.addInventory @have + + @_need = new Inventory while not @_pending.isEmpty @_processPending() + @need.addInventory @_need @steps.reverse() # Object Overrides ############################################################################# toString: -> - return "#{@constructor.name} { need:#{@need}, make:#{@make}, result:#{@result} }" + return "#{@constructor.name} { + have:#{@have}, + want:#{@want}, + need:#{@_need}, + result:#{@result}, + steps:#{@steps} + }" # Private Methods ############################################################################## @@ -88,18 +104,17 @@ module.exports = class CraftingPlan @result.remove stack.itemSlug, quantityUsed @_pending.add stack.itemSlug, quantityNeeded - @need.add stack.itemSlug, quantityNeeded + @_need.add stack.itemSlug, quantityNeeded _processOutputStack: (stack)-> - quantityMissing = @need.quantityOf stack.itemSlug + quantityMissing = @_need.quantityOf stack.itemSlug quantityUsed = Math.min quantityMissing, stack.quantity quantityLeft = stack.quantity - quantityUsed logger.trace "processing output:#{stack.itemSlug}, m:#{quantityMissing}, u:#{quantityUsed}, l:#{quantityLeft}" - @make.add stack.itemSlug, stack.quantity - @need.remove stack.itemSlug, quantityUsed + @_need.remove stack.itemSlug, quantityUsed @result.add stack.itemSlug, quantityLeft _totalQuantityOf: (itemSlug)-> - return @result.quantityOf(itemSlug) - @need.quantityOf(itemSlug) + return @result.quantityOf(itemSlug) - @_need.quantityOf(itemSlug) diff --git a/src/scripts/models/crafting_table.coffee b/src/scripts/models/crafting_table.coffee index 9bac60837..d55e577f5 100644 --- a/src/scripts/models/crafting_table.coffee +++ b/src/scripts/models/crafting_table.coffee @@ -24,6 +24,8 @@ module.exports = class CraftingTable extends BaseModel attributes.want ?= new Inventory super attributes, options + Object.defineProperty @prototype, 'need', -> @plan?.need + # Public Methods ############################################################################### craft: -> diff --git a/src/scripts/models/item_page.coffee b/src/scripts/models/item_page.coffee index fe23b1136..eb834d1af 100644 --- a/src/scripts/models/item_page.coffee +++ b/src/scripts/models/item_page.coffee @@ -5,9 +5,9 @@ Copyright (c) 2014-2015 by Redwood Labs All rights reserved. ### -BaseModel = require './base_model' -CraftingTable = require './crafting_table' -ModPack = require './mod_pack' +BaseModel = require './base_model' +CraftingPlan = require './crafting_plan' +ModPack = require './mod_pack' ######################################################################################################################## @@ -15,5 +15,5 @@ module.exports = class ItemPage extends BaseModel constructor: (attributes={}, options={})-> attributes.modPack ?= new ModPack - attributes.table ?= new CraftingTable modPack:attributes.modPack + attributes.plan ?= new CraftingPlan attributes.modPack super attributes, options diff --git a/src/templates/item_page.jade b/src/templates/item_page.jade index 784a18678..6bf12ccc9 100644 --- a/src/templates/item_page.jade +++ b/src/templates/item_page.jade @@ -8,6 +8,6 @@ .view__item_page .view__inventory.have .view__inventory.want + .view__inventory.need - .view__crafting_table .view__mod_pack