Class StructureActivityManager

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.api.restartable.Restartable
nl.pim16aap2.animatedarchitecture.core.animation.StructureActivityManager
All Implemented Interfaces:
IDebuggable, IRestartable, StructureDeletionManager.IDeletionListener

@Singleton public final class StructureActivityManager extends Restartable implements StructureDeletionManager.IDeletionListener, IDebuggable
Keeps track of which structures are currently active.
  • Constructor Details

  • Method Details

    • registerAnimation

      @CheckReturnValue public OptionalLong registerAnimation(Structure targetStructure, boolean requiresWriteAccess)
      Attempts to register a new animation.

      The registration attempt returns an optional long. This value is the stamp of the registry. In case the registered animation is registered with read/write access, the stamp will be a unique, non-zero value.

      Registrations with read-only access all share a single stamp for all animators for the same structure UID. The stamp is still unique between each group of animators.

      Once registered, the animator for the animation can be inserted using addAnimator(long, Animator).

      Parameters:
      targetStructure - The structure being animated.
      requiresWriteAccess - True to register the animation with read/write access. Only one such animator can be active per structure.
      Returns:
      The stamp of the animation entry if it was registered successfully. If the animation could not be registered, OptionalLong.empty() is returned.
    • unregisterAnimation

      public void unregisterAnimation(long uid, long stamp)
      Unregisters an animation.
      Parameters:
      uid - The UID of the structure for which the animation was registered.
      stamp - The stamp of the registry entry.
      Throws:
      IllegalArgumentException - If an entry was found and its stamp does not match the provided stamp.
    • stopAnimatorsWithWriteAccess

      public void stopAnimatorsWithWriteAccess(long uid)
      Stops an active animator with write access if one currently exists for the structure with the provided UID.

      See Animator.stopAnimation().

      Parameters:
      uid - The UID of the structure being animated.
    • stopAnimators

      public void stopAnimators(long uid)
      Stops all active animators regardless of read/write access.
      Parameters:
      uid - The UID of the structure whose animation(s) to stop.
    • addAnimator

      public void addAnimator(long stamp, Animator animator)
      Stores a Animator in the appropriate slot in animators
      Parameters:
      stamp - The stamp of the entry.

      The stamp is used to validate the correct

      animator - The Animator.
      Throws:
      IllegalStateException - When no existing entry exists for the provided animator.
    • getBlockMovers

      public Stream<Animator> getBlockMovers()
      Gets all the currently active Animators.
      Returns:
      All the currently active Animators.
    • onStructureDeletion

      public void onStructureDeletion(IStructureConst structure)
      Description copied from interface: StructureDeletionManager.IDeletionListener
      Called when a structure is deleted.
      Specified by:
      onStructureDeletion in interface StructureDeletionManager.IDeletionListener
      Parameters:
      structure - The structure that was deleted.
    • shutDown

      public void shutDown()
      Description copied from interface: IRestartable
      Handles a shutdown.
      Specified by:
      shutDown in interface IRestartable
    • initialize

      public void initialize()
      Description copied from interface: IRestartable
      Handles the initialization.
      Specified by:
      initialize in interface IRestartable
    • getDebugInformation

      public String getDebugInformation()
      Description copied from interface: IDebuggable
      Gets the debug information for this object.
      Specified by:
      getDebugInformation in interface IDebuggable
      Returns:
      The debug information or null if there's nothing to log at this time.