Add ability to craft multipl items at once
* Remove the old crafting table view * Complete UI/UX of the inventory view
This commit is contained in:
+1
-1
@@ -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; }
|
||||
|
||||
|
||||
@@ -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%; }
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 317 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 489 B |
Binary file not shown.
|
After Width: | Height: | Size: 275 B |
@@ -23,23 +23,39 @@ module.exports = class ItemPageController extends BaseController
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
setParams: (params)->
|
||||
@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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
.view__item_page
|
||||
.view__inventory.have
|
||||
.view__inventory.want
|
||||
.view__inventory.need
|
||||
|
||||
.view__crafting_table
|
||||
.view__mod_pack
|
||||
|
||||
Reference in New Issue
Block a user