Skip to main content

Moonaltarlink

Overview

This component enables an entity to dynamically link with and track a set of moon altars, calculating and occupying the centroid position of the linked altars. When linked, it assigns itself to each altar's moonaltarlinktarget.link property and invokes optional callbacks on both the altars and itself. When broken, it nullifies those references and triggers unlink callbacks.

Dependencies & Tags

  • Requires target altars to have the moonaltarlinktarget component.
  • Does not automatically add or remove entity tags.
  • Uses Transform component on self.inst and target altars for position management.

Properties

PropertyTypeDefault ValueDescription
instEntity(injected)Reference to the entity this component is attached to.
altarstable or nilnilArray of altar entities currently linked. Populated on EstablishLink, cleared on BreakLink.
onlinkfnfunction or nilnilOptional callback invoked after link establishment; called as onlinkfn(self.inst, altars).
onlinkbrokenfnfunction or nilnilOptional callback invoked after link is broken; called as onlinkbrokenfn(self.inst, self.altars).

Main Functions

EstablishLink(altars)

  • Description: Links the component's entity to a list of moon altar entities. Computes the arithmetic mean of the X and Z world positions of all altars and moves the entity to that centroid (Y is set to 0). For each altar, sets moonaltarlinktarget.link to self.inst and triggers the altar's onlinkfn if defined.
  • Parameters:
    altars (table) — An array (list) of altar entities, each expected to have the moonaltarlinktarget component.
  • Description: Severs all existing links to altars. Clears moonaltarlinktarget.link on each altar, invokes the altar's onlinkbrokenfn if defined, and finally calls self.onlinkbrokenfn (if set). Resets the altars array to nil.
  • Parameters: None.

Events & Listeners

None. This component does not register or dispatch any events via inst:ListenForEvent or inst:PushEvent.