BlueGit

timfa questward

Resolve alchemy recipe-paper ingredient keys to display names.

Key-only rows like oak-bark and rock-salt fell through to the raw key; look up item defs the same way resolved recipes do.

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
6fc06710b48dac1c436527fa91be50ff8577f194
Parent
087584f1
2 files changed +51 −5
server/tests/alchemy.test.js +22 −1
@@ -10,8 +10,11 @@ import
10 10 hashAlchemySteps,
11 11 resolvedAlchemyPotions,
12 12 unstablePotionFromSteps,
13 potionItemInstance
13 potionItemInstance,
14 recipePaperBody,
15 formatAlchemyStep
14 16 } from "../../shared/alchemy/recipes.js";
17 import { alchemyPotionDefinition } from "../../shared/definitions/alchemy.js";
15 18 import { emptyEquipment, emptySlots, insertStack } from "../../shared/items/inventory.js";
16 19 import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
17 20 import { Component } from "../src/ecs/components.js";
@@ -47,6 +50,24 @@ function countItem (slots, itemId)
47 50 .reduce((sum, slot) => sum + (slot.quantity | 0), 0);
48 51 }
49 52
53 test("recipe paper body resolves ingredient keys to display names", () =>
54 {
55 const potion = alchemyPotionDefinition("tanningBrew");
56 assert.ok(potion);
57 const body = recipePaperBody(potion);
58 assert.match(body, /2× Oak bark/);
59 assert.match(body, /1× Rock salt/);
60 assert.match(body, /1× Bottle of Animal Fat \(full bottle\)/);
61 assert.doesNotMatch(body, /oak-bark/);
62 assert.doesNotMatch(body, /rock-salt/);
63 assert.match(body, /- insert Oak bark/);
64 assert.match(body, /- insert Rock salt/);
65 assert.equal(
66 formatAlchemyStep({ kind: AlchemyStepKind.insert, itemKey: "oak-bark" }),
67 "insert Oak bark"
68 );
69 });
70
50 71 test("lesser health tonic ratios and steps evaluate to a success batch", () =>
51 72 {
52 73 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
@@ -10,8 +10,11 @@ import
10 hashAlchemySteps,
10 hashAlchemySteps,
11 resolvedAlchemyPotions,
11 resolvedAlchemyPotions,
12 unstablePotionFromSteps,
12 unstablePotionFromSteps,
13 potionItemInstance
13 potionItemInstance,
14 recipePaperBody,
15 formatAlchemyStep
14 } from "../../shared/alchemy/recipes.js";
16 } from "../../shared/alchemy/recipes.js";
17import { alchemyPotionDefinition } from "../../shared/definitions/alchemy.js";
15import { emptyEquipment, emptySlots, insertStack } from "../../shared/items/inventory.js";
18import { emptyEquipment, emptySlots, insertStack } from "../../shared/items/inventory.js";
16import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
19import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
17import { Component } from "../src/ecs/components.js";
20import { Component } from "../src/ecs/components.js";
@@ -47,6 +50,24 @@ function countItem (slots, itemId)
47 .reduce((sum, slot) => sum + (slot.quantity | 0), 0);
50 .reduce((sum, slot) => sum + (slot.quantity | 0), 0);
48}
51}
49
52
53test("recipe paper body resolves ingredient keys to display names", () =>
54{
55 const potion = alchemyPotionDefinition("tanningBrew");
56 assert.ok(potion);
57 const body = recipePaperBody(potion);
58 assert.match(body, /2× Oak bark/);
59 assert.match(body, /1× Rock salt/);
60 assert.match(body, /1× Bottle of Animal Fat \(full bottle\)/);
61 assert.doesNotMatch(body, /oak-bark/);
62 assert.doesNotMatch(body, /rock-salt/);
63 assert.match(body, /- insert Oak bark/);
64 assert.match(body, /- insert Rock salt/);
65 assert.equal(
66 formatAlchemyStep({ kind: AlchemyStepKind.insert, itemKey: "oak-bark" }),
67 "insert Oak bark"
68 );
69});
70
50test("lesser health tonic ratios and steps evaluate to a success batch", () =>
71test("lesser health tonic ratios and steps evaluate to a success batch", () =>
51{
72{
52 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
73 const potion = resolvedAlchemyPotions().find((entry) => entry.potionKey === "lesserHealthTonic");
shared/alchemy/recipes.js +29 −4
@@ -2,6 +2,27 @@ import { AlchemyStepKind, ALCHEMY_POTION_DEFINITIONS, UNSTABLE_POTION_EFFECTS, C
2 2 import { ITEM_DEFINITIONS, ItemId, itemDefinition } from "../definitions/items.js";
3 3 import { skillLevel, SkillId } from "../definitions/skills.js";
4 4
5 /** Resolve an alchemy ingredient/step item key or id to a player-facing name. */
6 export function alchemyItemLabel ({ itemId = null, itemKey = null, key = null } = {})
7 {
8 if (itemId != null)
9 {
10 const def = itemDefinition(itemId);
11 if (def?.displayName)
12 { return def.displayName; }
13 }
14 const lookupKey = itemKey ?? key;
15 if (lookupKey)
16 {
17 const resolvedId = itemIdByKeyMap().get(lookupKey);
18 const def = resolvedId != null ? itemDefinition(resolvedId) : null;
19 if (def?.displayName)
20 { return def.displayName; }
21 return String(lookupKey);
22 }
23 return itemId != null ? String(itemId) : "?";
24 }
25
5 26 /** Serialize a step for hashing / recipe papers. */
6 27 export function formatAlchemyStep (step)
7 28 {
@@ -12,8 +33,10 @@ export function formatAlchemyStep (step)
12 33 const potion = alchemyPotionDefinition(step.potionKey);
13 34 return `insert ${potion?.displayName ?? step.potionKey}`;
14 35 }
15 const def = itemDefinition(step.itemId);
16 return `insert ${def?.displayName ?? step.itemKey ?? step.itemId}`;
36 return `insert ${alchemyItemLabel({
37 itemId: step.itemId,
38 itemKey: step.itemKey
39 })}`;
17 40 }
18 41 return step.kind;
19 42 }
@@ -303,8 +326,10 @@ export function recipePaperBody (potion)
303 326 lines.push(`- ${row.quantity}× ${brew?.displayName ?? row.potionKey} (full bottle)`);
304 327 continue;
305 328 }
306 const def = itemDefinition(row.itemId);
307 lines.push(`- ${row.quantity}× ${def?.displayName ?? row.key ?? row.itemId}`);
329 lines.push(`- ${row.quantity}× ${alchemyItemLabel({
330 itemId: row.itemId,
331 key: row.key
332 })}`);
308 333 }
309 334 lines.push("", "Steps:");
310 335 for (const step of potion.steps ?? [])
@@ -2,6 +2,27 @@ import { AlchemyStepKind, ALCHEMY_POTION_DEFINITIONS, UNSTABLE_POTION_EFFECTS, C
2import { ITEM_DEFINITIONS, ItemId, itemDefinition } from "../definitions/items.js";
2import { ITEM_DEFINITIONS, ItemId, itemDefinition } from "../definitions/items.js";
3import { skillLevel, SkillId } from "../definitions/skills.js";
3import { skillLevel, SkillId } from "../definitions/skills.js";
4
4
5/** Resolve an alchemy ingredient/step item key or id to a player-facing name. */
6export function alchemyItemLabel ({ itemId = null, itemKey = null, key = null } = {})
7{
8 if (itemId != null)
9 {
10 const def = itemDefinition(itemId);
11 if (def?.displayName)
12 { return def.displayName; }
13 }
14 const lookupKey = itemKey ?? key;
15 if (lookupKey)
16 {
17 const resolvedId = itemIdByKeyMap().get(lookupKey);
18 const def = resolvedId != null ? itemDefinition(resolvedId) : null;
19 if (def?.displayName)
20 { return def.displayName; }
21 return String(lookupKey);
22 }
23 return itemId != null ? String(itemId) : "?";
24}
25
5/** Serialize a step for hashing / recipe papers. */
26/** Serialize a step for hashing / recipe papers. */
6export function formatAlchemyStep (step)
27export function formatAlchemyStep (step)
7{
28{
@@ -12,8 +33,10 @@ export function formatAlchemyStep (step)
12 const potion = alchemyPotionDefinition(step.potionKey);
33 const potion = alchemyPotionDefinition(step.potionKey);
13 return `insert ${potion?.displayName ?? step.potionKey}`;
34 return `insert ${potion?.displayName ?? step.potionKey}`;
14 }
35 }
15 const def = itemDefinition(step.itemId);
36 return `insert ${alchemyItemLabel({
16 return `insert ${def?.displayName ?? step.itemKey ?? step.itemId}`;
37 itemId: step.itemId,
38 itemKey: step.itemKey
39 })}`;
17 }
40 }
18 return step.kind;
41 return step.kind;
19}
42}
@@ -303,8 +326,10 @@ export function recipePaperBody (potion)
303 lines.push(`- ${row.quantity}× ${brew?.displayName ?? row.potionKey} (full bottle)`);
326 lines.push(`- ${row.quantity}× ${brew?.displayName ?? row.potionKey} (full bottle)`);
304 continue;
327 continue;
305 }
328 }
306 const def = itemDefinition(row.itemId);
329 lines.push(`- ${row.quantity}× ${alchemyItemLabel({
307 lines.push(`- ${row.quantity}× ${def?.displayName ?? row.key ?? row.itemId}`);
330 itemId: row.itemId,
331 key: row.key
332 })}`);
308 }
333 }
309 lines.push("", "Steps:");
334 lines.push("", "Steps:");
310 for (const step of potion.steps ?? [])
335 for (const step of potion.steps ?? [])