aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-20 12:31:27 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-23 19:21:49 +0200
commit2520370a10782bd41fccc54589362467b809939f (patch)
tree52f876c15087eb5b4b25231cce34ad2b310fa780
parent934913b03957e2c11b269c6ff6f2e9441eceee0a (diff)
downloadhurrycurry-2520370a10782bd41fccc54589362467b809939f.tar
hurrycurry-2520370a10782bd41fccc54589362467b809939f.tar.bz2
hurrycurry-2520370a10782bd41fccc54589362467b809939f.tar.zst
experiment with recipe generation
-rw-r--r--data/recipes.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/data/recipes.ts b/data/recipes.ts
new file mode 100644
index 00000000..dcd73d8e
--- /dev/null
+++ b/data/recipes.ts
@@ -0,0 +1,76 @@
+
+//? Is is a good idea? Probably not.
+
+interface Recipe {
+ tile?: string,
+ inputs: string[],
+ outputs: string[],
+ action: "instant" | "passive" | "active"
+ duration?: number
+}
+
+const all_items = new Set<string>()
+function out(r: Recipe) {
+ r.inputs.forEach(i => all_items.add(i))
+ r.outputs.forEach(i => all_items.add(i))
+ console.log(`- { tile: ${r.tile ?? null}, inputs: ${JSON.stringify(r.inputs)}, outputs: ${JSON.stringify(r.outputs)}, action: !${r.action + " " + (r.duration ?? "")} }`);
+}
+type Component = (e: string) => void
+
+const cut = (new_name?: string): Component => e => {
+ out({ action: "active", duration: 2, tile: "cuttingboard", inputs: [e], outputs: [new_name ?? ("sliced-" + e)] })
+}
+const cook = (new_name?: string): Component => e => {
+ const i = e + "-pot"
+ const o = (new_name ?? ("cooked-" + e)) + "-pot"
+ out({ action: "instant", inputs: ["pot", e], outputs: [i] })
+ out({ action: "passive", duration: 2, tile: "stove", inputs: [i], outputs: [o] })
+}
+const crate: Component = e => out({ action: "instant", tile: e + "-crate", inputs: [], outputs: [e], })
+
+function item(name: string, ...components: Component[]) {
+ for (const f of components) {
+ f(name)
+ }
+}
+
+
+function combine(container: string, ...inputs: string[]) {
+ const open = inputs.map(i => [i])
+ while (1) {
+ const e = open.pop()
+ if (!e) break;
+ const cur = e.join("-") + "-" + container
+ for (const i of inputs) {
+ if (e.includes(i)) continue
+ const parts = [...e, i]
+ parts.sort()
+ const o = parts.join("-") + "-" + container
+ if (all_items.has(o)) continue
+ open.push(parts)
+ out({
+ action: "instant",
+ inputs: [cur, i],
+ outputs: [o]
+ })
+ }
+ }
+}
+
+item("tomato", cut(), crate, cook("tomato-soop"))
+combine("plate", "steak", "sliced-tomato", "bread")
+
+for (const i of all_items) {
+ const parts = i.split("-");
+ const container = parts.pop()!;
+ if (parts.length >= 1 && ["pot", "plate"].includes(container)) {
+ out({
+ action: "instant",
+ tile: "trash",
+ inputs: [i],
+ outputs: [container]
+ })
+ } else {
+ out({ action: "instant", tile: "trash", inputs: [i], outputs: [] })
+ }
+}