using System;
using ADOFAIRenderer.Core;
using ADOFAIRenderer.Data;
namespace ADOFAIRenderer.API;
///
/// Fluent builder for configuring and starting a render session.
///
public class RenderSession
{
private bool _auto = true;
///
/// Specifies the types of patches that can be configured for a render session.
///
public enum PatchType
{
///
/// Time-related patch controlling frame timing and clock synchronization.
///
Time,
///
/// Screen-related patch controlling screen resolution.
///
Screen
}
private bool _timePatch = true;
private bool _screenPatch = true;
private static Func _endCondition = () => scrController.instance.state == States.Won;
///
/// Sets whether automatic rendering is enabled.
///
/// true to enable automatic rendering; otherwise, false. Default is true.
/// The current instance for method chaining.
public RenderSession WithAuto(bool enabled = true)
{
_auto = enabled;
return this;
}
///
/// Sets whether a specific patch type is enabled for the render session.
///
/// The to configure.
/// true to enable the specified patch; otherwise, false. Default is true.
/// The current instance for method chaining.
/// Thrown when an unsupported is provided.
public RenderSession WithPatch(PatchType patchType, bool enabled = true)
{
switch (patchType)
{
case PatchType.Time: _timePatch = enabled; break;
case PatchType.Screen: _screenPatch = enabled; break;
default: throw new ArgumentOutOfRangeException(nameof(patchType), patchType, null);
}
return this;
}
public RenderSession WithEndCondition(Func endCondition)
{
_endCondition = endCondition;
return this;
}
///
/// Applies the configured flags and initiates the render session.
///
/// The configuration settings for the render session.
/// The file path of the level to render.
public void Start(RenderConfig renderConfig, string levelPath)
{
RenderContext.Auto = _auto;
RenderContext.TimePatch = _timePatch;
RenderContext.ScreenPatch = _screenPatch;
RenderContext.EndCondition = _endCondition;
RenderManager.Instance.levelPath = levelPath;
RenderManager.Instance.Configuration = renderConfig;
RenderManager.Instance.StartLoadingOverride();
RenderManager.Instance.SetupCaptureDirectory();
RenderManager.Instance.SetupGameScene();
}
}