17 lines
No EOL
825 B
TypeScript
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))
|
|
} |