Screenie/Configuration.cs

98 lines
3.3 KiB
C#
Raw Normal View History

2024-02-18 00:32:45 +00:00
using System.Drawing.Imaging;
using Dalamud.Configuration;
2024-02-18 21:31:26 +00:00
using Dalamud.Game.ClientState.GamePad;
2024-02-19 01:40:04 +00:00
using FFXIVClientStructs.FFXIV.Client.UI;
2024-02-18 04:40:58 +00:00
using Scriban;
using Scriban.Parsing;
2024-02-18 00:32:45 +00:00
namespace Screenie;
[Serializable]
public class Configuration : IPluginConfiguration {
public int Version { get; set; } = 1;
public string SaveDirectory = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Screenie");
public Format SaveFormat = Format.Png;
public int SaveFormatData = 90;
2024-02-18 06:28:04 +00:00
2024-02-18 05:26:53 +00:00
public string SaveFileNameFormat = """
2024-02-18 06:28:04 +00:00
{{ captured_at_local | date.to_string '%Y/%m %b/[%H.%M.%S]' }}
2024-02-18 21:06:33 +00:00
{{ if active_character -}}
{{ active_character.name }} - {{ location }}
{{- else -}}
Main Menu or Loading Screen
{{- end -}}
2024-02-18 21:31:26 +00:00
2024-02-18 06:28:04 +00:00
{{- if area }} ({{ area }}) {{- end -}}
{{- if ward }} W{{ ward }} {{- end -}}
{{- if plot -}} P{{ plot }} {{- end -}}
2024-02-18 05:26:53 +00:00
""";
2024-02-18 04:40:58 +00:00
2024-02-18 21:40:21 +00:00
public GamepadButtons GamepadKeybind = GamepadButtons.L1 | GamepadButtons.Start;
2024-02-19 01:49:53 +00:00
public List<SeVirtualKey> KeyboardKeybind = [];
public bool DisableNativeScreenshots = true;
2024-02-18 21:31:26 +00:00
2024-02-18 04:40:58 +00:00
private int _templateHashCode;
private Template? _template;
internal Template SaveFileNameTemplate {
get {
var currentHash = this.SaveFileNameFormat.GetHashCode();
if (currentHash == this._templateHashCode && this._template != null) {
return this._template;
}
this._templateHashCode = currentHash;
this._template = Template.Parse(
this.SaveFileNameFormat,
parserOptions: new ParserOptions {
LiquidFunctionsToScriban = true,
}
);
return this._template;
}
}
2024-02-18 00:32:45 +00:00
}
public enum Format {
Png,
2024-02-18 02:36:57 +00:00
WebpLossless,
WebpLossy,
2024-02-18 00:32:45 +00:00
Jpg,
2024-02-18 16:00:46 +00:00
// AvifLossless,
// AvifLossy,
// HeicLossless,
// HeicLossy,
2024-02-18 00:32:45 +00:00
}
public static class FormatExt {
2024-02-18 16:00:46 +00:00
public static string Name(this Format format) {
return format switch {
Format.Png => "PNG",
Format.WebpLossless => "WEBP (lossless)",
Format.WebpLossy => "WEBP (lossy)",
Format.Jpg => "JPG",
// Format.AvifLossless => "AVIF (lossless)",
// Format.AvifLossy => "AVIF (lossy)",
// Format.HeicLossless => "HEIC (lossless)",
// Format.HeicLossy => "HEIC (lossy)",
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
}
2024-02-18 02:36:57 +00:00
public static ImageFormat? ToImageFormat(this Format format) {
2024-02-18 00:32:45 +00:00
return format switch {
Format.Png => ImageFormat.Png,
2024-02-18 02:36:57 +00:00
Format.WebpLossless => null,
Format.WebpLossy => null,
2024-02-18 00:32:45 +00:00
Format.Jpg => ImageFormat.Jpeg,
2024-02-18 16:00:46 +00:00
// Format.AvifLossless => null,
// Format.AvifLossy => null,
// Format.HeicLossless => null,
// Format.HeicLossy => null,
2024-02-18 00:32:45 +00:00
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
}
}