Writeable Replica
Overview
This component acts as a client-side replica for writeable entities (e.g., journals, notes), coordinating access to writeable_classified data, managing UI screen creation, and synchronizing text input with the server via RPC. It ensures safe rendering and interaction when the client gains access to classified writeable data, while avoiding duplication of behavior handled by the master simulation.
Dependencies & Tags
- Relies on the
writeable_classifiedprefab for classification data (spawned on master, referenced on client). - Listens to the
"onremove"event on the attachedclassifiedentity. - Does not add or remove entity tags directly.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | Reference to the entity this component is attached to. |
screen | WriteableScreen? | nil | Reference to the currently active writeable UI screen on the client. |
opentask | Task? | nil | A delayed task to begin writing immediately upon classified attachment; canceled during detach or explicit close. |
classified | writeable_classified? | nil | Reference to the classified component providing writeable content; populated differently on master vs. client. |
ondetachclassified | function? | nil | Callback function to handle classified entity removal; stores self:DetachClassified() to be passed to event listener. |
Main Functions
AttachClassified(classified)
- Description: Attaches a classified component to this writeable replica, sets up removal listener, and schedules immediate writing initialization via
opentask. Called when client receives classified data (e.g., after server sync). - Parameters:
classified: Thewriteable_classifiedcomponent instance to attach.
DetachClassified()
- Description: Removes the classified reference and ends any active writing session, closing the UI if present.
- Parameters: None.
BeginWriting(doer)
- Description: Initiates the writing process. If the master sim
writeablecomponent exists, delegates to it; otherwise, creates the writeable screen on the client (only for local player). - Parameters:
doer: The entity attempting to write (typicallyThePlayer); must be provided for client-side screen creation.
Write(doer, text)
- Description: Writes or updates the writeable’s text. Delegates to the master
writeablecomponent if present; otherwise, sends RPC to server with sanitized text (length-checked) for replication. - Parameters:
doer: The entity performing the write (validated againstThePlayeron client).text: The string ornilto clear the writeable; length enforced viatext:utf8len()against layout-defined max characters.
EndWriting()
- Description: Ends the active writing session. Cancels pending open task, delegates to master
writeableif present, or closes and destroys the local screen. - Parameters: None.
SetWriter(writer)
- Description: Assigns the writer (target entity) for the classified component’s network tracking. Used for permission or attribution logic; asserts that this is not used during normal operation if a master
writeablecomponent exists. - Parameters:
writer: The entity to set as writer (ornilto clear); defaults toself.instif passed asnil.
Events & Listeners
- Listens for
"onremove"event onself.classified, triggeringself.ondetachclassified(which callsDetachClassified()). - Triggers no custom events itself.