Ven0maus / SOD.Common

A common library for shadows of doubt modding.
MIT License
4 stars 4 forks source link

[FEATURE] Add Interactable pooling/loading events #10

Open ReveredRedHood opened 10 months ago

ReveredRedHood commented 10 months ago

Introduction Add Interactable pooling/loading events and potentially a "safe reference class".

Description of the feature

Lib.Interactable.OnBeforeLoadedOrRespawned(SafeInteractableRef )
Lib.Interactable.OnAfterLoadedOrRespawned(SafeInteractableRef , bool wasPooled)
Lib.Interactable.OnBeforePooled(SafeInteractableRef )
Lib.Interactable.OnAfterPooled(SafeInteractableRef )
Lib.Interactable.OnBeforeDeleted(SafeInteractableRef , bool isSafeDelete)
// potentially an extension like this:
public static SafeInteractableRef GetSafeInteractableRef(this Interactable interactable)
public class SafeInteractableRef {
  InteractablePreset Preset { get; } // never deleted
  bool TryGetInteractable(out Interactable) // can be explicitly deleted
  bool TryGetController(out InteractableController) // deleted when interactable despawns
  bool TryGetSpawnedObject(out GameObject) // deleted when interactable despawns
}

Feature usage The pooling/loading events allow mod authors to respond if an interactable is pooled or re-loaded. This is important when a mod needs to change something about one particular instance of a Interactable, rather than the preset, because interactables are made to match their preset when they are re-loaded. The extension method is intended to allow mod authors to safely access (or be denied access to) Interactable data regardless of what is happening to the Interactable.

Dependencies and Prerequisites Does this feature require any new dependencies? No

Implementation details As a Lib helper with patches, and as an extension method and class definition (SafeInteractableRef).

ReveredRedHood commented 10 months ago

I'm not sure if this is needed now that we have InteractableInstanceData.

Ven0maus commented 10 months ago

I suppose it is still useful to have a feature to detect if an interactable is being pooled or spawned from the pool. As we currently only have access to starting/completing/cancelling actions.