SHA256
Compare commits
12
Commits
0.3.1-INDEV
...
main
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
5efe1d0dd2
|
||
|
|
71e86c0262
|
||
|
|
f72a8acbac | ||
|
|
d90d06c095 | ||
|
|
b66d774cb9 | ||
|
|
d1ba5d5c18 | ||
|
|
7c6210d2c4 | ||
|
|
9e3941e3b5
|
||
|
|
78ea42b368
|
||
|
|
064bd816e8
|
||
|
|
46fc00df9c
|
||
|
|
769f368f66
|
No files matched your search
@@ -17,6 +17,11 @@ internal class GlobalConfig
|
||||
/// GlobalSettings.DefaultOutputDirectory. Ignored while the directory does not exist (see EffectiveOutputDirectory).
|
||||
/// </summary>
|
||||
public string? OutputDirectory { get; set; }
|
||||
/// <summary>
|
||||
/// File name format template chosen in the render configuration window; null or empty selects
|
||||
/// GlobalSettings.DefaultFileNameFormat ("{date} {time}").
|
||||
/// </summary>
|
||||
public string? FileNameFormat { get; set; }
|
||||
/// <summary>Name of the preset last selected or saved in the render configuration window; selected again when it opens.</summary>
|
||||
public string? LastPresetName { get; set; }
|
||||
/// <summary>
|
||||
@@ -72,6 +77,18 @@ internal static class GlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Default file name format template: "{date} {time}".</summary>
|
||||
public const string DefaultFileNameFormat = "{date} {time}";
|
||||
|
||||
/// <summary>
|
||||
/// File name format used for renders without an explicit output path: Current.FileNameFormat when it is set,
|
||||
/// otherwise <see cref="DefaultFileNameFormat"/>.
|
||||
/// </summary>
|
||||
public static string EffectiveFileNameFormat =>
|
||||
string.IsNullOrWhiteSpace(Current.FileNameFormat)
|
||||
? DefaultFileNameFormat
|
||||
: Current.FileNameFormat;
|
||||
|
||||
static GlobalSettings()
|
||||
{
|
||||
Load();
|
||||
|
||||
+22
-3
@@ -940,6 +940,14 @@ internal class RenderManager : MonoBehaviour
|
||||
// Cancelled or failed during the countdown: do not start the encoder
|
||||
if (stage != RenderStage.OnScene) yield break;
|
||||
|
||||
if (Configuration.AdvancedConfig.DisableTileCulling && scrLevelMaker.instance)
|
||||
{
|
||||
foreach (var floor in scrLevelMaker.instance.listFloors)
|
||||
{
|
||||
if (floor) floor.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
frameCount = 0; framesSent = 0;
|
||||
_renderStopwatch.Restart();
|
||||
|
||||
@@ -1045,9 +1053,20 @@ internal class RenderManager : MonoBehaviour
|
||||
var startTime = DateTime.Now;
|
||||
if (RenderContext.OutputPath != null) CurrentOutPath = RenderContext.OutputPath;
|
||||
else {
|
||||
var fileName = startTime.ToString("yyyy-MM-dd HH-mm-ss") +
|
||||
$".{Configuration.AdvancedConfig.FileExtension.TrimStart('.').ToLower()}";
|
||||
CurrentOutPath = Path.Combine(GlobalSettings.EffectiveOutputDirectory, fileName);
|
||||
var format = GlobalSettings.EffectiveFileNameFormat;
|
||||
var ext = Configuration.AdvancedConfig.FileExtension;
|
||||
var baseName = RenderFileNameUtil.FormatFileName(
|
||||
format,
|
||||
startTime,
|
||||
Configuration,
|
||||
GlobalSettings.Current.LastPresetName,
|
||||
levelPath
|
||||
);
|
||||
CurrentOutPath = RenderFileNameUtil.GetUniqueFilePath(
|
||||
GlobalSettings.EffectiveOutputDirectory,
|
||||
baseName,
|
||||
ext
|
||||
);
|
||||
}
|
||||
|
||||
FFmpegNativeEncoder? videoFFmpeg = null;
|
||||
|
||||
@@ -95,6 +95,32 @@ public class AdvancedConfig
|
||||
/// </summary>
|
||||
public bool NonTile { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// When true, the game's bloom (<c>VideoBloom</c>) computes its blur size as if the frame were 720 pixels high, so the
|
||||
/// blur passes on the 198-pixel-high bloom buffer are the same as in a 720p frame at any render height
|
||||
/// (VideoBloomPatch). Default false.
|
||||
/// </summary>
|
||||
public bool HighResBloomCorrection { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// When true, fixes in-game and render bugs during SetFramerate events (where objects disappear on the first frame
|
||||
/// or parallax/tiles lag behind) by deferring manual camera rendering to the end of the frame after all LateUpdates.
|
||||
/// Default true.
|
||||
/// </summary>
|
||||
public bool FixCustomFrameRate { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// When true, prevents floor tiles from being disabled when outside the camera frustum (scrFloor.OnBecameInvisible),
|
||||
/// eliminating the 1-frame update lag/glitch when tiles enter the screen. Default false.
|
||||
/// </summary>
|
||||
public bool DisableTileCulling { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// When true, hides placeholder decorations (default tree-in-circle sprite) that failed to load or are empty.
|
||||
/// Default false.
|
||||
/// </summary>
|
||||
public bool HideFailedDecorations { get; set; } = false;
|
||||
|
||||
/// <summary>File extension of the default output file name, without the dot (e.g. "mkv", "mp4"); selects the container.</summary>
|
||||
public string FileExtension { get; set; } = "mkv";
|
||||
|
||||
@@ -120,6 +146,10 @@ public class AdvancedConfig
|
||||
RandomSeed = source.RandomSeed;
|
||||
ProcessAudio = source.ProcessAudio;
|
||||
NonTile = source.NonTile;
|
||||
HighResBloomCorrection = source.HighResBloomCorrection;
|
||||
FixCustomFrameRate = source.FixCustomFrameRate;
|
||||
DisableTileCulling = source.DisableTileCulling;
|
||||
HideFailedDecorations = source.HideFailedDecorations;
|
||||
FileExtension = source.FileExtension;
|
||||
firePlanetColor = source.firePlanetColor;
|
||||
icePlanetColor = source.icePlanetColor;
|
||||
|
||||
@@ -39,9 +39,16 @@
|
||||
"ui.render_config.output_dir": "Output Directory",
|
||||
"ui.render_config.browse": "Browse...",
|
||||
"ui.render_config.reset_default": "Reset to Default",
|
||||
"ui.render_config.filename_format": "Filename Format",
|
||||
"ui.render_config.filename_format_hint": "Tags: {song}, {artist}, {author}, {date}, {time}, {resolution}, {fps}, {preset}",
|
||||
"ui.render_config.reset_filename_default": "Reset to Default",
|
||||
"ui.render_config.file_extension": "File Extension",
|
||||
"ui.render_config.process_audio": "Process Audio",
|
||||
"ui.render_config.non_tile": "Non-Tile Mode",
|
||||
"ui.render_config.high_res_bloom_correction": "High-Resolution Bloom Correction",
|
||||
"ui.render_config.fix_custom_frame_rate": "Fix Custom FPS Render Timing",
|
||||
"ui.render_config.disable_tile_culling": "Disable Tile Culling",
|
||||
"ui.render_config.hide_failed_decorations": "Hide Failed Decorations",
|
||||
"ui.render_config.random_seed": "Random Seed (Optional)",
|
||||
"ui.render_config.validation_title": "Invalid Settings",
|
||||
"ui.render_config.validation_error": "Please check your input values:\n- Width and Height must be integers > 0\n- Render FPS and Video FPS must be > 0\n- Delay After End must be >= 0",
|
||||
|
||||
@@ -39,9 +39,16 @@
|
||||
"ui.render_config.output_dir": "출력 디렉토리",
|
||||
"ui.render_config.browse": "찾아보기...",
|
||||
"ui.render_config.reset_default": "기본값으로 초기화",
|
||||
"ui.render_config.filename_format": "파일 이름 형식",
|
||||
"ui.render_config.filename_format_hint": "태그: {song}, {artist}, {author}, {date}, {time}, {resolution}, {fps}, {preset}",
|
||||
"ui.render_config.reset_filename_default": "기본값으로 초기화",
|
||||
"ui.render_config.file_extension": "파일 확장자",
|
||||
"ui.render_config.process_audio": "오디오 처리",
|
||||
"ui.render_config.non_tile": "논타일 모드",
|
||||
"ui.render_config.high_res_bloom_correction": "고해상도 블룸 보정",
|
||||
"ui.render_config.fix_custom_frame_rate": "커스텀 FPS 렌더 타이밍 보정",
|
||||
"ui.render_config.disable_tile_culling": "타일 컬링 비활성화",
|
||||
"ui.render_config.hide_failed_decorations": "로딩 실패한 장식 숨기기",
|
||||
"ui.render_config.random_seed": "랜덤 시드 (선택 사항)",
|
||||
"ui.render_config.validation_title": "설정 오류",
|
||||
"ui.render_config.validation_error": "입력값을 확인해 주세요:\n- 너비와 높이는 0보다 큰 정수여야 합니다.\n- 렌더 FPS와 영상 FPS는 0보다 커야 합니다.\n- 종료 후 대기 시간은 0 이상이어야 합니다.",
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ADOFAIRenderer.Core;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Fixes the in-game and render bug where objects (floors, decorations, planets) disappear on the first frame of
|
||||
/// a SetFramerate event (due to camera Z=0 near clip culling) and where parallax/tiles lag behind on subsequent frames.
|
||||
/// <para>
|
||||
/// Defers the manual camera rendering (<c>scrCamera.UpdateCustomFrameRateScreen</c>) to the very end of the frame
|
||||
/// (execution order <c>int.MaxValue - 1</c>), after all components (<c>scrCamera</c>, <c>scrFloor</c>,
|
||||
/// <c>scrDecorationManager</c>, <c>scrPlanet</c>, <c>scrParallax</c>, and <c>scrController</c>) have finished their
|
||||
/// <c>LateUpdate</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public static class CustomFrameRateDeferPatch
|
||||
{
|
||||
private static bool _isExecutingDeferred;
|
||||
private static scrCamera? _pendingCamera;
|
||||
|
||||
private static readonly Action<scrCamera>? UpdateCustomFrameRateScreenInvoker =
|
||||
AccessTools.MethodDelegate<Action<scrCamera>>(AccessTools.Method(typeof(scrCamera), "UpdateCustomFrameRateScreen"));
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the SetFramerate render timing fix is enabled.
|
||||
/// Active if rendering session has the option enabled, or enabled by default during normal in-game play.
|
||||
/// </summary>
|
||||
public static bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (RenderManager.IsActive && RenderManager.Instance?.Configuration?.AdvancedConfig != null)
|
||||
{
|
||||
return RenderManager.Instance.Configuration.AdvancedConfig.FixCustomFrameRate;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intercepts manual camera render calls from SetCustomFrameRate (Update phase) or CheckUpdateFrameRateScreen
|
||||
/// (LateUpdate phase). If not currently executing the deferred render pass, records the camera instance and
|
||||
/// suppresses the premature render.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(scrCamera), "UpdateCustomFrameRateScreen")]
|
||||
private static bool DeferManualRender(scrCamera __instance)
|
||||
{
|
||||
if (!IsEnabled) return true;
|
||||
if (_isExecutingDeferred) return true;
|
||||
|
||||
_pendingCamera = __instance;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the runner component is attached to the camera when it starts.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(scrCamera), "Start")]
|
||||
private static void AttachRunner(scrCamera __instance)
|
||||
{
|
||||
if (!__instance) return;
|
||||
if (!__instance.gameObject.GetComponent<CustomFrameRateDeferredRunner>())
|
||||
{
|
||||
__instance.gameObject.AddComponent<CustomFrameRateDeferredRunner>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked at the very end of LateUpdate (Order int.MaxValue - 1). If a manual render was requested during the frame,
|
||||
/// executes the camera's original UpdateCustomFrameRateScreen once with all objects fully prepared.
|
||||
/// </summary>
|
||||
internal static void ExecuteDeferredRender()
|
||||
{
|
||||
if (_pendingCamera == null) return;
|
||||
|
||||
var cam = _pendingCamera;
|
||||
_pendingCamera = null;
|
||||
|
||||
if (!cam) return;
|
||||
|
||||
_isExecutingDeferred = true;
|
||||
try
|
||||
{
|
||||
UpdateCustomFrameRateScreenInvoker?.Invoke(cam);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isExecutingDeferred = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runner component attached to scrCamera that executes deferred custom frame rate renders at the end of LateUpdate.
|
||||
/// Execution order <c>int.MaxValue - 1</c> guarantees it runs after all normal game components (including
|
||||
/// scrController at 400), but right before PostRenderHook at <c>int.MaxValue</c>.
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(int.MaxValue - 1)]
|
||||
internal class CustomFrameRateDeferredRunner : MonoBehaviour
|
||||
{
|
||||
private void LateUpdate()
|
||||
{
|
||||
CustomFrameRateDeferPatch.ExecuteDeferredRender();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using ADOFAIRenderer.Core;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Patches decoration rendering to hide decorations that failed to load (or are empty) and fell back to the default
|
||||
/// placeholder sprite (tree inside a circle) during a render when <c>AdvancedConfig.HideFailedDecorations</c> is enabled.
|
||||
/// </summary>
|
||||
public static class DecorationPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// True while a render is loading or active and <c>HideFailedDecorations</c> is enabled in the configuration.
|
||||
/// </summary>
|
||||
public static bool IsEnabled =>
|
||||
RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration?.AdvancedConfig?.HideFailedDecorations == true;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given sprite is the default placeholder or not-found sprite of the decoration manager.
|
||||
/// </summary>
|
||||
public static bool IsPlaceholderSprite(Sprite? sprite, scrDecorationManager? manager = null)
|
||||
{
|
||||
if (!sprite) return false;
|
||||
manager ??= scrDecorationManager.instance;
|
||||
if (!manager) return false;
|
||||
|
||||
return sprite == manager.defaultSprite || (manager.notFoundSprite && sprite == manager.notFoundSprite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sweeps all visual decorations in <c>scrDecorationManager.instance.allDecorations</c> and clears any placeholder sprites.
|
||||
/// Called from <see cref="scnGamePatch.ProcessFloors"/> when <c>scnGame.Play</c> runs.
|
||||
/// </summary>
|
||||
public static void ProcessDecorations()
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
var manager = scrDecorationManager.instance;
|
||||
if (!manager || manager.allDecorations == null) return;
|
||||
|
||||
foreach (var dec in manager.allDecorations)
|
||||
{
|
||||
if (dec is scrVisualDecoration visualDec && visualDec.spriteRenderer)
|
||||
{
|
||||
if (IsPlaceholderSprite(visualDec.spriteRenderer.sprite, manager))
|
||||
{
|
||||
visualDec.SetSprite((Sprite)null!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefix of <c>scrVisualDecoration.SetSprite(Sprite)</c>: replaces placeholder default/not-found sprites with null
|
||||
/// when <see cref="IsEnabled"/> is true.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(scrVisualDecoration), nameof(scrVisualDecoration.SetSprite), typeof(Sprite))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static class VisualDecorationSetSpritePatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static void Prefix(scrVisualDecoration __instance, ref Sprite? sprite)
|
||||
{
|
||||
if (!IsEnabled || !sprite) return;
|
||||
|
||||
if (IsPlaceholderSprite(sprite, __instance.manager))
|
||||
{
|
||||
sprite = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefix of <c>scrDecorationManager.ShowEmptyDecorations(bool)</c>: suppresses showing placeholder default sprites
|
||||
/// during render when <see cref="IsEnabled"/> is true.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(scrDecorationManager), nameof(scrDecorationManager.ShowEmptyDecorations))]
|
||||
public static class ShowEmptyDecorationsPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(bool show)
|
||||
{
|
||||
if (show && IsEnabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using ADOFAIRenderer.Core;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Makes the game's bloom compute its blur size as if the frame were 720 pixels high
|
||||
/// ("High-Resolution Bloom Correction" option).
|
||||
/// <para>
|
||||
/// Patched member: <c>VideoBloom.OnRenderImage(RenderTexture source, RenderTexture destination)</c>. The game scales the
|
||||
/// frame down to a bloom buffer 198 pixels high (<c>scale = 198 / source.height</c>) and sets the blur radius in bloom
|
||||
/// buffer pixels to <c>KernelSize * MediumKernelScale * scale</c> (and <c>KernelSize * LargeKernelScale * scale</c>).
|
||||
/// <c>BloomBlit</c> turns the radius into the number of 5-tap blur passes and the blend amount of the last pass.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// While the render is active (<see cref="RenderManager.IsActive"/>) and <c>AdvancedConfig.HighResBloomCorrection</c> is
|
||||
/// enabled, the prefix multiplies <c>KernelSize</c> by <c>source.height / 720</c> for the duration of the call, so the
|
||||
/// radius equals <c>KernelSize * MediumKernelScale * 198 / 720</c> and the blur passes on the bloom buffer are the same
|
||||
/// as in a 720p frame. The finalizer restores the original <c>KernelSize</c>. The bloom buffer size and the downscale
|
||||
/// from the source frame keep the game's behavior.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(VideoBloom))]
|
||||
public class VideoBloomPatch
|
||||
{
|
||||
/// <summary>Frame height in pixels the blur size is computed for.</summary>
|
||||
private const float ReferenceHeight = 720f;
|
||||
|
||||
/// <summary>Prefix of <c>VideoBloom.OnRenderImage</c>.</summary>
|
||||
/// <param name="__instance">The bloom component on the game camera.</param>
|
||||
/// <param name="source">The camera frame; its height selects the multiplier.</param>
|
||||
/// <param name="__state">Original <c>KernelSize</c>, or null when it was not changed.</param>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch("OnRenderImage")]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public static void ScaleKernelSize(VideoBloom __instance, RenderTexture source, out float? __state)
|
||||
// ReSharper restore InconsistentNaming
|
||||
{
|
||||
__state = null;
|
||||
if (!source || !RenderManager.IsActive || !RenderManager.Instance.Configuration.AdvancedConfig.HighResBloomCorrection)
|
||||
return;
|
||||
|
||||
__state = __instance.KernelSize;
|
||||
__instance.KernelSize *= source.height / ReferenceHeight;
|
||||
}
|
||||
|
||||
/// <summary>Finalizer of <c>VideoBloom.OnRenderImage</c>: restores <c>KernelSize</c> when the prefix changed it.</summary>
|
||||
/// <param name="__instance">The bloom component on the game camera.</param>
|
||||
/// <param name="__state">Original <c>KernelSize</c> stored by the prefix, or null.</param>
|
||||
[HarmonyFinalizer]
|
||||
[HarmonyPatch("OnRenderImage")]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public static void RestoreKernelSize(VideoBloom __instance, float? __state)
|
||||
// ReSharper restore InconsistentNaming
|
||||
{
|
||||
if (__state.HasValue) __instance.KernelSize = __state.Value;
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,21 @@ public static class scnGamePatch
|
||||
[HarmonyPatch("Play")]
|
||||
public static void ProcessFloors()
|
||||
{
|
||||
var nonTile = RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration.AdvancedConfig.NonTile;
|
||||
if (RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
|
||||
{
|
||||
foreach (var floor in scrLevelMaker.instance.listFloors)
|
||||
{
|
||||
if (floor) floor.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
DecorationPatch.ProcessDecorations();
|
||||
|
||||
var nonTile = RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration?.AdvancedConfig?.NonTile == true;
|
||||
|
||||
if (!nonTile) return;
|
||||
foreach (var floor in scrLevelMaker.instance.listFloors)
|
||||
|
||||
@@ -33,4 +33,41 @@ public class scrFloorPatch
|
||||
RenderManager.Instance.Configuration.AdvancedConfig.NonTile;
|
||||
return !nonTile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Postfix of <c>scrFloor.Start</c>.
|
||||
/// The game sets <c>enabled = isVisible</c> in Start(), which disables all off-screen tiles right at spawn.
|
||||
/// When <c>DisableTileCulling</c> is enabled, force every floor to remain enabled.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch("Start")]
|
||||
public static void ForceEnableOnStart(scrFloor __instance)
|
||||
{
|
||||
if (RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
|
||||
{
|
||||
__instance.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefix of <c>scrFloor.OnBecameInvisible</c>.
|
||||
/// Skips disabling the floor component (<c>enabled = false</c>) while rendering with
|
||||
/// <c>AdvancedConfig.DisableTileCulling</c> enabled, preventing the 1-frame update lag/glitch
|
||||
/// when tiles enter the camera view.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch("OnBecameInvisible")]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static bool PreventTileCulling(scrFloor __instance)
|
||||
{
|
||||
if (RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ using MelonLoader.Utils;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.1-INDEV", "ADOFAI Editor Forum")]
|
||||
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.3-INDEV", "ADOFAI Editor Forum")]
|
||||
[assembly: MelonGame("7th Beat Games", "A Dance of Fire and Ice")]
|
||||
|
||||
namespace ADOFAIRenderer;
|
||||
|
||||
@@ -135,10 +135,19 @@ internal static class RenderConfigWindow
|
||||
/// </summary>
|
||||
private static O5InputField? _outputDirInput;
|
||||
|
||||
/// <summary>
|
||||
/// File name format template input. Bound to <c>GlobalSettings.Current.FileNameFormat</c>.
|
||||
/// </summary>
|
||||
private static O5InputField? _fileNameFormatInput;
|
||||
|
||||
private static O5Dropdown<string>? _fileExtensionDropdown;
|
||||
private static O5InputField? _randomSeedInput;
|
||||
private static O5Toggle? _processAudioToggle;
|
||||
private static O5Toggle? _nonTileToggle;
|
||||
private static O5Toggle? _highResBloomCorrectionToggle;
|
||||
private static O5Toggle? _fixCustomFrameRateToggle;
|
||||
private static O5Toggle? _disableTileCullingToggle;
|
||||
private static O5Toggle? _hideFailedDecorationsToggle;
|
||||
|
||||
// Planet color overrides: the toggle enables the override, the picker holds the color. A disabled toggle stores
|
||||
// null in AdvancedConfig (no override is applied by PersistencePatch) and blocks the picker.
|
||||
@@ -644,7 +653,7 @@ internal static class RenderConfigWindow
|
||||
{
|
||||
var trimmed = val?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(trimmed) ||
|
||||
string.Equals(trimmed, GlobalSettings.DefaultOutputDirectory, StringComparison.OrdinalIgnoreCase))
|
||||
string.Equals(trimmed, GlobalSettings.DefaultOutputDirectory, StringComparison.Ordinal))
|
||||
{
|
||||
GlobalSettings.Current.OutputDirectory = null;
|
||||
}
|
||||
@@ -694,10 +703,48 @@ internal static class RenderConfigWindow
|
||||
}
|
||||
);
|
||||
|
||||
// Filename format template: typing updates GlobalSettings.Current.FileNameFormat in memory only.
|
||||
_fileNameFormatInput = CreateFullWidthInputField(
|
||||
ctx, globalContent,
|
||||
"ui.render_config.filename_format",
|
||||
GlobalSettings.DefaultFileNameFormat,
|
||||
GlobalSettings.EffectiveFileNameFormat,
|
||||
"input_filename_format",
|
||||
val =>
|
||||
{
|
||||
var trimmed = val?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(trimmed) ||
|
||||
string.Equals(trimmed, GlobalSettings.DefaultFileNameFormat, StringComparison.Ordinal))
|
||||
{
|
||||
GlobalSettings.Current.FileNameFormat = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalSettings.Current.FileNameFormat = trimmed;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var fnHint = CreateLabel(ctx, globalContent, "ui.render_config.filename_format_hint", 11f);
|
||||
fnHint.color = new Color(ctx.Theme.TextDim.r, ctx.Theme.TextDim.g, ctx.Theme.TextDim.b, ctx.Theme.TextDim.a * 0.7f);
|
||||
|
||||
CreateButton(
|
||||
ctx, globalContent,
|
||||
"ui.render_config.reset_filename_default",
|
||||
"btn_reset_filename_format",
|
||||
() =>
|
||||
{
|
||||
_fileNameFormatInput.Set(GlobalSettings.DefaultFileNameFormat);
|
||||
GlobalSettings.Current.FileNameFormat = null;
|
||||
GlobalSettings.Save();
|
||||
}
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Section 6: Advanced Settings card (RenderConfig.AdvancedConfig)
|
||||
// File Extension | Random Seed
|
||||
// Process Audio | Non-Tile Mode
|
||||
// High-Resolution Bloom Correction |
|
||||
// "Planet Colors" label, then three columns: Fire | Ice | Wind (toggle + color picker each)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 7. Advanced Settings (Collapsible Card)
|
||||
@@ -739,6 +786,39 @@ internal static class RenderConfigWindow
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// High-Resolution Bloom Correction (AdvancedConfig.HighResBloomCorrection): the game's bloom computes its blur
|
||||
// size as if the frame were 720 pixels high (VideoBloomPatch)
|
||||
_highResBloomCorrectionToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advLeft),
|
||||
labelKey: "",
|
||||
defaultValue: false,
|
||||
value: config.AdvancedConfig.HighResBloomCorrection,
|
||||
toggleTextKey: "ui.render_config.high_res_bloom_correction",
|
||||
id: "toggle_high_res_bloom_correction",
|
||||
onChanged: val =>
|
||||
{
|
||||
config.AdvancedConfig.HighResBloomCorrection = val;
|
||||
MarkConfigModified();
|
||||
},
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// Disable Tile Culling (AdvancedConfig.DisableTileCulling): prevents tiles from being disabled outside the frustum
|
||||
_disableTileCullingToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advLeft),
|
||||
labelKey: "",
|
||||
defaultValue: false,
|
||||
value: config.AdvancedConfig.DisableTileCulling,
|
||||
toggleTextKey: "ui.render_config.disable_tile_culling",
|
||||
id: "toggle_disable_tile_culling",
|
||||
onChanged: val =>
|
||||
{
|
||||
config.AdvancedConfig.DisableTileCulling = val;
|
||||
MarkConfigModified();
|
||||
},
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// Random Seed (AdvancedConfig.RandomSeed): integer passed to UnityEngine.Random.InitState before the game scene
|
||||
// loads; empty text stores null (no seeding). Text that is neither empty nor an integer keeps the previous value.
|
||||
_randomSeedInput = CreateInputField(
|
||||
@@ -772,6 +852,38 @@ internal static class RenderConfigWindow
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// Fix SetFramerate Render Timing (AdvancedConfig.FixCustomFrameRate): defers manual camera rendering to frame end
|
||||
_fixCustomFrameRateToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advRight),
|
||||
labelKey: "",
|
||||
defaultValue: true,
|
||||
value: config.AdvancedConfig.FixCustomFrameRate,
|
||||
toggleTextKey: "ui.render_config.fix_custom_frame_rate",
|
||||
id: "toggle_fix_custom_frame_rate",
|
||||
onChanged: val =>
|
||||
{
|
||||
config.AdvancedConfig.FixCustomFrameRate = val;
|
||||
MarkConfigModified();
|
||||
},
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// Hide Failed Decorations (AdvancedConfig.HideFailedDecorations): hides placeholder tree decorations when decoration images fail to load
|
||||
_hideFailedDecorationsToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advRight),
|
||||
labelKey: "",
|
||||
defaultValue: false,
|
||||
value: config.AdvancedConfig.HideFailedDecorations,
|
||||
toggleTextKey: "ui.render_config.hide_failed_decorations",
|
||||
id: "toggle_hide_failed_decorations",
|
||||
onChanged: val =>
|
||||
{
|
||||
config.AdvancedConfig.HideFailedDecorations = val;
|
||||
MarkConfigModified();
|
||||
},
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// 7-1. Planet Color Settings (Optional).
|
||||
// For each planet: the toggle turns the override on/off (off stores null and blocks/collapses the picker);
|
||||
// the picker writes its color into the config only while the toggle is on.
|
||||
@@ -975,11 +1087,16 @@ internal static class RenderConfigWindow
|
||||
_audioBitrateSlider?.Set(config.AudioConfig.AudioBitrate / 1000.0, false, noFilter: true);
|
||||
|
||||
_outputDirInput?.Set(GlobalSettings.EffectiveOutputDirectory, false);
|
||||
_fileNameFormatInput?.Set(GlobalSettings.EffectiveFileNameFormat, false);
|
||||
|
||||
_fileExtensionDropdown?.Set(config.AdvancedConfig.FileExtension, false);
|
||||
_randomSeedInput?.Set(config.AdvancedConfig.RandomSeed?.ToString() ?? "", false);
|
||||
_processAudioToggle?.Set(config.AdvancedConfig.ProcessAudio, false);
|
||||
_nonTileToggle?.Set(config.AdvancedConfig.NonTile, false);
|
||||
_highResBloomCorrectionToggle?.Set(config.AdvancedConfig.HighResBloomCorrection, false);
|
||||
_fixCustomFrameRateToggle?.Set(config.AdvancedConfig.FixCustomFrameRate, false);
|
||||
_disableTileCullingToggle?.Set(config.AdvancedConfig.DisableTileCulling, false);
|
||||
_hideFailedDecorationsToggle?.Set(config.AdvancedConfig.HideFailedDecorations, false);
|
||||
|
||||
// Planet colors: toggle on when an override is stored; the picker shows the stored color or the default and is
|
||||
// blocked without an override
|
||||
@@ -1074,7 +1191,7 @@ internal static class RenderConfigWindow
|
||||
{
|
||||
var path = _outputDirInput.Value.Trim();
|
||||
if (string.IsNullOrWhiteSpace(path) ||
|
||||
string.Equals(path, GlobalSettings.DefaultOutputDirectory, StringComparison.OrdinalIgnoreCase))
|
||||
string.Equals(path, GlobalSettings.DefaultOutputDirectory, StringComparison.Ordinal))
|
||||
{
|
||||
GlobalSettings.Current.OutputDirectory = null;
|
||||
}
|
||||
@@ -1097,6 +1214,20 @@ internal static class RenderConfigWindow
|
||||
}
|
||||
}
|
||||
|
||||
if (_fileNameFormatInput != null)
|
||||
{
|
||||
var format = _fileNameFormatInput.Value.Trim();
|
||||
if (string.IsNullOrWhiteSpace(format) ||
|
||||
string.Equals(format, GlobalSettings.DefaultFileNameFormat, StringComparison.Ordinal))
|
||||
{
|
||||
GlobalSettings.Current.FileNameFormat = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalSettings.Current.FileNameFormat = format;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalSettings.Save();
|
||||
SetWindowActive(false);
|
||||
|
||||
@@ -1161,6 +1292,10 @@ internal static class RenderConfigWindow
|
||||
}
|
||||
if (_processAudioToggle != null) target.AdvancedConfig.ProcessAudio = _processAudioToggle.Value;
|
||||
if (_nonTileToggle != null) target.AdvancedConfig.NonTile = _nonTileToggle.Value;
|
||||
if (_highResBloomCorrectionToggle != null) target.AdvancedConfig.HighResBloomCorrection = _highResBloomCorrectionToggle.Value;
|
||||
if (_fixCustomFrameRateToggle != null) target.AdvancedConfig.FixCustomFrameRate = _fixCustomFrameRateToggle.Value;
|
||||
if (_disableTileCullingToggle != null) target.AdvancedConfig.DisableTileCulling = _disableTileCullingToggle.Value;
|
||||
if (_hideFailedDecorationsToggle != null) target.AdvancedConfig.HideFailedDecorations = _hideFailedDecorationsToggle.Value;
|
||||
|
||||
// Planet Colors
|
||||
target.AdvancedConfig.firePlanetColor = (_firePlanetToggle?.Value == true && _firePlanetPicker != null)
|
||||
|
||||
@@ -1080,6 +1080,14 @@ namespace ADOFAIRenderer.Util.FFmpeg
|
||||
{
|
||||
TrySetOption("x265-params", "hrd=1:strict-cbr=1");
|
||||
}
|
||||
// NVENC: without "rc", nvenc_setup_rate_control selects CONSTQP when "qp" is set and VBR otherwise;
|
||||
// bit_rate and rc_max_rate being equal does not select CBR. "rc=cbr" selects NV_ENC_PARAMS_RC_CBR.
|
||||
// Reference: https://github.com/FFmpeg/FFmpeg/blob/release/8.0/libavcodec/nvenc.c (nvenc_setup_rate_control),
|
||||
// https://github.com/FFmpeg/FFmpeg/blob/release/8.0/libavcodec/nvenc_h264.c ("rc" option, "cbr" constant)
|
||||
else if (encoder.Kind == EncoderKind.NVENC)
|
||||
{
|
||||
TrySetOption("rc", "cbr");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace ADOFAIRenderer.Util.OS;
|
||||
/// </para>
|
||||
/// <para>- <b>macOS</b>: <c>osascript</c> running AppleScript <c>choose folder</c>.</para>
|
||||
/// <para>
|
||||
/// - <b>Linux</b>: <c>zenity --file-selection --directory</c>; when zenity does not return an existing directory (not installed,
|
||||
/// cancelled or failed), <c>kdialog --getexistingdirectory</c>.
|
||||
/// - <b>Linux</b>: <c>zenity --file-selection --directory</c>; when zenity is not installed or fails (exit code other than 0
|
||||
/// or 1), <c>kdialog --getexistingdirectory</c>. A cancelled zenity dialog (exit code 1) ends the selection.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The dialog runs off the main Unity thread so the game keeps rendering frames while it is open. Only one dialog can be open
|
||||
@@ -688,13 +688,13 @@ internal static class FolderDialogUtil
|
||||
|
||||
/// <summary>
|
||||
/// Runs <c>zenity --file-selection --directory --title=... [--filename=initialDirectory]</c> and blocks until it exits.
|
||||
/// When zenity cannot be started, exits with a non-zero code (cancel or error) or prints a path that is not an existing
|
||||
/// directory, runs <c>kdialog --getexistingdirectory [initialDirectory] --title ...</c> instead. Both commands print the
|
||||
/// Exit code 0 returns the printed path when it is an existing directory, and exit code 1 (cancelled or closed) returns null
|
||||
/// without opening a second dialog. When zenity cannot be started or exits with any other code, runs <c>kdialog --getexistingdirectory [initialDirectory] --title ...</c> instead. Both commands print the
|
||||
/// selected path to standard output.
|
||||
/// </summary>
|
||||
/// <param name="initialDirectory">Folder shown first; used only when it is an existing directory.</param>
|
||||
/// <returns>
|
||||
/// The selected existing directory; null when both dialogs return nothing, when kdialog cannot be started, or on an
|
||||
/// The selected existing directory; null when the dialog is cancelled, when kdialog cannot be started, or on an
|
||||
/// exception (logged as a warning).
|
||||
/// </returns>
|
||||
private static string? OpenLinuxFolderBrowser(string initialDirectory)
|
||||
@@ -725,15 +725,19 @@ internal static class FolderDialogUtil
|
||||
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode == 0 && !string.IsNullOrEmpty(output) && Directory.Exists(output))
|
||||
if (process.ExitCode == 0)
|
||||
{
|
||||
return output;
|
||||
return !string.IsNullOrEmpty(output) && Directory.Exists(output) ? output : null;
|
||||
}
|
||||
|
||||
// zenity exit code 1: the dialog was cancelled or closed.
|
||||
// Reference: https://gitlab.gnome.org/GNOME/zenity/-/raw/master/src/util.c (ZENITY_OK_DEFAULT 0, ZENITY_CANCEL_DEFAULT 1, ZENITY_ESC_DEFAULT 1, ZENITY_ERROR_DEFAULT -1).
|
||||
if (process.ExitCode == 1) return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to kdialog if zenity fails to start
|
||||
// Falls back to kdialog when zenity is not installed or cannot be started.
|
||||
}
|
||||
|
||||
var kdialogInfo = new ProcessStartInfo
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using ADOFAIRenderer.Core.Data;
|
||||
using ADOFAIRenderer.Data;
|
||||
|
||||
namespace ADOFAIRenderer.Util;
|
||||
|
||||
/// <summary>
|
||||
/// Formats and sanitizes render output file names according to customizable template patterns.
|
||||
/// </summary>
|
||||
internal static class RenderFileNameUtil
|
||||
{
|
||||
private static readonly Regex RichTextRegex = new(@"<[^>]+>", RegexOptions.Compiled);
|
||||
private static readonly Regex TokenRegex = new(@"\{([a-zA-Z0-9_]+)\}", RegexOptions.Compiled);
|
||||
|
||||
private static readonly HashSet<string> ReservedWindowsNames = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"CON", "PRN", "AUX", "NUL",
|
||||
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
||||
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Removes Unity rich text tags (such as <color=...>, <b>, etc.) from the given text.
|
||||
/// </summary>
|
||||
public static string StripRichText(string? input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return string.Empty;
|
||||
return RichTextRegex.Replace(input, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces invalid file name characters within a single token with an underscore.
|
||||
/// </summary>
|
||||
public static string SanitizeToken(string? token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) return string.Empty;
|
||||
|
||||
var invalidChars = Path.GetInvalidFileNameChars();
|
||||
var sb = new StringBuilder(token.Length);
|
||||
foreach (var c in token)
|
||||
{
|
||||
sb.Append(invalidChars.Contains(c) ? '_' : c);
|
||||
}
|
||||
|
||||
return sb.ToString().Trim(' ', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sanitizes the final formatted file name, ensuring no illegal characters or Windows reserved device names.
|
||||
/// </summary>
|
||||
public static string SanitizeFileName(string? fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName)) return string.Empty;
|
||||
|
||||
var invalidChars = Path.GetInvalidFileNameChars();
|
||||
var sb = new StringBuilder(fileName.Length);
|
||||
foreach (var c in fileName)
|
||||
{
|
||||
sb.Append(invalidChars.Contains(c) ? '_' : c);
|
||||
}
|
||||
|
||||
var result = sb.ToString().Trim(' ', '.');
|
||||
if (ReservedWindowsNames.Contains(result))
|
||||
{
|
||||
result = "_" + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a file name without extension by substituting template variables.
|
||||
/// Available tokens: {song}, {title}, {artist}, {author}, {level}, {preset},
|
||||
/// {date}, {time}, {year}, {month}, {day}, {hour}, {minute}, {second},
|
||||
/// {resolution}, {width}, {height}, {fps}.
|
||||
/// </summary>
|
||||
public static string FormatFileName(
|
||||
string? formatTemplate,
|
||||
DateTime startTime,
|
||||
RenderConfig config,
|
||||
string? presetName = null,
|
||||
string? levelPath = null)
|
||||
{
|
||||
var scn = scnGame.instance;
|
||||
string rawSong = "";
|
||||
string rawArtist = "";
|
||||
string rawAuthor = "";
|
||||
|
||||
if (scn != null && scn.levelData != null)
|
||||
{
|
||||
rawSong = scn.levelData.song ?? "";
|
||||
rawArtist = scn.levelData.artist ?? "";
|
||||
rawAuthor = scn.levelData.author ?? "";
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rawSong) && !string.IsNullOrWhiteSpace(levelPath))
|
||||
{
|
||||
var dir = Path.GetDirectoryName(levelPath);
|
||||
rawSong = !string.IsNullOrWhiteSpace(dir)
|
||||
? Path.GetFileName(dir)
|
||||
: Path.GetFileNameWithoutExtension(levelPath);
|
||||
}
|
||||
|
||||
var song = SanitizeToken(StripRichText(rawSong));
|
||||
var artist = SanitizeToken(StripRichText(rawArtist));
|
||||
var author = SanitizeToken(StripRichText(rawAuthor));
|
||||
var level = !string.IsNullOrWhiteSpace(levelPath)
|
||||
? SanitizeToken(Path.GetFileNameWithoutExtension(levelPath))
|
||||
: song;
|
||||
var preset = SanitizeToken(presetName ?? "");
|
||||
|
||||
var date = startTime.ToString("yyyy-MM-dd");
|
||||
var time = startTime.ToString("HH-mm-ss");
|
||||
var year = startTime.ToString("yyyy");
|
||||
var month = startTime.ToString("MM");
|
||||
var day = startTime.ToString("dd");
|
||||
var hour = startTime.ToString("HH");
|
||||
var minute = startTime.ToString("mm");
|
||||
var second = startTime.ToString("ss");
|
||||
|
||||
var width = config.RenderWidth.ToString();
|
||||
var height = config.RenderHeight.ToString();
|
||||
var resolution = $"{config.RenderWidth}x{config.RenderHeight}";
|
||||
|
||||
var effectiveFps = Math.Min(config.VideoFPS, config.RenderFPS);
|
||||
var fps = Math.Abs(effectiveFps % 1) < 0.001
|
||||
? ((int)effectiveFps).ToString()
|
||||
: effectiveFps.ToString("0.##");
|
||||
|
||||
var tokens = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "song", song },
|
||||
{ "title", song },
|
||||
{ "artist", artist },
|
||||
{ "author", author },
|
||||
{ "level", level },
|
||||
{ "preset", preset },
|
||||
{ "date", date },
|
||||
{ "time", time },
|
||||
{ "year", year },
|
||||
{ "month", month },
|
||||
{ "day", day },
|
||||
{ "hour", hour },
|
||||
{ "minute", minute },
|
||||
{ "second", second },
|
||||
{ "width", width },
|
||||
{ "height", height },
|
||||
{ "resolution", resolution },
|
||||
{ "fps", fps }
|
||||
};
|
||||
|
||||
var template = string.IsNullOrWhiteSpace(formatTemplate)
|
||||
? GlobalSettings.DefaultFileNameFormat
|
||||
: formatTemplate;
|
||||
|
||||
var replaced = TokenRegex.Replace(template, match =>
|
||||
{
|
||||
var key = match.Groups[1].Value;
|
||||
return tokens.TryGetValue(key, out var val) ? val : match.Value;
|
||||
});
|
||||
|
||||
var sanitized = SanitizeFileName(replaced);
|
||||
return string.IsNullOrWhiteSpace(sanitized)
|
||||
? startTime.ToString("yyyy-MM-dd HH-mm-ss")
|
||||
: sanitized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collision-free output file path by appending (1), (2), etc. if a file with the given name already exists.
|
||||
/// </summary>
|
||||
public static string GetUniqueFilePath(string directory, string fileNameWithoutExt, string ext)
|
||||
{
|
||||
var normalizedExt = "." + ext.TrimStart('.').ToLowerInvariant();
|
||||
var fileName = $"{fileNameWithoutExt}{normalizedExt}";
|
||||
var fullPath = Path.Combine(directory, fileName);
|
||||
|
||||
var counter = 1;
|
||||
while (File.Exists(fullPath))
|
||||
{
|
||||
fileName = $"{fileNameWithoutExt} ({counter}){normalizedExt}";
|
||||
fullPath = Path.Combine(directory, fileName);
|
||||
counter++;
|
||||
}
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user