| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { CraftingItemId, TINDERBOX_MAX_CHARGES, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js"; |
| 4 | import |
| 5 | { |
| 6 | chargeFractionRemaining, |
| 7 | chargeSpriteFrameIndex, |
| 8 | isChargeWorn, |
| 9 | normalizeChargeStack, |
| 10 | stackChargesRemaining |
| 11 | } from "../../shared/items/charges.js"; |
| 12 | import { normalizeInventorySlots } from "../../shared/items/inventory.js"; |
| 13 | |
| 14 | test("tinderbox max charges is 6 and frames map 1:1 to uses left", () => |
| 15 | { |
| 16 | assert.equal(TINDERBOX_MAX_CHARGES, 6); |
| 17 | assert.equal(chargeSpriteFrameIndex({ |
| 18 | itemId: CraftingItemId.tinderbox, |
| 19 | instance: tinderboxItemInstance(6) |
| 20 | }), 5); |
| 21 | assert.equal(chargeSpriteFrameIndex({ |
| 22 | itemId: CraftingItemId.tinderbox, |
| 23 | instance: tinderboxItemInstance(5) |
| 24 | }), 4); |
| 25 | assert.equal(chargeSpriteFrameIndex({ |
| 26 | itemId: CraftingItemId.tinderbox, |
| 27 | instance: tinderboxItemInstance(1) |
| 28 | }), 0); |
| 29 | }); |
| 30 | |
| 31 | test("legacy tinderboxes with more than max charges clamp to max", () => |
| 32 | { |
| 33 | const raw = { |
| 34 | itemId: CraftingItemId.tinderbox, |
| 35 | quantity: 1, |
| 36 | instance: { kind: "tinderbox", charges: 20 } |
| 37 | }; |
| 38 | const normalized = normalizeChargeStack(raw); |
| 39 | assert.equal(normalized.instance.charges, 6); |
| 40 | assert.equal(stackChargesRemaining(normalized), 6); |
| 41 | assert.equal(isChargeWorn(normalized), false); |
| 42 | assert.equal(chargeFractionRemaining({ |
| 43 | itemId: CraftingItemId.tinderbox, |
| 44 | instance: tinderboxItemInstance(3) |
| 45 | }), 0.5); |
| 46 | |
| 47 | const slots = normalizeInventorySlots([raw]); |
| 48 | assert.equal(slots[0].instance.charges, 6); |
| 49 | }); |