using System.Collections.Generic; using System.Linq; using EcsRx.Extensions; using EcsRx.Infrastructure; using EcsRx.Infrastructure.Extensions; using EcsRx.Plugins.ReactiveSystems.Systems; using EcsRx.Systems; namespace EcsRx.Plugins.ReactiveSystems.Extensions { public static class IEcsRxApplicationExtensions { /// /// Resolve all systems which have been bound in the order they need to be triggered /// /// The application to act on /// The ordering here will be Setup, Anything else public static IEnumerable GetAllBoundReactiveSystems(this IEcsRxApplication application) { var allSystems = application.Container.ResolveAll(); return allSystems .OrderByDescending(x => x is ISetupSystem) .ThenByPriority(); } /// /// Resolve all systems which have been bound and register them in order with the systems executor /// /// The application to act on /// The ordering here will be Setup, Anything else public static void StartAllBoundReactiveSystems(this IEcsRxApplication application) { var orderedSystems = GetAllBoundReactiveSystems(application); orderedSystems.ForEachRun(application.SystemExecutor.AddSystem); } } }