Sign in
mod

Music boxes

by Potluck · version 1 · Checked for all ages

Old music boxes turn up in the island's lost places: a gnome's in the diggings, a brass one in the workshops' vaults, one of moonsilver behind the moon seal and a little wooden one in old chests. Hold one and Interact looking at the sky to wind it, and it plays its tune for everyone near.

1--!strict
2-- Music boxes' own tests: `potluck-server --test=music-boxes`.
3
4local test = require("@potluck/test@0.8")
5local world = require("@potluck/world@0.27")
6
7test.case("a music box wound in hand plays both halves of its tune", function()
8 local p = test.player("Ada", { survival = true, carrying = { ["Brass music box"] = 1 } })
9 test.hold(p, "Brass music box")
10 test.use_item(p, vector.create(0, 1, 0))
11 test.wait(0.2)
12 test.same(test.shown(p, "music"), "The brass music box plays Island waltz.")
13 test.same(test.heard("brass_a"), 1, "the first half")
14 test.same(test.heard("brass_b"), 0, "not the second yet")
15 test.wait(3.2)
16 test.same(test.heard("brass_b"), 1, "then the second")
17end)
18
19test.case("winding it again while it plays does nothing until the tune's done", function()
20 local p = test.player("Ada", { survival = true, carrying = { ["Moonsilver music box"] = 1 } })
21 test.hold(p, "Moonsilver music box")
22 test.use_item(p, vector.create(0, 1, 0))
23 test.wait(0.5)
24 test.use_item(p, vector.create(0, 1, 0))
25 test.wait(0.2)
26 test.same(test.heard("moonsilver_a"), 1, "it doesn't start over")
27 test.wait(6)
28 test.use_item(p, vector.create(0, 1, 0))
29 test.wait(0.2)
30 test.same(test.heard("moonsilver_a"), 2, "but it plays again once it's done")
31end)
32
33test.case("every box is an item of its own, one to a slot", function()
34 for _, name in { "Brass music box", "Gnome music box", "Moonsilver music box", "Wooden music box" } do
35 local it = world.item(name)
36 test.check(it ~= nil and it.by == "music-boxes" and it.stack == 1, name)
37 end
38end)
39
40test.case("other things in hand play nothing", function()
41 local p = test.player("Ada", { survival = true, carrying = { Planks = 1 } })
42 test.hold(p, "Planks")
43 test.use_item(p, vector.create(0, 1, 0))
44 test.wait(0.2)
45 test.same(test.heard("brass_a") + test.heard("gnome_a") + test.heard("moonsilver_a") + test.heard("wooden_a"), 0, "no tune")
46end)