Animators and coilhead animations

This commit is contained in:
2026-11-21 21:54:02 -03:00
parent 69ad4b80d0
commit 0c711b8163
21 changed files with 960 additions and 34 deletions
+30 -2
View File
@@ -9,7 +9,8 @@ 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, test_game, test_mob } from "./helpers.ts";
import { copy_dir, errors_during, load_as_player, test_game, test_mob } from "./helpers.ts";
import { animation_for } from "@/client/rendering/entity_animators.ts";
const HALF = "dangerous_business:concrete_wall_slab";
const CONNECTS = "dangerous_business:floor_grate";
@@ -138,15 +139,18 @@ function spawn_coilhead(t: Awaited<ReturnType<typeof setup>>["t"]) {
Deno.test("a coilhead can't move while a player looks at it, and comes for them once they look away", async () => {
const { t } = await setup();
const coilhead = spawn_coilhead(t);
const coilhead = spawn_coilhead(t) as Mob;
for (let i = 0; i < 100; i++) t.game.tick();
assertAlmostEquals(coilhead.x, 0.5, 1e-6);
assertAlmostEquals(coilhead.z, -2.5, 1e-6);
// what its animator reads
assertEquals(coilhead.client_data.frozen, true);
// looking south, with it behind her
t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: Math.PI, pitch: 0 });
for (let i = 0; i < 100; i++) t.game.tick();
assert(coilhead.z > 0, `it only got to z ${coilhead.z}`);
assertEquals(coilhead.client_data.frozen, undefined);
});
Deno.test("a player can't stop a coilhead through a wall", async () => {
@@ -251,3 +255,27 @@ Deno.test("a coilhead seen while it waits at a closed door stops waiting, and do
assert(!open(), "it opened the door while it was seen");
assertEquals(coilhead.navigation.blocked_by, undefined);
});
// 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_" });
copy_dir("mods/dangerous_business", `${dir}/dangerous_business`);
await load_as_player(dir);
const coilhead = (frozen: boolean) => ({
id: "e1",
type: COILHEAD,
data: frozen ? { client_data: { frozen: true } } : {},
age: 0,
yaw: 0,
head_yaw: 0,
pitch: 0,
walk_animation: () => ({ position: 0, speed: 0 }),
attack_animation: () => 0,
});
const head = (frozen: boolean, time: number) => animation_for(coilhead(frozen))!.pose(time)!.get("head")?.rotation;
assertNotEquals(head(true, 5), [0, 0, 0]);
assertEquals(head(false, 5), [0, 0, 0]);
// it's over in under a minute
assertEquals(head(true, 1200), head(false, 1200));
Deno.removeSync(dir, { recursive: true });
});