gw2e-recipe-nesting
v2.5.1
Published
Nest an array of recipes into a tree
Downloads
1
Readme
recipe-nesting
Nest an array of recipes into a tree
This is part of gw2efficiency. Please report all issues in the central repository.
Install
npm install gw2e-recipe-nesting
This module can be used for Node.js as well as browsers using Browserify.
If you want to calculate the price of the tree generated from this, take a look at gw2e-recipe-calculation
.
Usage
import nesting from 'gw2e-recipe-nesting'
// Expects a list of recipes in the API format
// -> https://github.com/arenanet/api-cdi/blob/master/v2/recipes.js
// This needs to include at least the recipe you want to transform
// and all sub-recipes including guild upgrade recipes
// (since we want to build a full tree).
// It is easiest to just pass in all existing recipes. ;)
let recipes = [
{
"type": "Refinement",
"output_item_id": 19713,
"output_item_count": 1,
"min_rating": 75,
"time_to_craft_ms": 2000,
"disciplines": ["Artificer", "Weaponsmith", "Scribe", "Huntsman"],
"flags": ["AutoLearned"],
"ingredients": [{
"item_id": 19726,
"count": 2
}],
"id": 1,
"chat_link": "[&CQEAAAA=]"
},
// ...
]
// This is a (optional) map of guild upgrade ids to item ids. This should only be used
// for type == Decoration, and resolves all the Basic Decorations needed for scribing
let decorations = {
42: 1337,
// ...
}
let nestedRecipes = nesting(recipes, decorations)
// The output is an array consisting of the following:
nestedRecipes = [
{
"id": 13243,
"quantity": 5,
"output": 1,
"components": [
{
"id": 19712,
"quantity": 2,
"output": 1,
"components": [
{
"id": 19725,
"quantity": 3
},
// ...
]
},
// ...
]
}
// ...
]
Tests
npm test
Licence
MIT