Track time on jester windup
This commit is contained in:
@@ -12,6 +12,8 @@ import type { Mob } from "@/server/game/entity/mob.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 { set_mods_client } from "@/client/mods.ts";
|
||||
import type { Client } from "@/client/client.ts";
|
||||
import type { EntityData } from "@/common/protocol.ts";
|
||||
|
||||
const HALF = "dangerous_business:concrete_wall_slab";
|
||||
@@ -342,6 +344,17 @@ Deno.test("a popped jester runs down the nearest player faster and faster, and b
|
||||
assertEquals(speed(), walking);
|
||||
});
|
||||
|
||||
Deno.test("a jester saved while it winds goes on from where it got to", async () => {
|
||||
const { t } = await setup();
|
||||
const jester = spawn_jester(t, 2);
|
||||
// 39.5 seconds in
|
||||
jester.client_data = { state: 2, since: t.game.world.time - 790 };
|
||||
for (let i = 0; i < 5; i++) t.game.tick();
|
||||
assertEquals(jester.client_data.state, 2);
|
||||
for (let i = 0; i < 15; i++) t.game.tick();
|
||||
assertEquals(jester.client_data.state, 3);
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -404,16 +417,20 @@ Deno.test("a jester keeps its tendrils in the box until it pops, and turns its c
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("a jester's music box plays while it winds, and it screams while it's popped", async () => {
|
||||
Deno.test("a jester's music box and scream play from as far as it's got, for a player who comes upon it partway", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
|
||||
copy_dir("mods/dangerous_business", `${dir}/dangerous_business`);
|
||||
await load_as_player(dir);
|
||||
// the world's time on this client, in ticks
|
||||
const level = { time: 10_000 };
|
||||
set_mods_client({ level } as unknown as Client);
|
||||
const output = new ListOutput();
|
||||
sounds.set_output(output);
|
||||
const jester = {
|
||||
id: "e1",
|
||||
type: JESTER,
|
||||
data: { client_data: { state: 2 } } as EntityData,
|
||||
// winding for 30 seconds already
|
||||
data: { client_data: { state: 2, since: 10_000 - 600 } } as EntityData,
|
||||
age: 0,
|
||||
yaw: 0,
|
||||
head_yaw: 0,
|
||||
@@ -429,23 +446,29 @@ Deno.test("a jester's music box plays while it winds, and it screams while it's
|
||||
);
|
||||
const set_state = (state: number) => {
|
||||
const before = jester.data;
|
||||
jester.data = { client_data: { state } };
|
||||
jester.data = { client_data: { state, since: level.time } };
|
||||
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]);
|
||||
assertEquals(theme.file.id, "dangerous_business:jester/theme");
|
||||
assert(theme.settings.loop);
|
||||
// and a moment of the real clock since it was played
|
||||
assertAlmostEquals(theme.settings.offset, 30, 0.1);
|
||||
|
||||
level.time += 200;
|
||||
set_state(3);
|
||||
assert(theme.stopped);
|
||||
const [scream] = output.playing;
|
||||
assertEquals([scream.file.id, scream.settings.loop], ["dangerous_business:jester/scream", true]);
|
||||
assertEquals(scream.file.id, "dangerous_business:jester/scream");
|
||||
assert(scream.settings.loop);
|
||||
assertAlmostEquals(scream.settings.offset, 0, 0.1);
|
||||
|
||||
set_state(1);
|
||||
assertEquals(output.playing, []);
|
||||
sounds.stop_all();
|
||||
set_mods_client(undefined as unknown as Client);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user