(
inputFile: string,
outputFile: string)
| 103 | |
| 104 | // Central function to process the file and generate the output |
| 105 | async function processFile( |
| 106 | inputFile: string, |
| 107 | outputFile: string) : Promise<{ buildings: { |
| 108 | [key: string]: number }; |
| 109 | items: ParserItemDataInterface; |
| 110 | recipes: ParserRecipe[], |
| 111 | powerGenerationRecipes: ParserPowerRecipe[]; |
| 112 | customBuildings: ParserCustomBuilding[]; |
| 113 | buildingCosts: { [key: string]: ParserBuildingCostIngredient[] }; |
| 114 | } | undefined> { |
| 115 | try { |
| 116 | const fileContent = await readFileAsUtf8(inputFile); |
| 117 | const cleanedContent = cleanInput(fileContent); |
| 118 | const data = JSON.parse(cleanedContent); |
| 119 | |
| 120 | // Get parts |
| 121 | const items = getItems(data); |
| 122 | fixItemNames(items); |
| 123 | |
| 124 | // Get an array of all buildings that produce something |
| 125 | const producingBuildings = getProducingBuildings(data); |
| 126 | |
| 127 | // Get power consumption for the producing buildings |
| 128 | const buildings = getPowerConsumptionForBuildings(data, producingBuildings); |
| 129 | |
| 130 | // Everything else the player can place that draws power — portals, stations, lights. |
| 131 | const customBuildings = getCustomBuildings(data, producingBuildings); |
| 132 | |
| 133 | // What it costs in parts to place each building, whichever of the above it is. |
| 134 | const knownBuildings = new Set<string>([ |
| 135 | ...Object.keys(buildings), |
| 136 | ...customBuildings.map(building => building.name), |
| 137 | ]); |
| 138 | const buildingCosts = getBuildingCosts(data, knownBuildings); |
| 139 | |
| 140 | // Pass the producing buildings with power data to getRecipes to calculate perMin and powerPerProduct |
| 141 | const recipes = getProductionRecipes(data, buildings, items); |
| 142 | removeRubbishItems(items, recipes); |
| 143 | fixTurbofuel(items, recipes); |
| 144 | |
| 145 | //IMPORTANT: The order here matters - don't run this because fixing the turbofuel. |
| 146 | const powerGenerationRecipes = getPowerGeneratingRecipes(data, items); |
| 147 | |
| 148 | // IMPORTANT: This must run after getPowerGeneratingRecipes — power recipes read fuel |
| 149 | // energy values from items.parts (e.g. Leaves), and the byproducts they emit |
| 150 | // (Nuclear / Plutonium Waste) are part of what counts as "producible". |
| 151 | removeRecipelessItems(items, recipes, powerGenerationRecipes); |
| 152 | |
| 153 | // Since we've done some manipulation of the items data, re-sort it |
| 154 | const sortedItems: { [key: string]: ParserPart } = {}; |
| 155 | Object.keys(items.parts).sort((a, b) => a.localeCompare(b)).forEach(key => { |
| 156 | sortedItems[key] = items.parts[key]; |
| 157 | }); |
| 158 | items.parts = sortedItems; |
| 159 | |
| 160 | // Construct the final JSON object |
| 161 | const finalData = { |
| 162 | buildings, |
no test coverage detected