add variant fileter
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
import { computed } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import type { CraftingRecipe, ProfitResult, IngredientBreakdown, SortState } from '../types/crafting'
|
||||
import type { FilterState } from '../types/filters'
|
||||
import type { FilterState, VariantType } from '../types/filters'
|
||||
import { useAlbionPrices } from './useAlbionPrices'
|
||||
import { formatItemId } from '../utils/formatting'
|
||||
|
||||
// Returns 0=basic, 1=artifact, 2=avalon, 3=crystal
|
||||
function variantRank(outputItemId: string): number {
|
||||
function variantOf(outputItemId: string): VariantType {
|
||||
const id = outputItemId.replace(/@\d$/, '') // strip enchantment suffix
|
||||
if (id.endsWith('_AVALON')) return 2
|
||||
if (id.endsWith('_CRYSTAL')) return 3
|
||||
if (/_SET[123]$/.test(id)) return 0
|
||||
// Artifact suffixes: UNDEAD, HELL, MORGANA, KEEPER, and unique named artifacts
|
||||
if (/_(?:UNDEAD|HELL|MORGANA|KEEPER|ROYAL|FEY)$/.test(id)) return 1
|
||||
return 0
|
||||
if (id.endsWith('_AVALON')) return 'avalon'
|
||||
if (id.endsWith('_CRYSTAL')) return 'crystal'
|
||||
if (/_SET[123]$/.test(id)) return 'basic'
|
||||
if (/_(?:UNDEAD|HELL|MORGANA|KEEPER|ROYAL|FEY)$/.test(id)) return 'artifact'
|
||||
return 'basic'
|
||||
}
|
||||
|
||||
const VARIANT_ORDER: Record<VariantType, number> = { basic: 0, artifact: 1, avalon: 2, crystal: 3 }
|
||||
|
||||
function variantRank(outputItemId: string): number {
|
||||
return VARIANT_ORDER[variantOf(outputItemId)]
|
||||
}
|
||||
|
||||
export function useCraftingProfit(
|
||||
@@ -34,6 +38,7 @@ export function useCraftingProfit(
|
||||
for (const recipe of recipes) {
|
||||
if (!f.tiers.has(recipe.tier)) continue
|
||||
if (f.enchantments !== null && !f.enchantments.has(recipe.enchantment)) continue
|
||||
if (f.variants !== null && !f.variants.has(variantOf(recipe.outputItemId))) continue
|
||||
const baseName = recipe.displayName.replace(/^T\d+\.\d /, '')
|
||||
if (f.selectedItemTypes !== null && !f.selectedItemTypes.has(baseName)) continue
|
||||
if (nameLower && !recipe.displayName.toLowerCase().includes(nameLower)) continue
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import type { FilterState } from '../types/filters'
|
||||
import type { FilterState, VariantType } from '../types/filters'
|
||||
import { ALL_VARIANTS } from '../types/filters'
|
||||
import type { Tier, Enchantment } from '../types/crafting'
|
||||
import type { AlbionCity } from '../types/api'
|
||||
import { ENCHANTMENTS } from '../data/constants'
|
||||
@@ -20,6 +21,7 @@ const filters = ref<FilterState>({
|
||||
rrr: loadRrr(),
|
||||
nameFilter: '',
|
||||
enchantments: null,
|
||||
variants: null,
|
||||
})
|
||||
|
||||
function setCity(city: AlbionCity) {
|
||||
@@ -65,6 +67,21 @@ function resetEnchantments() {
|
||||
filters.value.enchantments = null
|
||||
}
|
||||
|
||||
function toggleVariant(variant: VariantType) {
|
||||
const current = filters.value.variants
|
||||
const next = current === null ? new Set(ALL_VARIANTS) : new Set(current)
|
||||
if (next.has(variant)) {
|
||||
next.delete(variant)
|
||||
} else {
|
||||
next.add(variant)
|
||||
}
|
||||
filters.value.variants = next.size === ALL_VARIANTS.length ? null : next
|
||||
}
|
||||
|
||||
function resetVariants() {
|
||||
filters.value.variants = null
|
||||
}
|
||||
|
||||
export function useFilters() {
|
||||
return {
|
||||
filters,
|
||||
@@ -75,5 +92,7 @@ export function useFilters() {
|
||||
setNameFilter,
|
||||
toggleEnchantment,
|
||||
resetEnchantments,
|
||||
toggleVariant,
|
||||
resetVariants,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user