using Syntriax.Engine.Core.Exceptions; namespace Syntriax.Engine.Core; public static class UniverseExtensions { public static IUniverseObject InstantiateUniverseObject(this IUniverse universe, params object?[]? args) => universe.InstantiateUniverseObject(args); /// /// Searches through all s to find the specified instance of the type. /// /// Type to be searched through the . /// The specified type if found; otherwise, throws . public static T GetRequiredUniverseObject(this IUniverse universe) where T : class => universe.GetUniverseObject() ?? throw new UniverseObjectNotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} object of type {typeof(T).FullName}"); /// /// Searches through all s to find the specified instance of the type. /// /// Type to be searched through the . /// The specified type if found; otherwise, throws . public static T FindRequiredBehaviour(this IUniverse universe) where T : class => universe.FindBehaviour() ?? throw new BehaviourNotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} with {nameof(IBehaviour)} of type {typeof(T).FullName}"); /// /// Searches through all s and s to find the specified instance of the type. /// /// /// WARNING: This is more expensive compared to or as it combines the two. If you know whether the type is either a type that gets implemented on an or use the method appropriate for it for performance. /// /// Type to be searched through the . /// The specified type if found; otherwise, throws . public static T FindRequired(this IUniverse universe) where T : class => universe.Find() ?? throw new NotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} or {nameof(IBehaviour)} of type {typeof(T).FullName}"); }