Added the producing graph

This commit is contained in:
Sebastian Seedorf
2022-08-13 02:13:47 +02:00
parent 185f39cb8a
commit 7682aeaea1
14 changed files with 312 additions and 47 deletions

26
src/calculateInputs.ts Normal file
View 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
}

View File

@@ -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
}
}