SHA256
Document Render Core And API
This commit is contained in:
1 parent
354c42fdd9
commit
8deb64fd4d
22 files changed
+1241
-27
No files matched your search
@@ -6,29 +6,59 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace ADOFAIRenderer.Core.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Mod-wide settings that are not part of a render preset, stored as JSON in
|
||||
/// <game root>/UserData/ADOFAIRenderer/global_settings.json (see <see cref="GlobalSettings"/>).
|
||||
/// </summary>
|
||||
internal class GlobalConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Output directory chosen in the render configuration window; null or empty selects
|
||||
/// GlobalSettings.DefaultOutputDirectory. Ignored while the directory does not exist (see EffectiveOutputDirectory).
|
||||
/// </summary>
|
||||
public string? OutputDirectory { 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>
|
||||
/// True once PresetManager.EnsureDefaultPresetsCreated has written the built-in preset files. Built-in presets the user
|
||||
/// deleted afterwards are not written again.
|
||||
/// </summary>
|
||||
public bool DefaultPresetsInitialized { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and saves <see cref="GlobalConfig"/>. The file is read once by the static constructor and again by
|
||||
/// RenderMod.OnInitializeMelon (Load), and written by Save. Read and write errors are logged as warnings and never
|
||||
/// thrown; a file that cannot be read yields the default settings. Main thread.
|
||||
/// </summary>
|
||||
internal static class GlobalSettings
|
||||
{
|
||||
/// <summary>MelonLoader's game root directory, or the application base directory when it is empty.</summary>
|
||||
private static string GetGameRootDir()
|
||||
{
|
||||
var root = MelonEnvironment.GameRootDirectory;
|
||||
return string.IsNullOrEmpty(root) ? AppDomain.CurrentDomain.BaseDirectory : root;
|
||||
}
|
||||
|
||||
/// <summary><game root>/UserData/ADOFAIRenderer/global_settings.json.</summary>
|
||||
private static string SettingsFilePath =>
|
||||
Path.Combine(GetGameRootDir(), "UserData", "ADOFAIRenderer", "global_settings.json");
|
||||
|
||||
/// <summary>
|
||||
/// Settings in memory. Changes are kept in memory until <see cref="Save"/> is called; <see cref="Load"/> replaces the
|
||||
/// object.
|
||||
/// </summary>
|
||||
public static GlobalConfig Current { get; private set; } = new();
|
||||
|
||||
/// <summary>Output directory used when none is configured: <game root>/Render.</summary>
|
||||
public static string DefaultOutputDirectory =>
|
||||
Path.Combine(GetGameRootDir(), "Render");
|
||||
|
||||
/// <summary>
|
||||
/// Directory where renders without an explicit output path are written: Current.OutputDirectory when it is set and
|
||||
/// exists, otherwise <see cref="DefaultOutputDirectory"/>. The default directory is not created here
|
||||
/// (RenderManager.SetupCaptureDirectory creates it).
|
||||
/// </summary>
|
||||
public static string EffectiveOutputDirectory
|
||||
{
|
||||
get
|
||||
@@ -47,6 +77,10 @@ internal static class GlobalSettings
|
||||
Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces <see cref="Current"/> with the content of the settings file. A missing, empty or unreadable file gives the
|
||||
/// default settings (an unreadable file is logged as a warning).
|
||||
/// </summary>
|
||||
public static void Load()
|
||||
{
|
||||
try
|
||||
@@ -66,6 +100,10 @@ internal static class GlobalSettings
|
||||
Current = new GlobalConfig();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes <see cref="Current"/> as indented JSON to the settings file, creating the directory when needed.
|
||||
/// Errors are logged as warnings.
|
||||
/// </summary>
|
||||
public static void Save()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user