docs
Systems
Infrastructure
ApplicationSystem
Public API Reference

ApplicationConstants

Namespace: SaffronLibrary.Prime.Systems.Application

Static class of shared application constants.

public static class ApplicationConstants
{
    public const float PausedGameSpeed = 0f;
}
MemberDescription
PausedGameSpeedTime scale value that stops game time. Intended for use with Time.timeScale.

ApplicationCoordinator

Namespace: SaffronLibrary.Prime.Systems.Application

Abstract MonoBehaviour that implements IInitializable and IAsyncInitializable. It is the application's entry point and lifecycle manager. Attach a concrete subclass to a root GameObject in the startup scene.

public abstract class ApplicationCoordinator : MonoBehaviour, IInitializable, IAsyncInitializable

Public static fields

public static ApplicationCoordinator Instance;

Global singleton instance. A TODO in the source notes the intent to remove this singleton.

Protected fields (for subclasses)

protected ApplicationLogicManager logicManager;
protected IApplicationLifecycleHandler lifecycleHandler;
protected IApplicationLifecycleAdapter lifecycleAdapter;
FieldDescription
logicManagerOwns focus-loss timing. Created in Init.
lifecycleHandlerThe project's lifecycle handler. Set by InitializeLifecycle.
lifecycleAdapterThe project's lifecycle adapter. Set by InitializeLifecycle.

Methods

protected void Awake()

Enforces the singleton. The first instance is stored in Instance, marked DontDestroyOnLoad, and registered with InitializationRegistry as both IInitializable and IAsyncInitializable. Duplicates are destroyed.

public virtual void Init()

Creates logicManager as a new ApplicationLogicManager. Called during the sync initialization phase.

public async Task InitAsync()

Subscribes InitializeApplication to SaffronLibrarySignals.SystemsReady using SignalBus.WhenRaised, then awaits InitializeVolumeState.

public virtual void InitializeApplication()

Calls RegisterPlatformModules, RunPlatformModules, InitializeStartupPresentation, and the lifecycle setup. Runs when SystemsReady is raised.

public void SetLifecycleHandler(IApplicationLifecycleHandler handler)

Assigns lifecycleHandler.

public void SetLifecycleAdapter(IApplicationLifecycleAdapter adapter)

Assigns lifecycleAdapter.

public void ProcessQuery(IQuery query)

Routes a query by verb and subject. For QueryVerb.Get with subject ApplicationSubjects.Focus, it sets CoreParamKeys.Duration on the query result to the focus-loss duration. Other combinations are ignored.

Protected abstract hooks

protected abstract void InitializeStartupPresentation();
protected abstract Task InitializeVolumeState();
protected abstract void RegisterPlatformModules();
protected abstract void RunPlatformModules();
protected abstract IApplicationLifecycleHandler CreateLifecycleHandler();
protected abstract IApplicationLifecycleAdapter CreateLifecycleAdapter();
HookDescription
InitializeStartupPresentationProject-specific startup presentation.
InitializeVolumeStateProject-specific volume restoration, awaited during InitAsync.
RegisterPlatformModulesRegisters platform-specific modules.
RunPlatformModulesRuns registered platform modules.
CreateLifecycleHandlerCreates the project's lifecycle handler.
CreateLifecycleAdapterCreates the project's lifecycle adapter.

ApplicationFlowController

Namespace: SaffronLibrary.Prime.Systems.Application

Flow controller for Domain.Application. Derives from FlowController.

public class ApplicationFlowController : FlowController
protected override Domain Domain => Domain.Application;

Property. Identifies the domain this controller owns.

public override void Init()

Calls base.Init() to register the command handler, then registers OnQuery with the QueryBus for Domain.Application.

protected void OnQuery(IQuery query)

Forwards the query to ApplicationCoordinator.Instance.ProcessQuery.

protected override void HandleCommand(ICommand cmd)

Empty. No commands are routed through Domain.Application.

ApplicationFlowService

Namespace: SaffronLibrary.Prime.Systems.Application

public static partial class ApplicationFlowService
public static void ResetLocalData(Action onReload)

Calls PlayerPrefs.DeleteAll(), then invokes onReload if it is not null. The source remarks describe this as an irreversible reset of all local data.

ApplicationInterfaces

Namespace: SaffronLibrary.Prime.Systems.Application.Interfaces

public interface IApplicationLifecycleHandler
{
    void OnFocusChanged(bool hasFocus);
}
MemberDescription
OnFocusChanged(bool hasFocus)Called when application focus changes.
public interface IApplicationLifecycleAdapter
{
    void Initialize(IApplicationLifecycleHandler handler);
    float GetRealtimeSinceStartup();
}
MemberDescription
Initialize(IApplicationLifecycleHandler handler)Assigns the handler that receives forwarded events.
GetRealtimeSinceStartup()Returns the engine's running time in seconds since startup.

ApplicationKeyNames

Namespace: SaffronLibrary.Prime.Systems.Application

public static class ApplicationKeyNames
{
    public const string HasFocus = Base + ".hasfocus";
    public const string Subject = Base + ".subject";
}
MemberDescription
HasFocusName for the focus state key. Resolves to core.application.hasfocus.
SubjectName for the subject key. Resolves to core.application.subject.

The private Base constant is core.application.

ApplicationParamKeys

Namespace: SaffronLibrary.Prime.Systems.Application

public static class ApplicationParamKeys
{
    public static readonly ParamKey<bool> HasFocus;
    public static readonly ParamKey<ApplicationSubjects> ApplicationSubject;
}
MemberDescription
HasFocusParamKey<bool> for whether the application has OS-level focus.
ApplicationSubjectParamKey<ApplicationSubjects> for the subject a message is about.

ApplicationEventFactory

Namespace: SaffronLibrary.Prime.Systems.Application

public static class ApplicationEventFactory
public static void OnFocusChanged(bool hasFocus)

Raises an Event on Domain.Application with verb ApplicationEventVerb.Changed, subject ApplicationSubjects.Focus, and the HasFocus param set to hasFocus.

public static void OnApplicationQuit()

Raises an Event on Domain.Application with verb ApplicationEventVerb.Quit and subject ApplicationSubjects.Application.

ApplicationEventVerb

Namespace: SaffronLibrary.Prime.Systems.Application

public enum ApplicationEventVerb
{
    Changed = 0,
    Quit = 1,
}
ValueDescription
ChangedAn application state changed, such as focus.
QuitThe application is quitting.

ApplicationLifecycleHandler

Namespace: SaffronLibrary.Prime.Systems.Application

Abstract base for lifecycle handlers. Implements IApplicationLifecycleHandler.

public abstract class ApplicationLifecycleHandler : IApplicationLifecycleHandler
public void OnFocusChanged(bool hasFocus)

Not overridable. Calls ApplicationEventFactory.OnFocusChanged(hasFocus), then ProcessFocusChanged(hasFocus).

protected abstract void ProcessFocusChanged(bool hasFocus)

Project-specific reaction to a focus change.

UnityLifecycleAdapter

Namespace: SaffronLibrary.Prime.Systems.Application

MonoBehaviour that implements IApplicationLifecycleAdapter.

public class UnityLifecycleAdapter : MonoBehaviour, IApplicationLifecycleAdapter
public void Initialize(IApplicationLifecycleHandler handler)

Stores the handler that receives forwarded events.

public float GetRealtimeSinceStartup()

Returns Time.realtimeSinceStartup.

The adapter also has two private Unity callbacks, OnApplicationFocus(bool hasFocus) and OnApplicationQuit(). The first forwards focus changes to the handler if one is set. The second calls ApplicationEventFactory.OnApplicationQuit().

ApplicationLogicManager

Namespace: SaffronLibrary.Prime.Systems.Application

Plain C# class that tracks focus-loss timing.

public class ApplicationLogicManager
public void SetFocusLossTime(float timeSinceStartup)

Stores the given time as the last focus-loss time.

public float GetFocusLossDuration(float timeSinceStartup)

Returns timeSinceStartup minus the stored focus-loss time. If SetFocusLossTime has never been called, the stored time is 0, so the result is the time since startup.

ApplicationQueryFactory

Namespace: SaffronLibrary.Prime.Systems.Application

public static class ApplicationQueryFactory
public static float GetFocusLossDuration()

Creates a Query for Domain.Application with verb QueryVerb.Get and subject ApplicationSubjects.Focus, then returns the CoreParamKeys.Duration result through BusUtility.AskAndGet. Throws if the result is missing.

ServiceLocator

Namespace: SaffronLibrary.Prime.Systems.Application

public static class ServiceLocator
public static void Initialize(BusRegistry registry)

Stores the BusRegistry. Intended to be called once during bootstrap.

public static BusRegistry GetBusRegistry()

Returns the stored BusRegistry, or null if Initialize has not been called.

ApplicationSubjects

Namespace: SaffronLibrary.Prime.Systems.Application

public enum ApplicationSubjects
{
    Focus = 0,
    Application = 1,
}
ValueDescription
FocusSubject for focus-related events and queries.
ApplicationSubject for application-level events, such as quitting.