/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR.xAPI. */ #if XAPI_REGISTRY_EXISTS using OmiLAXR.Composers; using OmiLAXR.TrackingBehaviours; using xAPI.Registry; namespace OmiLAXR.xAPI.Composers { /// /// Abstract base class for xAPI statement composers. /// Provides common functionality for creating and managing xAPI statements. /// /// A tracking behavior component that implements ITrackingBehaviour public abstract class xApiComposer : Composer where T : ActorPipelineComponent, ITrackingBehaviour { // Builder responsible for constructing xAPI statements /// /// Builds the actor information for xAPI statements /// protected xApiStatement.Builder actor; // Static access to xAPI context definitions /// /// Provides access to global xAPI context definitions /// protected static xAPI_Contexts xapi => xApiRegistry.definitions; public xApiRegistry Registry { get; protected set; } public override string GetDataStandardVersion() => Registry.version; // Base URI for the xAPI statements protected string Uri = ""; /// /// Virtual method to retrieve the current URI. /// Can be overridden by derived classes to provide custom URI logic. /// /// The current URI for xAPI statements protected virtual string GetUri() => Uri; /// /// Initializes the xAPI composer when the component is enabled. /// Sets up the URI and actor information for xAPI statements. /// protected override void OnEnable() { Registry = GetComponentInParent(); // Try to find a global xAPI registry in parent components Uri = Registry.uri; // Initialize the actor builder with the current URI and author actor = new xApiStatement.Builder(GetUri(), GetAuthor(), this); // Call the base OnEnable method base.OnEnable(); } } } #endif