Builtin Library
- ..
- .metadata279 B
- README.md4.2 KB
- edit.module
- init.luau3.9 KB
README.md
prefab.edit (procNode)
Edit the entity records of a prefab, the reusable entity template a spawn copies, and answer the result: add a component to the root, add a child entity, move entities under another, write one entity's id into another's component, join records on, place another prefab under an entity at a local pose, or look an entity up by name. The prefab wired in is left as it was. The parts a graph builds and parents itself are elements: elements.entity makes one and elements.link parents it under another.
prefab.add_component, prefab.entity, prefab.parent, prefab.link, prefab.place and prefab.find each call this node with their what; call those for the single edits, and this node for join. Each edit runs on a copy of the record list (the Luau module edit.module beside it):
add_componentappends{ type, data }to the root's components; an emptytypeis an error.entityappends a record namedname(orfallbackwhennameis empty), with idadd_<n>(n the record count before it), under the entityparentnames, or under the root whenparentis empty or names no entity.parentmoves every record namedname, the root excepted, under the entityparentnames (or the root).linkwrites the id of the first entity namedtointodata[field]of the firsttypecomponent on the first entity namedname, adding that component when the entity holds none;fieldempty takes "target", and an empty or unknown name is an error.joinappends the records ofchildrenafter the prefab's own.placeappends the records ofchildrenrenumbered: each takes the idplace<n>_<its id>(n the record count before it, raised past any id the prefab already holds), itsparent_idand every string in its components' data that names a placed id take the new ids, and each placed root hangs under the entityparentnames (the root whenparentis empty; an unknown name is an error), standing at its own pose inside the frameposition,rotationandscalepose.findanswers{ id, found }: the id of the first record namedname, orfallbackandfound = false.
Inputs
what(String, default "find"; one ofadd_component,entity,parent,link,join,place,find). Which edit runs.prefab(Prefab). The prefab edited: its record list is the first record, the root, then every entity added.name(String, default ""). The entity the edit names: the new child's name (entity), the entities moved (parent), the entity that holds the reference (link) or the entity looked up (find).fallback(String, default ""). The name an emptynametakes (entity), or the idfindanswers when no entity carries the name.parent(String, default ""). The name of the entity a child hangs under (entity, parent, place). Empty takes the root; a name the prefab does not carry takes the root (entity, parent) or is an error (place).to(String, default ""). The name of the entity pointed at (link).type(String, default ""). The component type added (add_component) or written into (link).field(String, default "target"). The key inside the component's data the referenced entity's id lands under (link).data(Record, optional). The component's fields (add_component). Unwired, the component takes its schema's defaults.children(List<Record>, optional). The records appended after the prefab's own (join), or the records of the prefab placed (place).position(List<Float>, default { 0, 0, 0 }). The local position the placed prefab's root stands at under its parent (place).rotation(List<Float>, default { 0, 0, 0, 1 }). The local rotation of the placed prefab's root, a quaternion (x, y, z, w) (place).scale(List<Float>, default { 1, 1, 1 }). The local scale of the placed prefab's root (place).
Outputs
value. The new record list, or{ id, found }forfind. A caller makes a prefab of a record list as{ records = list }.
local extra = g.prefab.record({ name = "extra", id = "9", parent = "0" })
local records = g.prefab.edit({ what = "join", prefab = g.prefab.empty({}), children = { extra } })
local joined = { records = records }