Complete refactoring to move Recipes into Items
* Changed "version" to "dataVersion" in data format * Changed the "modName" and "modVersion" fields on the ModVersion class to remove the "mod" prefix and changed the data format to match * Change the Stack class to use the itemSlug instead of the item itself * Update the ModVersion and ModPack classes to include methods for recording a correspondence between slugs and names. Update code which displays items from stacks to use these methods to determine display names. * Add a reference from Recipe back to the item it creates
This commit is contained in:
@@ -10,40 +10,25 @@ All rights reserved.
|
||||
module.exports = class Stack
|
||||
|
||||
constructor: (attributes={})->
|
||||
if not attributes.item? then throw new Error 'item is required'
|
||||
if not attributes.itemSlug? then throw new Error 'attributes.itemSlug is required'
|
||||
attributes.quantity ?= 1
|
||||
|
||||
@item = attributes.item
|
||||
@itemSlug = attributes.itemSlug
|
||||
@quantity = attributes.quantity
|
||||
|
||||
Object.defineProperty @prototype, 'name', get:-> @item?.name
|
||||
|
||||
Object.defineProperty @prototype, 'stackQuantity', get:@getStackQuantity
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
canMerge: (stack)->
|
||||
return @item.slug is stack.item.slug
|
||||
return @itemSlug is stack.itemSlug
|
||||
|
||||
merge: (stack)->
|
||||
if not @canMerge stack
|
||||
throw new Error "this stack of #{@item.name} cannot merge a stack of #{@stack.name}"
|
||||
throw new Error "this stack of #{@itemSlug} cannot merge a stack of #{@stack.itemSlug}"
|
||||
|
||||
@quantity += stack.quantity
|
||||
return this
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getStackQuantity: ->
|
||||
count = 0
|
||||
extra = @quantity
|
||||
while extra > @item.stackSize
|
||||
extra -= @item.stackSize
|
||||
count += 1
|
||||
|
||||
return count:count, extra:extra
|
||||
|
||||
# Object Overrides #############################################################################
|
||||
|
||||
toString: ->
|
||||
return "#{@quantity} #{@item.name}"
|
||||
return "#{@quantity} #{@itemSlug}"
|
||||
|
||||
Reference in New Issue
Block a user