Jester and coilhead sounds
This commit is contained in:
@@ -9,8 +9,10 @@ import { ItemStack } from "@/common/inventory.ts";
|
||||
import { get_state_value, set_state_value } from "@/common/utils.ts";
|
||||
import { create_entity } from "@/server/game/entity/entity_types.ts";
|
||||
import type { Mob } from "@/server/game/entity/mob.ts";
|
||||
import { copy_dir, errors_during, load_as_player, test_game, test_mob } from "./helpers.ts";
|
||||
import { copy_dir, errors_during, ListOutput, load_as_player, test_game, test_mob, VOLUMES } from "./helpers.ts";
|
||||
import { animation_for } from "@/client/rendering/entity_animators.ts";
|
||||
import { sounds } from "@/client/sounds.ts";
|
||||
import type { EntityData } from "@/common/protocol.ts";
|
||||
|
||||
const HALF = "dangerous_business:concrete_wall_slab";
|
||||
const CONNECTS = "dangerous_business:floor_grate";
|
||||
@@ -154,6 +156,26 @@ Deno.test("a coilhead can't move while a player looks at it, and comes for them
|
||||
assertEquals(coilhead.client_data.frozen, undefined);
|
||||
});
|
||||
|
||||
// the sounds conn was sent since last asked, as [sound, where]: the entity it follows, or the point it's at
|
||||
const sounds_sent = (t: Awaited<ReturnType<typeof setup>>["t"], conn: number): [string, unknown][] =>
|
||||
t.take(conn).filter((m) => m.type === "sound").map((m) => [m.sound, m.entity ?? m.at]);
|
||||
|
||||
Deno.test("a coilhead springs once when a player's look freezes it", async () => {
|
||||
const { t } = await setup();
|
||||
// looking south, away from it
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: Math.PI, pitch: 0 });
|
||||
const coilhead = spawn_coilhead(t);
|
||||
for (let i = 0; i < 5; i++) t.game.tick();
|
||||
assertEquals(sounds_sent(t, 1), []);
|
||||
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: 0, pitch: 0 });
|
||||
for (let i = 0; i < 40; i++) t.game.tick();
|
||||
assertEquals(sounds_sent(t, 1), [
|
||||
["dangerous_business:coilhead/stop", coilhead.id],
|
||||
["dangerous_business:coilhead/seen", coilhead.id],
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("a player can't stop a coilhead through a wall", async () => {
|
||||
const { t } = await setup();
|
||||
for (let x = -3; x <= 3; x++) {
|
||||
@@ -257,6 +279,24 @@ Deno.test("a coilhead seen while it waits at a closed door stops waiting, and do
|
||||
assertEquals(coilhead.navigation.blocked_by, undefined);
|
||||
});
|
||||
|
||||
Deno.test("a factory door sounds as it opens and closes, for everyone but the player whose click their client heard", async () => {
|
||||
const { t, state } = await setup();
|
||||
const { open } = door_in_wall(t, state);
|
||||
t.join(2, "bob");
|
||||
t.send(2, { type: "move", x: 1.5, y: 100, z: 2.5, yaw: 0, pitch: 0 });
|
||||
t.game.tick();
|
||||
t.take(1);
|
||||
t.take(2);
|
||||
|
||||
const click = () => t.send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "south", hit: [0.5, 0.5, 1] });
|
||||
click();
|
||||
assert(open());
|
||||
assertEquals(sounds_sent(t, 1), []);
|
||||
assertEquals(sounds_sent(t, 2), [["dangerous_business:door/open", [0.5, 101, 0.5]]]);
|
||||
click();
|
||||
assertEquals(sounds_sent(t, 2), [["dangerous_business:door/close", [0.5, 101, 0.5]]]);
|
||||
});
|
||||
|
||||
// a jester 6 blocks north of alice, in a state from its client data like one that was saved
|
||||
function spawn_jester(t: Awaited<ReturnType<typeof setup>>["t"], state?: number) {
|
||||
const jester = create_entity(t.game.entities, JESTER)! as Mob;
|
||||
@@ -302,6 +342,20 @@ Deno.test("a popped jester runs down the nearest player faster and faster, and b
|
||||
assertEquals(speed(), walking);
|
||||
});
|
||||
|
||||
Deno.test("a jester's crank clicks once a second while it winds, and it pops once", async () => {
|
||||
const { t } = await setup();
|
||||
const jester = spawn_jester(t, 2);
|
||||
for (let i = 0; i < 100; i++) t.game.tick();
|
||||
const cranking = sounds_sent(t, 1);
|
||||
assertEquals(cranking.length, 5);
|
||||
assertEquals(new Set(cranking.map(([sound]) => sound)), new Set(["dangerous_business:jester/turn_crank"]));
|
||||
|
||||
for (let i = 0; i < 1000 && jester.client_data.state !== 3; i++) t.game.tick();
|
||||
assertEquals(sounds_sent(t, 1).filter(([sound]) => sound !== "dangerous_business:jester/turn_crank"), [
|
||||
["dangerous_business:jester/pop", jester.id],
|
||||
]);
|
||||
});
|
||||
|
||||
// last, since it loads the mod the way a player gets it, in place of the server's
|
||||
Deno.test("a coilhead's head springs back and forth when it freezes, and stays still when it stands", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
|
||||
@@ -349,3 +403,49 @@ Deno.test("a jester keeps its tendrils in the box until it pops, and turns its c
|
||||
assertNotEquals(pose(2, 5).get("crank")!.rotation, pose(2, 15).get("crank")!.rotation);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("a jester's music box plays while it winds, and it screams while it's popped", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
|
||||
copy_dir("mods/dangerous_business", `${dir}/dangerous_business`);
|
||||
await load_as_player(dir);
|
||||
const output = new ListOutput();
|
||||
sounds.set_output(output);
|
||||
const jester = {
|
||||
id: "e1",
|
||||
type: JESTER,
|
||||
data: { client_data: { state: 2 } } as EntityData,
|
||||
age: 0,
|
||||
yaw: 0,
|
||||
head_yaw: 0,
|
||||
pitch: 0,
|
||||
walk_animation: () => ({ position: 0, speed: 0 }),
|
||||
attack_animation: () => 0,
|
||||
};
|
||||
const frame = () =>
|
||||
sounds.frame(
|
||||
{ x: 0, y: 0, z: 0, yaw: 0, pitch: 0 },
|
||||
(id) => id === "e1" ? { x: 0, y: 0, z: 3 } : undefined,
|
||||
VOLUMES,
|
||||
);
|
||||
const set_state = (state: number) => {
|
||||
const before = jester.data;
|
||||
jester.data = { client_data: { state } };
|
||||
animation.data_changed(before);
|
||||
frame();
|
||||
};
|
||||
// a player coming near while it already winds hears it too
|
||||
const animation = animation_for(jester)!;
|
||||
frame();
|
||||
const [theme] = output.playing;
|
||||
assertEquals([theme.file.id, theme.settings.loop], ["dangerous_business:jester/theme", false]);
|
||||
|
||||
set_state(3);
|
||||
assert(theme.stopped);
|
||||
const [scream] = output.playing;
|
||||
assertEquals([scream.file.id, scream.settings.loop], ["dangerous_business:jester/scream", true]);
|
||||
|
||||
set_state(1);
|
||||
assertEquals(output.playing, []);
|
||||
sounds.stop_all();
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user