level-up/shared/util.ts
Moritz Ruth 88f0632194
All checks were successful
Build / build (push) Successful in 1m14s
Update dependencies, containerize, add build workflow
2025-03-03 00:35:21 +01:00

17 lines
No EOL
825 B
TypeScript

import type { Combination, Interaction } from "./script/types"
import { isEqual } from "lodash-es"
export const cSet = <T>(...values: T[]) => new Set(values)
export const cMap = <K extends string | number | symbol, V>(object: Record<K, V>) => new Map(Object.entries(object))
export function getInteractionQueueItemId(interaction: Interaction) {
let id: string
if (interaction.type === "use") id = `use-${interaction.objectId}`
else if (interaction.type === "combine") id = `combine-${[...interaction.objectIds].sort().join("_")}`
else throw new Error("Unknown interaction type")
return id
}
export function findMatchingCombination(combinations: Set<Combination>, objectIds: Set<string>) {
return combinations.values().find(c => isEqual(new Set(c.inputs.values().map(i => i.objectId)), objectIds))
}