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:
Andrew Miner
2015-01-03 20:08:11 -08:00
parent 392c410df8
commit 0d25ac723d
24 changed files with 260 additions and 285 deletions
+5 -20
View File
@@ -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}"