defineMapObject
defineMapObject<
Placement,Fields>(kind,options):MapObject<Placement,Fields>
Declares a kind of object a map places by name, at module scope in a
module src/game.ts imports, so the room, every page and the cli know
it: build stands its entity, with no mesh, and view draws it on a
page. A map’s props places one as { "kind": "lamppost", "position": [x, z], "fields": { ... } }. Unity’s prefab with a custom inspector,
Godot’s scene with exported properties.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Placement extends MapObjectPlacement |
Point |
Fields extends MapObjectFields |
MapObjectFields |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
kind |
string |
options |
MapObjectOptions<Placement, Fields> |
Returns
Section titled “Returns”MapObject<Placement, Fields>
Example
Section titled “Example”export const lamppost = defineMapObject("lamppost", { category: "lights", icon: { glyph: "✦", color: "#ffb46b" }, help: "A lamp that lights at dusk.", fields: z.strictObject({ height: z._default(z.number(), 3.2) }), build: ({ fields }) => ({ collider: { shape: cylinder({ radius: 0.15, height: fields.height }) }, bounds: { size: [0.6, fields.height, 0.6] }, }), view: LamppostView, });