* 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
31 lines
859 B
CoffeeScript
31 lines
859 B
CoffeeScript
###
|
|
Crafting Guide - inventory_parser.coffee
|
|
|
|
Copyright (c) 2014 by Redwood Labs
|
|
All rights reserved.
|
|
###
|
|
|
|
Inventory = require './inventory'
|
|
Item = require './item'
|
|
|
|
########################################################################################################################
|
|
|
|
module.exports = class InventoryParser
|
|
|
|
@ITEM_REGEX = /^([0-9]+)(.*)$/
|
|
|
|
parse: (data, inventory=null)->
|
|
inventory ?= new Inventory
|
|
return inventory if not data? or data.length is 0
|
|
|
|
lines = data.split '\n'
|
|
for line in lines
|
|
match = InventoryParser.ITEM_REGEX.exec line
|
|
name = if match? then match[2].trim() else line
|
|
quantity = if match? then parseInt(match[1]) else 1
|
|
|
|
if name.length > 0
|
|
inventory.add _.slugify(name), quantity
|
|
|
|
return inventory
|