begin recipe selector
This commit is contained in:
parent
586cea0529
commit
ddd74a262c
26
index.html
26
index.html
|
|
@ -32,7 +32,7 @@
|
||||||
</nav>
|
</nav>
|
||||||
<aside id="left-menu" data-state="planning">
|
<aside id="left-menu" data-state="planning">
|
||||||
<span data-resize="left-menu"></span>
|
<span data-resize="left-menu"></span>
|
||||||
<section id="block-picker">
|
<section id="block-picker" data-state="planning">
|
||||||
<label>
|
<label>
|
||||||
Filter:
|
Filter:
|
||||||
<input data-input="block-picker:filter">
|
<input data-input="block-picker:filter">
|
||||||
|
|
@ -82,6 +82,30 @@
|
||||||
</main>
|
</main>
|
||||||
<aside id="right-menu">
|
<aside id="right-menu">
|
||||||
<span data-resize="right-menu"></span>
|
<span data-resize="right-menu"></span>
|
||||||
|
<section id="recipe-selector" data-state="planning">
|
||||||
|
<template id="recipe-selector:template">
|
||||||
|
<div>
|
||||||
|
<header data-text="recipe:type"></header>
|
||||||
|
<div class="recipe">
|
||||||
|
<div data-atlas="recipe:selected"></div>
|
||||||
|
<div data-text="recipe:selected"></div>
|
||||||
|
</div>
|
||||||
|
<input placeholder="Filter" type="text" data-input="recipe:filter">
|
||||||
|
<div class="select">
|
||||||
|
<template>
|
||||||
|
<div class="recipe">
|
||||||
|
<div data-atlas="recipe:item"></div>
|
||||||
|
<div data-text="recipe:item"></div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div id="recipe-selector:design" class="recipe-selector">
|
||||||
|
</div>
|
||||||
|
<div id="recipe-selector:selection" class="recipe-selector">
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</aside>
|
</aside>
|
||||||
<footer>
|
<footer>
|
||||||
<div>pre-alpha 1.1</div>
|
<div>pre-alpha 1.1</div>
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ export class DomList {
|
||||||
list;
|
list;
|
||||||
template;
|
template;
|
||||||
|
|
||||||
constructor(rootElem) {
|
constructor(rootElem, templateElement = undefined) {
|
||||||
this.list = rootElem;
|
this.list = rootElem;
|
||||||
this.template = this.list.querySelector("template").content.firstElementChild;
|
this.template = (templateElement ?? this.list.querySelector("template"))
|
||||||
|
.content.firstElementChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
|
|
||||||
|
|
@ -157,10 +157,10 @@ export async function saveFile(name = undefined) {
|
||||||
|
|
||||||
if (multiblockType === "nuclearcraft:overhaul_sfr") {
|
if (multiblockType === "nuclearcraft:overhaul_sfr") {
|
||||||
const coolantRecipes = [];
|
const coolantRecipes = [];
|
||||||
let coolantRecipeIndex = -1;
|
let coolantRecipeIndex;
|
||||||
const plannerMetadata = getSolverMetadata(getPlannerDom());
|
const plannerMetadata = getSolverMetadata(getPlannerDom());
|
||||||
|
|
||||||
coolantRecipes.push(stripEntryToMinimums(plannerMetadata["coolant_recipe"]));
|
coolantRecipes.push(stripEntryToMinimums(plannerMetadata.coolant_recipe));
|
||||||
coolantRecipeIndex = 0;
|
coolantRecipeIndex = 0;
|
||||||
|
|
||||||
fileData = {
|
fileData = {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import "./js-utils.js"
|
||||||
import "./menu-bar.js";
|
import "./menu-bar.js";
|
||||||
import "./ncpf-utils.js";
|
import "./ncpf-utils.js";
|
||||||
import "./planner.js";
|
import "./planner.js";
|
||||||
|
import "./recipe-selector.js";
|
||||||
import "./resize-menus.js";
|
import "./resize-menus.js";
|
||||||
import "./solver.js";
|
import "./solver.js";
|
||||||
import { getState, setState, STATE } from "./state.js";
|
import { getState, setState, STATE } from "./state.js";
|
||||||
|
|
@ -84,7 +85,7 @@ window.addEventListener("load", () => {
|
||||||
|
|
||||||
emitEvent("setup-end");
|
emitEvent("setup-end");
|
||||||
|
|
||||||
void loadConfiguration("default");
|
void loadConfiguration("addons");
|
||||||
|
|
||||||
// awaitEvent("config:end").then(() => loadExampleFile("tiny reactor"));
|
// awaitEvent("config:end").then(() => loadExampleFile("tiny reactor"));
|
||||||
// awaitEvent("config:end").then(() => loadExampleFile("multi-reactor"));
|
// awaitEvent("config:end").then(() => loadExampleFile("multi-reactor"));
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -262,6 +262,8 @@ input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
|
||||||
outline: calc(var(--scale-factor) * 1px) solid var(--block-hover-outline-color, #6666);
|
outline: calc(var(--scale-factor) * 1px) solid var(--block-hover-outline-color, #6666);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#recipe-selector {}
|
||||||
|
|
||||||
[data-tooltip] {
|
[data-tooltip] {
|
||||||
position: relative;
|
position: relative;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue