component_snapshot
Serialized snapshots of script-component public data.
component_snapshot
Serialized snapshots of script-component public data.
A component's public table is a live proxy — its fields live behind
__iter / __index metamethods, so copying or JSON-encoding the proxy
directly yields an empty table. This module materializes the plain,
serializable form. It is the script-component parallel to ecs.snapshot
(native components).
local componentSnapshot = require("modules.component_snapshot")
-- one component: live proxy -> plain table
local data = componentSnapshot.snapshot(entity(id).component.get("Camera"))
-- whole entity: { [type] = data }, named/multi instances nested as
-- { [type] = { [instanceName or "__default"] = data } }
local all = componentSnapshot.snapshotEntity(entity(id))
componentSnapshot.plainCopy(value) materializes ONE live value the same
way — a table behind a proxy is walked into a plain table, every other
value passes through — for callers reading a single field rather than a
whole component.
Serialized form: entity refs become id strings, asset refs become
{ __ref, name, type } envelopes, vectors and colors their plain-table
forms; framework functions are omitted. snapshot returns nil for a proxy
with no serializable fields.
Persistence (scene serializer, bundle capture, prototype spawn) and
inspection tooling (debug.inspect) read component data through this
module. Live gameplay reads and writes stay on the proxy itself via
entity(id).component.get / getAll.
Scoped to this part · feeds back into the world's score.