SHA256
Add RenderSession.OnComplete
This commit is contained in:
1 parent
6840395041
commit
4e67cb9b09
4 files changed
+816
-728
No files matched your search
@@ -8,7 +8,7 @@
|
|||||||
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
|
<EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>11</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace ADOFAIRenderer.API;
|
namespace ADOFAIRenderer.API;
|
||||||
|
|
||||||
@@ -62,6 +63,25 @@ public class RenderResult
|
|||||||
ErrorMessage = errorMessage;
|
ErrorMessage = errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RenderResult CreateSuccess(string outputPath, long totalFrames, double fps, TimeSpan renderDuration)
|
||||||
|
{
|
||||||
|
var fileSizeBytes = 0L;
|
||||||
|
if (!string.IsNullOrEmpty(outputPath) && File.Exists(outputPath))
|
||||||
|
{
|
||||||
|
try { fileSizeBytes = new FileInfo(outputPath).Length; }
|
||||||
|
catch { /* ignored */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
var videoDuration = fps > 0 ? totalFrames / fps : 0.0;
|
||||||
|
return new RenderResult(true, outputPath, totalFrames, videoDuration, renderDuration, fileSizeBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RenderResult CreateFailure(string? errorMessage, long totalFrames, double fps, TimeSpan renderDuration)
|
||||||
|
{
|
||||||
|
var videoDuration = fps > 0 ? totalFrames / fps : 0.0;
|
||||||
|
return new RenderResult(false, string.Empty, totalFrames, videoDuration, renderDuration, 0, errorMessage ?? "Rendering failed or was cancelled.");
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return Success
|
return Success
|
||||||
|
|||||||
+21
-3
@@ -33,10 +33,13 @@ public class RenderSession
|
|||||||
|
|
||||||
private bool _timePatch = true;
|
private bool _timePatch = true;
|
||||||
private bool _screenPatch = true;
|
private bool _screenPatch = true;
|
||||||
private Func<bool> _endCondition = () => scrController.instance.state == States.Won;
|
|
||||||
|
|
||||||
private string? _outputPath;
|
private string? _outputPath;
|
||||||
|
|
||||||
|
private bool _notification = true;
|
||||||
|
|
||||||
|
private Func<bool>? _endCondition;
|
||||||
|
private Action<RenderResult>? _onComplete;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets whether auto mode is enabled.
|
/// Sets whether auto mode is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -89,6 +92,18 @@ public class RenderSession
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RenderSession WithNotification(bool enabled)
|
||||||
|
{
|
||||||
|
_notification = enabled;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderSession OnComplete(Action<RenderResult> callback)
|
||||||
|
{
|
||||||
|
_onComplete += callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the configured flags and initiates the render session.
|
/// Applies the configured flags and initiates the render session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -99,8 +114,11 @@ public class RenderSession
|
|||||||
RenderContext.Auto = _auto;
|
RenderContext.Auto = _auto;
|
||||||
RenderContext.TimePatch = _timePatch;
|
RenderContext.TimePatch = _timePatch;
|
||||||
RenderContext.ScreenPatch = _screenPatch;
|
RenderContext.ScreenPatch = _screenPatch;
|
||||||
RenderContext.EndCondition = _endCondition;
|
|
||||||
RenderContext.OutputPath = _outputPath;
|
RenderContext.OutputPath = _outputPath;
|
||||||
|
RenderContext.Notification = _notification;
|
||||||
|
|
||||||
|
if (_endCondition is not null) RenderContext.EndCondition = _endCondition;
|
||||||
|
if (_onComplete is not null) RenderContext.OnComplete = _onComplete;
|
||||||
|
|
||||||
RenderManager.Instance.levelPath = levelPath;
|
RenderManager.Instance.levelPath = levelPath;
|
||||||
RenderManager.Instance.Configuration = renderConfig;
|
RenderManager.Instance.Configuration = renderConfig;
|
||||||
|
|||||||
+774
-724
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user