Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

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 Parameter Default type
Placement extends MapObjectPlacement Point
Fields extends MapObjectFields MapObjectFields
Parameter Type
kind string
options MapObjectOptions<Placement, Fields>

MapObject<Placement, Fields>

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,
});