90 lines
3.4 KiB
JavaScript
90 lines
3.4 KiB
JavaScript
import { registerLoadCallback } from "./main.js";
|
|
import { listenTo } from "./events.js";
|
|
import { configuration } from "./configuration.js";
|
|
import { getPlannerDom, getPlannerMultiblockType } from "./planner.js";
|
|
import { DomList } from "./dom-list.js";
|
|
import { getAtlasIndexFromMetadata, makeAtlasImage } from "./atlas.js";
|
|
import { getSolverMetadata, setSolverMetadata } from "./solver.js";
|
|
import { findFullEntry } from "./ncpf-utils.js";
|
|
|
|
const defaultRecipes = {
|
|
["nuclearcraft:overhaul_sfr"]: {
|
|
coolant_recipe: {
|
|
elements: [
|
|
{ name: "water", type: "legacy_fluid" },
|
|
{ name: "condensate_water", type: "legacy_fluid" },
|
|
],
|
|
type: "list",
|
|
},
|
|
},
|
|
};
|
|
|
|
registerLoadCallback(() => {
|
|
listenTo([ "config:end", "solver:reset:done" ], rescanDesignRecipes);
|
|
});
|
|
|
|
function rescanDesignRecipes() {
|
|
console.log("rescan recipes");
|
|
console.log(configuration);
|
|
|
|
const multiblockType = getPlannerMultiblockType();
|
|
|
|
const configs = [
|
|
...Object.entries(configuration.configuration),
|
|
...configuration.addons.flatMap(a => Object.entries(a.configuration)),
|
|
].filter(([type]) => type === multiblockType);
|
|
|
|
const designRecipes = new DomList(
|
|
document.getElementById("recipe-selector:design"),
|
|
document.getElementById("recipe-selector:template"),
|
|
);
|
|
designRecipes.clear();
|
|
|
|
if (multiblockType === "nuclearcraft:overhaul_sfr") {
|
|
const coolantRecipes = configs.filter(([, v]) => "coolant_recipes" in v && v.coolant_recipes.length > 0)
|
|
.flatMap(([, v]) => v.coolant_recipes);
|
|
|
|
const designItem = designRecipes.makeItem();
|
|
designItem.querySelectorAll('[data-text="recipe:type"]')
|
|
.forEach(e => e.innerText = "Coolant Recipe");
|
|
|
|
const plannerDom = getPlannerDom();
|
|
const plannerMetadata = getSolverMetadata(plannerDom);
|
|
let selectedRecipe = plannerMetadata?.coolant_recipe;
|
|
if (!plannerMetadata) {
|
|
selectedRecipe = defaultRecipes["nuclearcraft:overhaul_sfr"].coolant_recipe;
|
|
setSolverMetadata(plannerDom, {
|
|
coolant_recipe: selectedRecipe,
|
|
});
|
|
}
|
|
selectedRecipe = findFullEntry("coolant_recipes", selectedRecipe, { configurationHint: multiblockType });
|
|
|
|
const selectedRecipeName = selectedRecipe.modules["plannerator:display_name"].display_name;
|
|
const selectedAtlasId = getAtlasIndexFromMetadata(selectedRecipe, multiblockType, "coolant_recipes");
|
|
designItem.querySelectorAll('[data-text="recipe:selected"]')
|
|
.forEach(e => e.innerText = selectedRecipeName);
|
|
designItem.querySelectorAll('[data-atlas="recipe:selected"]')
|
|
.forEach(e => e.appendChild(makeAtlasImage(selectedAtlasId)));
|
|
|
|
const recipeList = new DomList(designItem.querySelector(":scope > .select"));
|
|
recipeList.clear();
|
|
for (let i = 0; i < coolantRecipes.length; i++) {
|
|
const recipe = coolantRecipes[i];
|
|
const recipeItem = recipeList.makeItem();
|
|
|
|
const recipeName = recipe.modules["plannerator:display_name"].display_name;
|
|
const atlasId = getAtlasIndexFromMetadata(recipe, multiblockType, "coolant_recipes");
|
|
|
|
recipeItem.querySelectorAll('[data-text="recipe:item"]')
|
|
.forEach(e => e.innerText = recipeName);
|
|
recipeItem.querySelectorAll('[data-atlas="recipe:item"]')
|
|
.forEach(e => e.appendChild(makeAtlasImage(atlasId)));
|
|
|
|
console.log(recipe, recipeItem, atlasId);
|
|
recipeList.addItem(recipeItem);
|
|
}
|
|
|
|
designRecipes.addItem(designItem);
|
|
}
|
|
}
|