Render in-game-inspired recipe stations and result item cards

This commit is contained in:
Dev 2026-11-27 07:31:17 +01:00
commit 4e8be37c13
5 changed files with 64 additions and 12 deletions

View file

@ -16,7 +16,14 @@ function item(command) {
const custom = command.match(/"executableitems:ei-id":"([^"]+)"/)?.[1];
const name = command.match(/minecraft:custom_name=\{"text":"([^"]+)"/)?.[1]
?? material.replaceAll('_', ' ').replace(/\b\w/g, letter => letter.toUpperCase());
return { id: custom ?? material, name, material, custom: Boolean(custom) };
const result = entry(custom ?? material, name, material, Boolean(custom));
const quality = command.match(/"dunerealms:quality":"([a-z_]+)"/)?.[1];
const mark = command.match(/"dunerealms:equipment_mark":"(\d+)"/)?.[1];
const lore = command.match(/minecraft:lore=(\[[^\]]*\])/);
if (quality) result.quality = quality;
if (mark) result.equipmentMark = Number(mark);
if (lore) result.lore = JSON.parse(lore[1]).map(line => line.text).filter(line => !/ \| MK /.test(line));
return result;
}
export function recipeCatalogue() {
@ -44,7 +51,7 @@ export function recipeCatalogue() {
const crafting = 'Crafting table';
for (const part of JSON.parse(readFileSync(repairParts, 'utf8'))) {
const ingredient = item(part.material.toLowerCase());
recipes.push({ id: part.id, station: crafting, inputs: [ingredient, spice], output: entry(part.id, part.name, ingredient.material, true), amount: 1, notes: part.purpose + ' Genuine Melange or Smuggled Spice works.' });
recipes.push({ id: part.id, station: crafting, inputs: [ingredient, spice], output: { ...entry(part.id, part.name, ingredient.material, true), quality: "uncommon", equipmentMark: 1, lore: [part.purpose] }, amount: 1, notes: part.purpose + ' Genuine Melange or Smuggled Spice works.' });
}
for (const [id, name, ingredient] of [['spice_block', 'Spice Block', spice], ['smuggled_spice_block', 'Smuggled Spice Block', smuggled]]) {
recipes.push({ id, station: crafting, inputs: Array(9).fill(ingredient), output: entry(id, name, 'dried_kelp_block', true), amount: 1, shaped: true, notes: 'Fill all nine slots with the same kind of genuine spice.' });

View file

@ -25,6 +25,25 @@
#recipe .recipe-sheet a{text-decoration:underline;text-underline-offset:2px}
#recipe-station{display:flex;align-items:center;gap:9px}#recipe-station img{width:28px;height:28px;object-fit:contain;image-rendering:pixelated}
.recipe-grid--crafting-table{padding:12px;gap:5px;border:3px solid #56391f;border-radius:6px;background:#80542c url('/recipe-icons/crafting-table-top.png') center/100% 100% no-repeat;image-rendering:pixelated}
.recipe-grid--crafting-table li{background:#f0ddb9d9;border-color:#5a3c26}
.recipe-grid--crafting-table li[aria-label]{background:#50331b39}
#recipe-station-layout{display:grid;grid-template-columns:minmax(0,1fr) clamp(14px,6%,32px) minmax(36px,1fr);gap:clamp(6px,2vw,20px);align-items:center;width:min(100%,360px);padding:clamp(7px,2vw,17px);border:2px solid #65482e;border-radius:5px;background:#c6c4b7;box-shadow:inset 2px 2px #eeead5,inset -2px -2px #858176;box-sizing:border-box}
#recipe-station-layout.recipe-station--crafting{grid-template-columns:minmax(0,3fr) clamp(14px,8%,32px) minmax(32px,1fr)}
#recipe-grid{grid-template-columns:repeat(auto-fit,minmax(28px,1fr));gap:2px;margin:0}
.recipe-station--crafting #recipe-grid{grid-template-columns:repeat(3,minmax(0,1fr));}
#recipe-grid li,#recipe-result{box-sizing:border-box;display:grid;place-items:center;aspect-ratio:1;min-height:0;margin:0;padding:2px;border:0;background:#8e8d82;box-shadow:inset 2px 2px #53524a,inset -2px -2px #efebdb}
#recipe-grid li[aria-label="Empty slot"]{background:#85847a}
#recipe-grid li>a{display:grid;place-items:center;width:100%;height:100%}
#recipe-grid img,#recipe-result img{width:min(85%,38px);height:auto;aspect-ratio:1;object-fit:contain;image-rendering:pixelated}
.recipe-arrow{width:100%;aspect-ratio:1;background:#675f4e;clip-path:polygon(0 39%,58% 39%,58% 14%,100% 50%,58% 86%,58% 61%,0 61%)}
#recipe-station-layout.recipe-station--cooking{grid-template-columns:minmax(28px,42px) clamp(14px,8%,32px) minmax(36px,50px);justify-content:center}
.recipe-station--cooking #recipe-grid{grid-template-columns:1fr}
.recipe-station--cooking #recipe-grid .recipe-heat{width:66%;justify-self:center;aspect-ratio:1.8;background:linear-gradient(#edb445,#af622a);box-shadow:none;clip-path:polygon(0 100%,10% 45%,26% 69%,39% 12%,53% 62%,74% 24%,100% 100%)}
#recipe-station-layout{margin:14px auto 0;border-color:#705338;box-shadow:inset 2px 2px #eeead5,inset -2px -2px #858176,0 4px 10px #41280f36}
#recipe-output{justify-content:center;text-align:center}
#recipe-result{outline:1px solid #8d693b;outline-offset:2px}
#recipe-grid li>a:focus-visible{outline:2px solid #ffe1a2;outline-offset:-2px}
#recipe-item-card{margin-top:20px}
#recipe-item-card .item-lore-card{max-width:100%}

View file

@ -4,8 +4,8 @@
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Imperial Recipe Book · DuneRealms</title>
<meta name="description" content="Browse DuneRealms crafting, furnace and smoker recipes in the Imperial Recipe Book.">
<link rel="stylesheet" href="/styles.css"><link rel="stylesheet" href="/imperial-recipe-book.css?v=4">
<script type="module" src="/imperial-recipe-book.js?v=4"></script>
<link rel="stylesheet" href="/styles.css"><link rel="stylesheet" href="/imperial-recipe-book.css?v=6">
<script type="module" src="/imperial-recipe-book.js?v=6"></script>
<link rel="stylesheet" href="/portal-navigation.css"><script src="/portal-navigation.js" defer></script></head>
<body><header class="dune-site-header"></header>
<main id="main" class="realm-handbook">
@ -20,9 +20,9 @@
<article id="recipe" hidden>
<div class="recipe-spread">
<section class="recipe-sheet"><h2>Ingredients</h2><ul id="recipe-ingredients"></ul></section>
<section class="recipe-sheet"><h2 id="recipe-name" tabindex="-1"></h2><p id="recipe-station"></p><ol id="recipe-grid" class="recipe-grid" aria-label="Recipe slots"></ol><p id="recipe-output"></p></section>
<section class="recipe-sheet"><h2 id="recipe-name" tabindex="-1"></h2><p id="recipe-station"></p><div id="recipe-station-layout"><ol id="recipe-grid" class="recipe-grid" aria-label="Recipe slots"></ol><span class="recipe-arrow" aria-hidden="true"></span><div id="recipe-result" aria-label="Recipe result"></div></div><p id="recipe-output"></p></section>
</div>
<section class="recipe-notes"><h2>Preparation</h2><p id="recipe-directions"></p><ul id="recipe-variants"></ul></section>
<section class="recipe-notes"><h2>Preparation</h2><p id="recipe-directions"></p><ul id="recipe-variants"></ul></section><div id="recipe-item-card" aria-label="Result item details"></div>
</article>
</div>
</div>

View file

@ -1,3 +1,4 @@
import { itemLoreCard } from './item-lore-view.mjs';
const get = id => document.getElementById(id);
const node = (tag, text) => Object.assign(document.createElement(tag), { textContent: text });
const link = (recipe, name = recipe.output.name) =>
@ -63,17 +64,42 @@ try {
get('recipe-name').textContent = selected.output.name;
const station = { 'Crafting table': 'crafting_table', Furnace: 'furnace', Smoker: 'smoker', 'Brewing stand': 'brewing_stand' }[selected.station];
get('recipe-station').replaceChildren(icon({ material: station }), node('span', 'Use a ' + selected.station.toLowerCase() + '.'));
get('recipe-output').replaceChildren(icon(selected.output), node('span', (selected.possible ? 'Possible result' : 'Makes') + ' · ' + selected.amount + ' × ' + selected.output.name));
get('recipe-result').replaceChildren(icon(selected.output));
get('recipe-result').setAttribute('aria-label', selected.output.name);
const card = itemLoreCard({ ...selected.output, nativeMetadata: true });
if (selected.output.icon) card.querySelector('.item-lore-name img').src = selected.output.icon;
get('recipe-item-card').replaceChildren(card);
get('recipe-output').textContent = (selected.possible ? 'Possible result' : 'Makes') + ' · ' + selected.amount + ' × ' + selected.output.name;
const crafting = selected.station === 'Crafting table';
get('recipe-grid').classList.toggle('recipe-grid--crafting-table', crafting);
const cooking = selected.station === 'Furnace' || selected.station === 'Smoker';
get('recipe-station-layout').classList.toggle('recipe-station--crafting', crafting);
get('recipe-station-layout').classList.toggle('recipe-station--cooking', cooking);
const slots = crafting ? Array.from({ length: 9 }, (_, index) => selected.inputs[index]) : selected.inputs;
get('recipe-grid').replaceChildren(...slots.map(item => {
const slot = node('li', '');
if (item) slot.append(icon(item), label(item));
if (item) {
slot.title = item.name;
slot.setAttribute('aria-label', item.name);
const source = items.get(item.id);
if (source && item.id !== selected.output.id) {
const anchor = link(source, '');
anchor.setAttribute('aria-label', item.name); anchor.append(icon(item)); slot.append(anchor);
} else slot.append(icon(item));
}
else slot.setAttribute('aria-label', 'Empty slot');
return slot;
}));
if (cooking) {
const heat = node('li', '');
heat.className = 'recipe-heat';
heat.setAttribute('aria-hidden', 'true');
const fuel = node('li', '');
fuel.title = 'Add any valid fuel';
fuel.setAttribute('aria-label', 'Fuel slot');
get('recipe-grid').append(heat, fuel);
}
const directions = crafting
? selected.shaped ? 'Arrange the ingredients exactly as shown.' : 'Place one ingredient in each occupied slot. The arrangement can vary.'
: selected.station === 'Brewing stand' ? 'Add the vial or potion below, place the spice above, and fuel the stand with blaze powder.'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B