forked from phenom/healer-man
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import {
|
|
clearMobRuntimeRegistry,
|
|
getMobPosition,
|
|
getMobRuntimeTransform,
|
|
nearbyMobRuntimeIds,
|
|
readMobRuntimePosition,
|
|
registerMobRuntime,
|
|
removeMobPosition,
|
|
setMobPosition,
|
|
updateMobRuntimePosition,
|
|
} from "./mobRuntimeRegistry";
|
|
|
|
describe("mob runtime position registry", () => {
|
|
beforeEach(clearMobRuntimeRegistry);
|
|
|
|
it("supports allocation-free frame updates and snapshot reads", () => {
|
|
const unregister = registerMobRuntime("mob-a", [1, 2, 3], 0.4);
|
|
const out: [number, number, number] = [0, 0, 0];
|
|
expect(readMobRuntimePosition("mob-a", out)).toBe(true);
|
|
expect(out).toEqual([1, 2, 3]);
|
|
updateMobRuntimePosition("mob-a", 4, 5, 6, 1.2);
|
|
expect(getMobPosition("mob-a")).toEqual([4, 5, 6]);
|
|
expect(getMobRuntimeTransform("mob-a")).toEqual({ position: [4, 5, 6], yaw: 1.2 });
|
|
unregister();
|
|
expect(getMobPosition("mob-a")).toBeNull();
|
|
});
|
|
|
|
it("sorts nearby mounted mobs by distance", () => {
|
|
setMobPosition("far", [8, 0, 0]);
|
|
setMobPosition("near", [2, 0, 0]);
|
|
setMobPosition("outside", [30, 0, 0]);
|
|
expect(nearbyMobRuntimeIds([0, 0, 0], 10)).toEqual(["near", "far"]);
|
|
removeMobPosition("near");
|
|
expect(nearbyMobRuntimeIds([0, 0, 0], 10)).toEqual(["far"]);
|
|
});
|
|
|
|
it("does not let stale cleanup remove a replacement registration", () => {
|
|
const staleCleanup = registerMobRuntime("mob", [1, 0, 0]);
|
|
registerMobRuntime("mob", [2, 0, 0]);
|
|
staleCleanup();
|
|
expect(getMobPosition("mob")).toEqual([2, 0, 0]);
|
|
});
|
|
});
|