Skip to content

Commit

Permalink
Merge pull request #7 from gw2efficiency/fix-looping-recipes
Browse files Browse the repository at this point in the history
Fix for Condensed Ley-Line Essence recipes
  • Loading branch information
queicherius authored Nov 17, 2024
2 parents 57873be + a5fe183 commit 26ebef7
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function nestRecipe(
const isGuildUpgrade = component.type === 'GuildUpgrade'
const id = isGuildUpgrade ? recipeUpgradesMap[component.id] || component.id : component.id
const componentRecipe = recipesMap[id]
const condensedLeyLineEssenceIds = [91224, 91137, 91222, 91171]

// Just give back the component for currencies
if (component.type === 'Currency') {
Expand Down Expand Up @@ -132,6 +133,11 @@ function nestRecipe(
: component
}

// These items should not have components if they are components of each other
if (condensedLeyLineEssenceIds.includes(recipe.id) && condensedLeyLineEssenceIds.includes(id)) {
return component
}

// The component recipe is not nested yet, so we nest it now!
if (!componentRecipe.nested) {
recipesMap[id] = nestRecipe(componentRecipe, recipesMap, recipeUpgradesMap, decorationsMap)
Expand Down
177 changes: 177 additions & 0 deletions tests/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,183 @@ Object {
}
`;

exports[`recipe-nesting excludes components for Condensed Ley-Line Essence items if they are components of each other 1`] = `
Array [
Object {
"achievement_id": undefined,
"components": Array [
Object {
"id": 24272,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24464,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24326,
"quantity": 1,
"type": "Item",
},
Object {
"id": 91224,
"quantity": 2,
"type": "Item",
},
],
"disciplines": Array [
"Mystic Forge",
],
"id": 91137,
"merchant": undefined,
"min_rating": 400,
"multipleRecipeCount": 3,
"output": 1,
"output_range": undefined,
"prerequisites": Array [
Object {
"id": 1,
"type": "Recipe",
},
],
"quantity": 1,
"type": "Recipe",
"upgrade_id": undefined,
},
Object {
"achievement_id": undefined,
"components": Array [
Object {
"id": 24272,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24534,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24326,
"quantity": 1,
"type": "Item",
},
Object {
"id": 91224,
"quantity": 2,
"type": "Item",
},
],
"disciplines": Array [
"Mystic Forge",
],
"id": 91171,
"merchant": undefined,
"min_rating": 400,
"multipleRecipeCount": 3,
"output": 1,
"output_range": undefined,
"prerequisites": Array [
Object {
"id": 2,
"type": "Recipe",
},
],
"quantity": 1,
"type": "Recipe",
"upgrade_id": undefined,
},
Object {
"achievement_id": undefined,
"components": Array [
Object {
"id": 24272,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24464,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24326,
"quantity": 1,
"type": "Item",
},
Object {
"id": 91224,
"quantity": 2,
"type": "Item",
},
],
"disciplines": Array [
"Mystic Forge",
],
"id": 91222,
"merchant": undefined,
"min_rating": 400,
"multipleRecipeCount": 3,
"output": 1,
"output_range": undefined,
"prerequisites": Array [
Object {
"id": 3,
"type": "Recipe",
},
],
"quantity": 1,
"type": "Recipe",
"upgrade_id": undefined,
},
Object {
"achievement_id": undefined,
"components": Array [
Object {
"id": 24272,
"quantity": 1,
"type": "Item",
},
Object {
"id": 24465,
"quantity": 1,
"type": "Item",
},
Object {
"id": 91137,
"quantity": 1,
"type": "Item",
},
Object {
"id": 91224,
"quantity": 2,
"type": "Item",
},
],
"disciplines": Array [
"Mystic Forge",
],
"id": 91224,
"merchant": undefined,
"min_rating": 400,
"multipleRecipeCount": 3,
"output": 1,
"output_range": undefined,
"prerequisites": Array [
Object {
"id": 4,
"type": "Recipe",
},
],
"quantity": 1,
"type": "Recipe",
"upgrade_id": undefined,
},
]
`;

exports[`recipe-nesting orders the components correctly 1`] = `
Object {
"achievement_id": undefined,
Expand Down
140 changes: 140 additions & 0 deletions tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,144 @@ describe('recipe-nesting', () => {
it('ignores recipes with only guild upgrades', () => {
expect(output.find((x) => x.id === 4567)).toEqual(undefined)
})

it('excludes components for Condensed Ley-Line Essence items if they are components of each other', () => {
const input: Array<API_Recipes_Entry_Next> = [
{
type: 'Recipe',
output_item_id: 91137,
output_item_count: 1,
min_rating: 400,
disciplines: ['Mystic Forge'],
flags: [],
ingredients: [
{
id: 24272,
type: 'Item',
count: 1,
},
{
id: 24464,
type: 'Item',
count: 1,
},
{
id: 24326,
type: 'Item',
count: 1,
},
{
id: 91224,
type: 'Item',
count: 2,
},
],
id: 1,
chat_link: '[&CQIAAAA=]',
multipleRecipeCount: 3,
},
{
type: 'Recipe',
output_item_id: 91171,
output_item_count: 1,
min_rating: 400,
disciplines: ['Mystic Forge'],
flags: [],
ingredients: [
{
id: 24272,
type: 'Item',
count: 1,
},
{
id: 24534,
type: 'Item',
count: 1,
},
{
id: 24326,
type: 'Item',
count: 1,
},
{
id: 91224,
type: 'Item',
count: 2,
},
],
id: 2,
chat_link: '[&CQIAAAA=]',
multipleRecipeCount: 3,
},
{
type: 'Recipe',
output_item_id: 91222,
output_item_count: 1,
min_rating: 400,
disciplines: ['Mystic Forge'],
flags: [],
ingredients: [
{
id: 24272,
type: 'Item',
count: 1,
},
{
id: 24464,
type: 'Item',
count: 1,
},
{
id: 24326,
type: 'Item',
count: 1,
},
{
id: 91224,
type: 'Item',
count: 2,
},
],
id: 3,
chat_link: '[&CQIAAAA=]',
multipleRecipeCount: 3,
},
{
type: 'Recipe',
output_item_id: 91224,
output_item_count: 1,
min_rating: 400,
disciplines: ['Mystic Forge'],
flags: [],
ingredients: [
{
id: 24272,
type: 'Item',
count: 1,
},
{
id: 24465,
type: 'Item',
count: 1,
},
{
id: 91137,
type: 'Item',
count: 1,
},
{
id: 91224,
type: 'Item',
count: 2,
},
],
id: 4,
chat_link: '[&CQIAAAA=]',
multipleRecipeCount: 3,
},
]

const output = nestRecipes(input)
expect(output).toMatchSnapshot()
})
})

0 comments on commit 26ebef7

Please sign in to comment.