core
The machinery every Trapwright piece shares: the registry of placed pieces, host authority and state replication over the dungeonKit:state, :all, :hello, :act and :evt channels, the shared host clock, events, bodies and teams through SecondWind (`K.hurt` calls `HK.damage`), the u…
dungeonKit.core
The machinery every Trapwright piece shares: the registry of placed pieces, host authority and state replication over the dungeonKit:state, :all, :hello, :act and :evt channels, the shared host clock, events, bodies and teams through SecondWind (K.hurt calls HK.damage), the use interaction, the per-player secret save in runtime_data and the rewrite hook. The kit's other modules define their pieces with K.define; game code uses dungeonKit.api instead.
Since 1.0.1: get and place treat a piece whose root entity died with a play session as gone (place builds it fresh, purgeDead drops every such piece), pieces placed during play are cleared when play stops (engine.onModeChange), and tick animates a piece's look only within setVisualRange (60 m) of the local avatar while host logic always runs (visualStats counts looks run and skipped).
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2dungeonKit.core: the machinery every trap, secret, puzzle, door and bridge shares. A registry of placed pieces, the authority (host) that owns their state and replicates it to every peer, the shared clock (the host's clock, measured on every state sync), events, who a piece may hurt (teams through SecondWind), the rewrite hook, per-player secret counters saved in runtime_data, and the local player's "use" interaction.
isAuthority( ) → boolean
True on the machine that owns every piece's state: the host, or this machine when playing alone or in edit.
now( ) → number
Seconds on the shared clock (the host's), the same on every machine.
on(evt: string, fn: (any) → void
Listen to a kit event on this machine ("*" for all). Returns a connection with :Disconnect().
| arg | type | description |
|---|---|---|
| evt | string | |
| fn | (any |
deliver(evt: string, payload: any) → void
| arg | type | description |
|---|---|---|
| evt | string | |
| payload | any |
emit(evt: string, payload: any?) → void
Fire an event here and on every other machine.
| arg | type | description |
|---|---|---|
| evt | string | |
| payload | any? |
vec(p: any) → void
| arg | type | description |
|---|---|---|
| p | any |
isTemplate(id: string) → boolean
Is this body a player template (inside a PlayerPrototype) rather than a real player?
| arg | type | description |
|---|---|---|
| id | string |
bodies( ) → void
Every living body with SecondWind health: { id, x, y, z, team, player }. Player templates are left out.
catches(target: string?, body: any) → boolean
Does a piece aimed at `target` ("players" | "monsters" | "all" | "nobody") catch this body?
| arg | type | description |
|---|---|---|
| target | string? | |
| body | any |
localBody( ) → any
The local player's body, or nil.
hurt(piece: any, bodyId: string, amount: number, opts: any?) → boolean
Hurt a body through SecondWind for a piece (authority only), at most once per `every` seconds per piece and body.
| arg | type | description |
|---|---|---|
| piece | any | |
| bodyId | string | |
| amount | number | |
| opts | any? |
slowFactor(bodyId: string) → number
The speed factor a frost field leaves on a body (1 = not slowed). Movement code can multiply by it.
| arg | type | description |
|---|---|---|
| bodyId | string |
define(defs: { [string]: any }) → void
Register definitions: defs[kind] = { family, title, size, build, onState, tick, host, state0, acts, usable, rewrite }.
| arg | type | description |
|---|---|---|
| defs | { [string]: any } |
kinds(family: string?) → void
Every defined kind id of a family (or all), sorted.
| arg | type | description |
|---|---|---|
| family | string? |
def(kind: string) → any return S
The definition of a kind.
| arg | type | description |
|---|---|---|
| kind | string |
alive(piece: any) → boolean
A placed piece by id.
| arg | type | description |
|---|---|---|
| piece | any |
forget(id: string) → void
Drop a piece whose look entities are gone (a play session ended under it) without touching entities.
| arg | type | description |
|---|---|---|
| id | string |
get(id: string) → any
A placed piece by id, or nil. A piece whose root entity no longer exists (its play session ended) is forgotten and reads nil, so placing it again builds it fresh.
| arg | type | description |
|---|---|---|
| id | string |
purgeDead( ) → number
Forget every piece whose root entity is gone. Returns how many were dropped.
all( ) → void
Every placed piece, in placement order.
toLocal(piece: any, x: number, y: number, z: number) → void
Piece local frame: origin at `at`, turned `yaw` degrees about +Y; +Z is the piece's front.
| arg | type | description |
|---|---|---|
| piece | any | |
| x | number | |
| y | number | |
| z | number |
toWorld(piece: any, lx: number, ly: number, lz: number) → void
| arg | type | description |
|---|---|---|
| piece | any | |
| lx | number | |
| ly | number | |
| lz | number |
inBox(piece: any, target: string?, cx: number, cy: number, cz: number, hx: number, hy: number, hz: number) → void
Bodies in a piece's local box (centre cx,cy,cz; half sizes hx,hy,hz) that `target` catches (nil = everyone).
| arg | type | description |
|---|---|---|
| piece | any | |
| target | string? | |
| cx | number | |
| cy | number | |
| cz | number | |
| hx | number | |
| hy | number | |
| hz | number |
inRadius(piece: any, target: string?, lx: number, lz: number, r: number) → void
Bodies within `r` metres (flat distance) of a local point that `target` catches (nil = everyone).
| arg | type | description |
|---|---|---|
| piece | any | |
| target | string? | |
| lx | number | |
| lz | number | |
| r | number |
applyState(piece: any, st: any) → void
| arg | type | description |
|---|---|---|
| piece | any | |
| st | any |
set(piece: any, patch: { [string]: any }) → void
Change a piece's shared state (authority only): merged, numbered and sent to every machine.
| arg | type | description |
|---|---|---|
| piece | any | |
| patch | { [string]: any } |
act(id: string, action: string, arg: any?, by: string?) → void
Ask the authority to run an action on a piece. Runs at once on the authority, else is sent there. Returns ok, why on the authority.
| arg | type | description |
|---|---|---|
| id | string | |
| action | string | |
| arg | any? | |
| by | string? |
_runAct(id: string, action: string, arg: any?, by: string?) → void
| arg | type | description |
|---|---|---|
| id | string | |
| action | string | |
| arg | any? | |
| by | string? |
retarget(piece: any, target: any) → void
| arg | type | description |
|---|---|---|
| piece | any | |
| target | any |
rewrite(piece: any, kv: any, by: any) → void
| arg | type | description |
|---|---|---|
| piece | any | |
| kv | any | |
| by | any |
stateMsgReceived(_from: number, id: any, patch: any) → void
| arg | type | description |
|---|---|---|
| _from | number | |
| id | any | |
| patch | any |
place(kind: string, opts: any?) → any
Make a piece: kind, opts { id, at, yaw, look, target, damage, trigger, ... }. Builds its look on this machine; the authority owns its state.
| arg | type | description |
|---|---|---|
| kind | string | |
| opts | any? |
_build(piece: any) → void
| arg | type | description |
|---|---|---|
| piece | any |
relook(id: string, look: string) → void
Rebuild a piece in another look, keeping its state.
| arg | type | description |
|---|---|---|
| id | string | |
| look | string |
remove(id: string) → void
Remove a piece and its look.
| arg | type | description |
|---|---|---|
| id | string |
clear( ) → void
Remove every piece.
onModeChange(newMode: string, oldMode: string) → void
Play ends: the pieces placed during it lose their entities with the session, so they are dropped (and anything else whose root died); pieces placed in edit (galleries) stay.
| arg | type | description |
|---|---|---|
| newMode | string | |
| oldMode | string |
nearest( ) → void
nearestUsable( ) → any
What the local player could use right now: { piece, spot = { label, arg } } or nil.
useNearest( ) → string
The local player uses the nearest usable thing (E key, the prompt, or your own input). Returns the piece id it used.
setVisualRange(metres: number, every: number?) → void
How far from the local player's avatar a piece's look keeps animating, in metres (default 60; 0 animates every piece every frame). `every` > 0 animates far pieces every Nth frame instead of not at all. Host logic (triggers, damage, puzzles) always runs.
| arg | type | description |
|---|---|---|
| metres | number | |
| every | number? |
visualStats( ) → any
Counts of piece looks animated and skipped by distance since the last call: { ran, skipped }.
tick(dt: number) → void
One frame for every piece (the Director calls it). Host logic runs for every piece; a piece's look only animates within the visual range of the local avatar.
| arg | type | description |
|---|---|---|
| dt | number |
setSaveRoot(path: string) → void
Where found secrets are saved in each player's runtime_data store (default "dungeonKit"; keys are <root>/secrets/<id>).
| arg | type | description |
|---|---|---|
| path | string |
store( ) → any
secretKey(id: string) → string
The runtime_data key a secret id is saved under.
| arg | type | description |
|---|---|---|
| id | string |
foundCount( ) → number
How many secrets the local player has found (saved across sessions).
hasFound(id: string) → boolean
Has the local player found this secret (saved)?
| arg | type | description |
|---|---|---|
| id | string |
_onFound(payload: any) → void
A secret was found by `payload.by` (a body id). Every machine hears it; only the finder's machine counts and saves it and plays the full fanfare.
| arg | type | description |
|---|---|---|
| payload | any |
markFound(piece: any, by: string?) → void
The authority marks a secret found by body `by` (nil: the nearest player): every machine hears "found"; the finder's counts it.
| arg | type | description |
|---|---|---|
| piece | any | |
| by | string? |
useRewrite(api: any) → void
Hand the kit a rewrite API (rewriteKit's api, or anything with expose(entityId, spec)) so every piece exposes itself to it. nil turns it off.
| arg | type | description |
|---|---|---|
| api | any |
rewriteSpec(piece: any) → any
The rewrite spec a piece hands to the rewrite API (nil when its kind has none).
| arg | type | description |
|---|---|---|
| piece | any |
apply(key: string, value: any, playerId: any) → void
| arg | type | description |
|---|---|---|
| key | string | |
| value | any | |
| playerId | any |
_refreshRewrite(piece: any) → void
| arg | type | description |
|---|---|---|
| piece | any |
ensureDirector( ) → void
Make sure a Director ticks the kit (spawns one when no scene holds one).
_setDirector(e: any) → void
| arg | type | description |
|---|---|---|
| e | any |
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.