Initial implementation of item page (disabled)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
###
|
||||
Crafting Guide - item_page.coffee
|
||||
|
||||
Copyright (c) 2015 by Redwood Labs
|
||||
All rights reserved.
|
||||
###
|
||||
|
||||
BaseModel = require './base_model'
|
||||
CraftingPlan = require './crafting_plan'
|
||||
Event = require '../constants'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class ItemPage extends BaseModel
|
||||
|
||||
constructor: (attributes={}, options={})->
|
||||
if not attributes.modPack? then throw new Error 'attributes.modPack is required'
|
||||
attributes.item ?= null
|
||||
super attributes, options
|
||||
|
||||
@_plan = new CraftingPlan modPack:@modPack
|
||||
@on Event.change + ':item', => @_updateCraftingPlan()
|
||||
@_updateCraftingPlan()
|
||||
|
||||
Object.defineProperties this,
|
||||
craftingRawMaterials: {get:-> @_plan.need}
|
||||
craftingSteps: {get:-> @_plan.steps}
|
||||
similarItems: {get:=> @getSimilarItems()}
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
findSimilarItems: ->
|
||||
return null unless @item?.modVersion?
|
||||
|
||||
result = []
|
||||
@item.modVersion.eachItemInGroup @item.group, (item)=>
|
||||
return if item is @item
|
||||
result.push item
|
||||
|
||||
return null unless result.length > 0
|
||||
return result
|
||||
|
||||
findComponentInItems: ->
|
||||
return null unless @item?
|
||||
|
||||
itemSlug = @item.slug
|
||||
result = {}
|
||||
@modPack.eachMod (mod)->
|
||||
mod.eachItem (item)->
|
||||
item.eachRecipe (recipe)->
|
||||
for stack in recipe.input
|
||||
if stack.slug is itemSlug
|
||||
result[item.slug] = item
|
||||
|
||||
result = _.values(result).sort (a, b)-> a.compareTo b
|
||||
return null unless result.length > 0
|
||||
return result
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_updateCraftingPlan: ->
|
||||
@_plan.clear()
|
||||
|
||||
if @item?
|
||||
@_plan.want.add @item.slug
|
||||
@_plan.craft()
|
||||
@@ -45,6 +45,8 @@ module.exports = class ModPack extends BaseModel
|
||||
return null
|
||||
|
||||
findItemDisplay: (slug)->
|
||||
if not slug? then return null
|
||||
|
||||
result = {}
|
||||
item = @findItem slug, includeDisabled:true
|
||||
if item?
|
||||
|
||||
@@ -39,6 +39,12 @@ module.exports = class ModVersion extends BaseModel
|
||||
@registerSlug item.slug, item.name
|
||||
return this
|
||||
|
||||
allItemsInGroup: (group)->
|
||||
result = []
|
||||
@eachItemInGroup group, (item)-> result.push item
|
||||
return null if result.length is 0
|
||||
return result
|
||||
|
||||
compareTo: (that)->
|
||||
if this.mod? and that.mod?
|
||||
return this.mod.compareTo that.mod
|
||||
|
||||
Reference in New Issue
Block a user