Add Preset Feature to Render Settings

This commit is contained in:
copecone committed 2026-07-03 12:25:54 +09:00
1 parent 4fbace630c
commit 59d16a7e90
5 files changed
+674 -71

No files matched your search

+14
View File
@@ -68,5 +68,19 @@ namespace ADOFAIRenderer.Data
callback(Value);
}
}
/// <summary>
/// Sets the selected enum value and updates the dropdown index.
/// </summary>
/// <param name="value">The enum value to set.</param>
public void SetValue(T value)
{
if (_dropdown == null) return;
int idx = _values.IndexOf(value);
if (idx >= 0)
{
_dropdown.index = idx;
}
}
}
}
+103
View File
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MelonLoader;
using MelonLoader.Utils;
using Newtonsoft.Json;
namespace ADOFAIRenderer.Data
{
public class RenderPreset
{
public string Name { get; set; } = string.Empty;
public RenderConfig Config { get; set; } = null!;
}
public static class PresetManager
{
private static string GetPresetsDirectory()
{
return Path.Combine(MelonEnvironment.GameRootDirectory, "UserData", "ADOFAIRenderer", "Presets");
}
private static string GetSafeFileName(string name)
{
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, '_'));
}
public static void SavePreset(string name, RenderConfig config)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("프리셋 이름은 비어 있을 수 없습니다.");
}
string dir = GetPresetsDirectory();
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
var preset = new RenderPreset
{
Name = name,
Config = config
};
string json = JsonConvert.SerializeObject(preset, Formatting.Indented);
string safeName = GetSafeFileName(name);
string filePath = Path.Combine(dir, safeName + ".json");
File.WriteAllText(filePath, json);
}
public static List<RenderPreset> GetPresets()
{
var presets = new List<RenderPreset>();
string dir = GetPresetsDirectory();
if (!Directory.Exists(dir))
{
return presets;
}
try
{
string[] files = Directory.GetFiles(dir, "*.json");
foreach (string file in files)
{
try
{
string json = File.ReadAllText(file);
var preset = JsonConvert.DeserializeObject<RenderPreset>(json);
if (preset != null && !string.IsNullOrEmpty(preset.Name) && preset.Config != null)
{
presets.Add(preset);
}
}
catch (Exception ex)
{
MelonLogger.Warning($"프리셋 파일 '{Path.GetFileName(file)}' 로드 중 오류 발생: {ex.Message}");
}
}
}
catch (Exception ex)
{
MelonLogger.Error($"프리셋 목록을 불러오는 중 오류 발생: {ex.Message}");
}
return presets;
}
public static void DeletePreset(string name)
{
string dir = GetPresetsDirectory();
string safeName = GetSafeFileName(name);
string filePath = Path.Combine(dir, safeName + ".json");
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
}
}
+16 -16
View File
@@ -4,31 +4,31 @@ namespace ADOFAIRenderer.Data
{
public class RenderConfig
{
public double RenderFPS;
public double VideoFPS;
public double RenderFPS { get; set; }
public double VideoFPS { get; set; }
public int RenderWidth;
public int RenderHeight;
public int RenderWidth { get; set; }
public int RenderHeight { get; set; }
public Codec Codec;
public EncodingConfig? EncodingConfig;
public Codec Codec { get; set; }
public EncodingConfig? EncodingConfig { get; set; }
public double DelayAfterLevelEnd;
public bool ShowJudgementText;
public double DelayAfterLevelEnd { get; set; }
public bool ShowJudgementText { get; set; }
public int? RandomSeed = null;
public bool ProcessAudio;
public int? RandomSeed { get; set; } = null;
public bool ProcessAudio { get; set; }
}
public class EncodingConfig
{
public RateControlMode RateControlMode;
public RateControlMode RateControlMode { get; set; }
public int Bitrate;
public int MaxBitrate;
public int Bitrate { get; set; }
public int MaxBitrate { get; set; }
// ReSharper disable once InconsistentNaming
public int QP;
public double KeyframeInterval;
public bool ForceSoftwareEncoder;
public int QP { get; set; }
public double KeyframeInterval { get; set; }
public bool ForceSoftwareEncoder { get; set; }
}
}