Skip to content

Commit

Permalink
Group merchant steps by merchant name
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Nov 25, 2024
1 parent 853f554 commit d4c4e82
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/craftingSteps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Prerequisites } from '@gw2efficiency/recipe-nesting'
import { RecipeTreeWithCraftFlags } from './types'

const MYSTIC_CLOVER_ID = 19675

export function craftingSteps(tree: RecipeTreeWithCraftFlags) {
let steps = craftingStepsInner(tree).reverse()

Expand All @@ -12,20 +14,16 @@ export function craftingSteps(tree: RecipeTreeWithCraftFlags) {
// since they generate items that are always useful for crafting the other steps
// Obsidian Shards and Philosopher Stones (required for Mystic Clovers) will be sorted
// above the Mystic Clovers in the next step when sorting merchants
const mysticCloversId = 19675
const mysticClovers = steps.find((step) => step.id === mysticCloversId)
if (mysticClovers) {
steps = steps.filter((step) => step.id !== mysticCloversId)
steps.unshift(mysticClovers)
}

// Sort merchants that only require currencies to the top
steps = steps.sort((a, b) => {
const aIsMerchant = isMerchantWithNoDependencies(a)
const bIsMerchant = isMerchantWithNoDependencies(b)

return aIsMerchant === bIsMerchant ? 0 : aIsMerchant ? -1 : 1
})
const mysticCloverSteps = steps.filter((step) => step.id === MYSTIC_CLOVER_ID)
steps = steps.filter((step) => step.id !== MYSTIC_CLOVER_ID)
steps = [...mysticCloverSteps, ...steps]

// Move merchants to the top of the steps
const merchantSteps = steps
.filter(isMerchantWithNoDependencies)
.sort((a, b) => a.merchant?.name.localeCompare(b.merchant?.name || '') || 0)
steps = steps.filter((step) => !isMerchantWithNoDependencies(step))
steps = [...merchantSteps, ...steps]

return steps.map((step) => ({
...step,
Expand Down

0 comments on commit d4c4e82

Please sign in to comment.