Rename RecipeBook to ModVersion
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Crafting Guide - recipe_books.scss
|
Crafting Guide - mod_versions.scss
|
||||||
|
|
||||||
Copyright (c) 2014 by Redwood Labs
|
Copyright (c) 2014 by Redwood Labs
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"mod_version": "1.7.10",
|
"mod_version": "1.7.10",
|
||||||
"description": "Crafting recipes from vanilla Minecraft",
|
"description": "Crafting recipes from vanilla Minecraft",
|
||||||
"raw_materials": [
|
"raw_materials": [
|
||||||
|
"Diamond",
|
||||||
"Emerald",
|
"Emerald",
|
||||||
"Lapis Lazuli",
|
"Lapis Lazuli",
|
||||||
"Nether Quartz",
|
"Nether Quartz",
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
# Crafting Guide - recipe_book_controller.coffee
|
# Crafting Guide - mod_version_controller.coffee
|
||||||
#
|
#
|
||||||
# Copyright (c) 2014 by Redwood Labs
|
# Copyright (c) 2014 by Redwood Labs
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
@@ -10,11 +10,11 @@ BaseController = require './base_controller'
|
|||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
module.exports = class RecipeBookController extends BaseController
|
module.exports = class ModVersionController extends BaseController
|
||||||
|
|
||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
if not options.model? then throw new Error "options.model is required"
|
if not options.model? then throw new Error "options.model is required"
|
||||||
options.templateName = 'recipe_book'
|
options.templateName = 'mod_version'
|
||||||
super options
|
super options
|
||||||
|
|
||||||
# Event Methods ################################################################################
|
# Event Methods ################################################################################
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
BaseController = require './base_controller'
|
BaseController = require './base_controller'
|
||||||
{DefaultBookUrls} = require '../constants'
|
{DefaultBookUrls} = require '../constants'
|
||||||
RecipeBookController = require './recipe_book_controller'
|
ModVersionController = require './mod_version_controller'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ module.exports = class RecipeCatalogController extends BaseController
|
|||||||
@_bookControllers = []
|
@_bookControllers = []
|
||||||
for i in [@model.books.length-1..0] by -1
|
for i in [@model.books.length-1..0] by -1
|
||||||
book = @model.books[i]
|
book = @model.books[i]
|
||||||
controller = new RecipeBookController model:book
|
controller = new ModVersionController model:book
|
||||||
controller.render()
|
controller.render()
|
||||||
@_bookControllers.push controller
|
@_bookControllers.push controller
|
||||||
@$table.prepend controller.$el
|
@$table.prepend controller.$el
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
Crafting Guide - recipe_book.coffee
|
Crafting Guide - mod_version.coffee
|
||||||
|
|
||||||
Copyright (c) 2014 by Redwood Labs
|
Copyright (c) 2014 by Redwood Labs
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
@@ -10,7 +10,7 @@ BaseModel = require './base_model'
|
|||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
module.exports = class RecipeBook extends BaseModel
|
module.exports = class ModVersion extends BaseModel
|
||||||
|
|
||||||
constructor: (attributes={}, options={})->
|
constructor: (attributes={}, options={})->
|
||||||
if _.isEmpty(attributes.modName) then throw new Error 'modName cannot be empty'
|
if _.isEmpty(attributes.modName) then throw new Error 'modName cannot be empty'
|
||||||
@@ -49,7 +49,7 @@ module.exports = class RecipeBook extends BaseModel
|
|||||||
# Object Overrides #############################################################################
|
# Object Overrides #############################################################################
|
||||||
|
|
||||||
toString: ->
|
toString: ->
|
||||||
return "RecipeBook (#{@cid}) {
|
return "ModVersion (#{@cid}) {
|
||||||
enabled:#{@enabled},
|
enabled:#{@enabled},
|
||||||
modName:#{@modName},
|
modName:#{@modName},
|
||||||
modVersion:#{@modVersion},
|
modVersion:#{@modVersion},
|
||||||
+19
-19
@@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
Crafting Guide - recipe_book_parser.coffee
|
Crafting Guide - mod_version_parser.coffee
|
||||||
|
|
||||||
Copyright (c) 2014 by Redwood Labs
|
Copyright (c) 2014 by Redwood Labs
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
@@ -7,11 +7,11 @@ All rights reserved.
|
|||||||
|
|
||||||
Item = require './item'
|
Item = require './item'
|
||||||
Recipe = require './recipe'
|
Recipe = require './recipe'
|
||||||
RecipeBook = require './recipe_book'
|
ModVersion = require './mod_version'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
module.exports = class RecipeBookParser
|
module.exports = class ModVersionParser
|
||||||
|
|
||||||
@CURRENT_VERSION = '1'
|
@CURRENT_VERSION = '1'
|
||||||
|
|
||||||
@@ -28,13 +28,13 @@ module.exports = class RecipeBookParser
|
|||||||
|
|
||||||
return parser.parse data
|
return parser.parse data
|
||||||
|
|
||||||
unparse: (recipeBook, version=RecipeBookParser.CURRENT_VERSION)->
|
unparse: (ModVersion, version=ModVersionParser.CURRENT_VERSION)->
|
||||||
if not recipeBook? then throw new Error 'recipe book is required'
|
if not ModVersion? then throw new Error 'recipe book is required'
|
||||||
|
|
||||||
parser = @_parsers["#{version}"]
|
parser = @_parsers["#{version}"]
|
||||||
if not parser? then throw new Error "version #{version} is not supported"
|
if not parser? then throw new Error "version #{version} is not supported"
|
||||||
|
|
||||||
return parser.unparse recipeBook
|
return parser.unparse ModVersion
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -44,21 +44,21 @@ module.exports.V1 = class V1
|
|||||||
@_errorLocation = 'the header information'
|
@_errorLocation = 'the header information'
|
||||||
|
|
||||||
parse: (data)->
|
parse: (data)->
|
||||||
return @_parseRecipeBook data
|
return @_parseModVersion data
|
||||||
|
|
||||||
unparse: (recipeBook)->
|
unparse: (ModVersion)->
|
||||||
return @_unparseRecipeBook recipeBook
|
return @_unparseModVersion ModVersion
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_parseRecipeBook: (data)->
|
_parseModVersion: (data)->
|
||||||
if not data? then throw new Error 'recipe book data is missing'
|
if not data? then throw new Error 'recipe book data is missing'
|
||||||
if not data.version? then throw new Error 'version is required'
|
if not data.version? then throw new Error 'version is required'
|
||||||
if not data.mod_name? then throw new Error 'mod_name is required'
|
if not data.mod_name? then throw new Error 'mod_name is required'
|
||||||
if not data.mod_version? then throw new Error 'mod_version is required'
|
if not data.mod_version? then throw new Error 'mod_version is required'
|
||||||
if not _.isArray(data.recipes) then throw new Error 'recipes must be an array'
|
if not _.isArray(data.recipes) then throw new Error 'recipes must be an array'
|
||||||
|
|
||||||
book = new RecipeBook version:data.version, modName:data.mod_name, modVersion:data.mod_version
|
book = new ModVersion version:data.version, modName:data.mod_name, modVersion:data.mod_version
|
||||||
book.description = data.description or ''
|
book.description = data.description or ''
|
||||||
|
|
||||||
book.rawMaterials = data.raw_materials or []
|
book.rawMaterials = data.raw_materials or []
|
||||||
@@ -114,19 +114,19 @@ module.exports.V1 = class V1
|
|||||||
|
|
||||||
return new Item quantity:data[0], name:data[1]
|
return new Item quantity:data[0], name:data[1]
|
||||||
|
|
||||||
_unparseRecipeBook: (recipeBook)->
|
_unparseModVersion: (ModVersion)->
|
||||||
result = []
|
result = []
|
||||||
result.push '{\n'
|
result.push '{\n'
|
||||||
result.push ' "version": 1,\n'
|
result.push ' "version": 1,\n'
|
||||||
result.push ' "mod_name": "' + recipeBook.modName + '",\n'
|
result.push ' "mod_name": "' + ModVersion.modName + '",\n'
|
||||||
result.push ' "mod_version": "' + recipeBook.modVersion + '",\n'
|
result.push ' "mod_version": "' + ModVersion.modVersion + '",\n'
|
||||||
if recipeBook.description.length > 0
|
if ModVersion.description.length > 0
|
||||||
result.push ' "description": "' + recipeBook.description + '",\n'
|
result.push ' "description": "' + ModVersion.description + '",\n'
|
||||||
|
|
||||||
if recipeBook.rawMaterials.length > 0
|
if ModVersion.rawMaterials.length > 0
|
||||||
result.push ' "raw_materials": [\n'
|
result.push ' "raw_materials": [\n'
|
||||||
firstItem = true
|
firstItem = true
|
||||||
materials = recipeBook.rawMaterials.slice()
|
materials = ModVersion.rawMaterials.slice()
|
||||||
materials.sort()
|
materials.sort()
|
||||||
for material in materials
|
for material in materials
|
||||||
if not firstItem then result.push ',\n'
|
if not firstItem then result.push ',\n'
|
||||||
@@ -135,7 +135,7 @@ module.exports.V1 = class V1
|
|||||||
result.push '\n ],\n'
|
result.push '\n ],\n'
|
||||||
|
|
||||||
result.push ' "recipes": [\n'
|
result.push ' "recipes": [\n'
|
||||||
recipes = recipeBook.recipes.slice()
|
recipes = ModVersion.recipes.slice()
|
||||||
recipes.sort (a, b)->
|
recipes.sort (a, b)->
|
||||||
if a.name isnt b.name
|
if a.name isnt b.name
|
||||||
return if a.name < b.name then -1 else +1
|
return if a.name < b.name then -1 else +1
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
BaseModel = require './base_model'
|
BaseModel = require './base_model'
|
||||||
{Event} = require '../constants'
|
{Event} = require '../constants'
|
||||||
RecipeBookParser = require './recipe_book_parser'
|
ModVersionParser = require './mod_version_parser'
|
||||||
{RequiredMods} = require '../constants'
|
{RequiredMods} = require '../constants'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
@@ -18,7 +18,7 @@ module.exports = class RecipeCatalog extends BaseModel
|
|||||||
attributes.books ?= []
|
attributes.books ?= []
|
||||||
super attributes, options
|
super attributes, options
|
||||||
|
|
||||||
@_parser = new RecipeBookParser
|
@_parser = new ModVersionParser
|
||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//-
|
//-
|
||||||
//- Crafting Guide - recipe_book.jade
|
//- Crafting Guide - mod_version.jade
|
||||||
//-
|
//-
|
||||||
//- Copyright (c) 2014 by Redwood Labs
|
//- Copyright (c) 2014 by Redwood Labs
|
||||||
//- All rights reserved.
|
//- All rights reserved.
|
||||||
@@ -15,5 +15,5 @@
|
|||||||
td
|
td
|
||||||
td
|
td
|
||||||
td
|
td
|
||||||
input.recipe_book_url(placeholder="enter a URL to load another recipe book...")
|
input.mod_version_url(placeholder="enter a URL to load another recipe book...")
|
||||||
button.recipe_book_load_button Load
|
button.mod_version_load_button Load
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
###
|
###
|
||||||
|
|
||||||
RecipeBookParser = require '../src/scripts/models/recipe_book_parser'
|
RecipeBookParser = require '../src/scripts/models/mod_version_parser'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -19,15 +19,15 @@ describe 'RecipeBookParser', ->
|
|||||||
|
|
||||||
before -> parser = new RecipeBookParser.V1
|
before -> parser = new RecipeBookParser.V1
|
||||||
|
|
||||||
describe '_parseRecipeBook', ->
|
describe '_parseModVersion', ->
|
||||||
|
|
||||||
it 'requires a mod_name', ->
|
it 'requires a mod_name', ->
|
||||||
data = version:1, mod_version:'1.0', recipes:[]
|
data = version:1, mod_version:'1.0', recipes:[]
|
||||||
expect(-> parser._parseRecipeBook data).to.throw Error, 'mod_name is required'
|
expect(-> parser._parseModVersion data).to.throw Error, 'mod_name is required'
|
||||||
|
|
||||||
it 'requires a mod_version', ->
|
it 'requires a mod_version', ->
|
||||||
data = version:1, mod_name:'Empty', recipes:[]
|
data = version:1, mod_name:'Empty', recipes:[]
|
||||||
expect(-> parser._parseRecipeBook data).to.throw Error, 'mod_version is required'
|
expect(-> parser._parseModVersion data).to.throw Error, 'mod_version is required'
|
||||||
|
|
||||||
it 'can parse an empty recipe book', ->
|
it 'can parse an empty recipe book', ->
|
||||||
data =
|
data =
|
||||||
@@ -35,7 +35,7 @@ describe 'RecipeBookParser', ->
|
|||||||
mod_name: 'Empty'
|
mod_name: 'Empty'
|
||||||
mod_version: '1.0'
|
mod_version: '1.0'
|
||||||
recipes: []
|
recipes: []
|
||||||
book = parser._parseRecipeBook data
|
book = parser._parseModVersion data
|
||||||
book.modName.should.equal 'Empty'
|
book.modName.should.equal 'Empty'
|
||||||
book.modVersion.should.equal '1.0'
|
book.modVersion.should.equal '1.0'
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ describe 'RecipeBookParser', ->
|
|||||||
{ input:'sugar cane', output:'sugar' }
|
{ input:'sugar cane', output:'sugar' }
|
||||||
{ input:[[3, 'wool'], [3, 'planks']], tools:'crafting table', output:'bed' }
|
{ input:[[3, 'wool'], [3, 'planks']], tools:'crafting table', output:'bed' }
|
||||||
]
|
]
|
||||||
book = parser._parseRecipeBook data
|
book = parser._parseModVersion data
|
||||||
book.modName.should.equal 'Minecraft'
|
book.modName.should.equal 'Minecraft'
|
||||||
book.modVersion.should.equal '1.7.10'
|
book.modVersion.should.equal '1.7.10'
|
||||||
(r.name for r in book.recipes).sort().should.eql ['bed', 'sugar']
|
(r.name for r in book.recipes).sort().should.eql ['bed', 'sugar']
|
||||||
@@ -60,8 +60,7 @@ describe 'RecipeBookParser', ->
|
|||||||
expect(-> parser._parseRecipe input:'wool').to.throw Error, 'boat is missing output'
|
expect(-> parser._parseRecipe input:'wool').to.throw Error, 'boat is missing output'
|
||||||
|
|
||||||
it 'requires input to be defined', ->
|
it 'requires input to be defined', ->
|
||||||
parser._errorLocation = 'boat'
|
expect(-> parser._parseRecipe output:'wool').to.throw Error, 'recipe for wool is missing input'
|
||||||
expect(-> parser._parseRecipe output:'wool').to.throw Error, 'boat is missing input'
|
|
||||||
|
|
||||||
it 'can parse a regular recipe', ->
|
it 'can parse a regular recipe', ->
|
||||||
data =
|
data =
|
||||||
+1
-1
@@ -27,7 +27,7 @@ mocha.setup 'bdd'
|
|||||||
require './crafting_plan.test'
|
require './crafting_plan.test'
|
||||||
require './inventory.test'
|
require './inventory.test'
|
||||||
require './inventory_parser.test'
|
require './inventory_parser.test'
|
||||||
require './recipe_book_parser.test'
|
require './mod_version_parser.test'
|
||||||
|
|
||||||
mocha.checkLeaks()
|
mocha.checkLeaks()
|
||||||
mocha.run()
|
mocha.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user