Recipes, resources and crafting mechanics. Recipes as data with inputs, outputs, tools that aren't consumed, required stations, craft time, learning and discovering recipes, "what can I craft now" and "how many can I make", missing-ingredient lists, safe crafting that rolls back when the bag is full, recursive raw-material costs for planning, and crafting UI. Includes a tested crafting.js that ...
Download skill (.zip) Files on GitHubCrafting system
Drop-in: assets/crafting.js (tests: unlearned recipes, missing tools and inputs, required station, crafting several at
once, max craftable, rollback when there’s no room, raw cost expansion). Uses any inventory with count / has / add / remove
(inventory-system).
import { createCrafting } from "./core/crafting.js";
const RECIPES = {
plank: { in: { log: 1 }, out: { plank: 4 } },
table: { in: { plank: 4, nail: 2 }, tools: ["hammer"], station: "bench", out: { table: 1 }, time: 2 },
torch: { in: { stick: 1, coal: 1 }, out: { torch: 4 }, discoverWith: ["coal"] },
};
const crafting = createCrafting(RECIPES, { known: ["plank"] });
crafting.canCraft("table", bag, { station: nearStation }) // { ok } or { ok:false, reason, missing: { nail: 2 } }
crafting.craft("plank", bag, {}, 3) // { ok, made: { plank: 12 } }
crafting.discover(bag) // after pickups → ["torch"]: "New recipe!"
crafting.rawCost("table") // { log: 1, nail: 2 } for planning UI
The loop
Gather → craft → use the result to gather better or survive longer. Every recipe should unlock a new action or area, not just a bigger number.
Design rules
- Start with 3–5 recipes. Add tiers (wood → stone → iron) that each open new places.
- Show recipes: craftable ones first, then “almost” (one missing, with what’s missing), then locked as silhouettes.
- Discovery: learn recipes by picking up a key ingredient, reaching a station, or finding a blueprint.
- Stations make the world matter (craft at the forge). Tools give lasting progression.
- Craft time: instant for small things, short progress bars for big ones, never long waits in action games.
- Batch crafting (“Craft x10”) with
maxCraftable. - Keep recipe data in one file; validate that every input is an item and that there are no loops (
rawCostthrows on loops).
UI for every device
List or grid; tap/click a recipe to see inputs with have/need counts (red when short); big Craft button; hold to craft many. Gamepad: d-pad through recipes, A to craft.