Start working on entities

This commit is contained in:
2026-11-21 10:53:33 -03:00
parent 65865033c1
commit 60a7cae86e
7 changed files with 150 additions and 11 deletions
+12 -2
View File
@@ -3,7 +3,7 @@
// mobs mods define in entities/<name>.json, drawn with a bedrock model from models/<name>.geo.json
import { assert, assertAlmostEquals, assertEquals, assertNotEquals, assertStringIncludes } from "@std/assert";
import { entity_model_from_geo, type EntityBoneJson, validate_entity } from "@/common/mod_data.ts";
import { entity_category, entity_model_from_geo, type EntityBoneJson, validate_entity } from "@/common/mod_data.ts";
import type { Texture } from "@/client/renderer/mod.ts";
import { IDENTITY } from "@/client/rendering/model_math.ts";
import { push_model } from "@/client/rendering/model_renderer.ts";
@@ -82,8 +82,18 @@ Deno.test("an entity needs a texture and a size", () => {
Deno.test("an entity without a model is drawn as its texture, and a scripted one has no ai", () => {
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "scripted", width: 0.25, height: 0.25 }), []);
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "flying", width: 0.25, height: 0.25 }), [
'behavior must be "animal", "monster" or "scripted"',
'behavior must be "animal", "monster", "scripted" or a behavior id like "my_mod:thing"',
]);
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "a:flying", width: 0.25, height: 0.25 }), []);
});
Deno.test("an entity's category is monster for monsters unless it says otherwise", () => {
const entity = { id: "a:b", texture: "a:b", width: 1, height: 1 };
assertEquals(entity_category(entity), "creature");
assertEquals(entity_category({ ...entity, behavior: "monster" }), "monster");
assertEquals(entity_category({ ...entity, behavior: "a:flying", category: "monster" }), "monster");
assertEquals(entity_category({ ...entity, behavior: "monster", category: "creature" }), "creature");
assertEquals(validate_entity({ ...entity, category: "boss" }), ['category must be "monster" or "creature"']);
});
Deno.test("scripted entities stay put and aren't saved with the world", async () => {