Added the producing graph
This commit is contained in:
26
src/calculateInputs.ts
Normal file
26
src/calculateInputs.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {EnrichedEntity} from "./types";
|
||||
|
||||
export const calculateInputs = (allProducingFactories: string[], ignoredFactories: string[], baseFactories: string[], exportedFactories: Set<string>, findFactory: (uid: string) => EnrichedEntity|undefined) => {
|
||||
const prducingSet = new Set(allProducingFactories)
|
||||
const ignored = new Set(ignoredFactories)
|
||||
const base = new Set(baseFactories)
|
||||
const inputs = new Set<string>()
|
||||
const intermediates = new Set<string>()
|
||||
|
||||
let next: string|undefined
|
||||
while (next = allProducingFactories.pop()) {
|
||||
const pres = Object.keys(findFactory(next)?.recipe?.prerequisites ?? {})
|
||||
for (const pre of pres) {
|
||||
if (exportedFactories.has(pre) || base.has(pre)) {
|
||||
if (!prducingSet.has(pre)) inputs.add(pre)
|
||||
} else if (!intermediates.has(pre)) {
|
||||
if (!prducingSet.has(pre)) intermediates.add(pre)
|
||||
allProducingFactories.push(pre)
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
Array.from(inputs).sort((a, b) => a.localeCompare(b)),
|
||||
Array.from(intermediates).sort((a, b) => a.localeCompare(b))
|
||||
] as const
|
||||
}
|
||||
@@ -98,7 +98,7 @@ function parseJSON<T>(value: string | null): T | undefined {
|
||||
try {
|
||||
return value === 'undefined' ? undefined : JSON.parse(value ?? '')
|
||||
} catch {
|
||||
console.log('parsing error on', { value })
|
||||
console.error('parsing error on', { value })
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user