feat: add handlebars template
This commit is contained in:
parent
da75b7966e
commit
5ea43ba1e2
15
Command.cs
15
Command.cs
|
@ -2,6 +2,7 @@ using System.Drawing;
|
|||
using System.Drawing.Imaging;
|
||||
using Blake3;
|
||||
using Dalamud.Game.Command;
|
||||
using HandlebarsDotNet;
|
||||
using Newtonsoft.Json;
|
||||
using WebP.Net;
|
||||
|
||||
|
@ -60,7 +61,7 @@ internal class Command : IDisposable {
|
|||
}
|
||||
|
||||
string hash;
|
||||
using (var stream = new Blake3Stream(this.OpenFile(ext))) {
|
||||
using (var stream = new Blake3Stream(this.OpenFile(ext, meta))) {
|
||||
stream.Write(imageData);
|
||||
hash = Convert.ToHexString(stream.ComputeHash().AsSpan());
|
||||
}
|
||||
|
@ -96,13 +97,15 @@ internal class Command : IDisposable {
|
|||
return (stream.ToArray(), ext);
|
||||
}
|
||||
|
||||
private FileStream OpenFile(string ext) {
|
||||
private FileStream OpenFile(string ext, ScreenshotMetadata meta) {
|
||||
Directory.CreateDirectory(this.Plugin.Config.SaveDirectory);
|
||||
|
||||
var path = Path.ChangeExtension(
|
||||
Path.Join(this.Plugin.Config.SaveDirectory, "screenie"),
|
||||
ext
|
||||
);
|
||||
var template = Handlebars.Compile(this.Plugin.Config.SaveFileNameFormat);
|
||||
var fileName = template(meta);
|
||||
|
||||
var path = Path.Join(this.Plugin.Config.SaveDirectory, fileName);
|
||||
path += $".{ext}";
|
||||
|
||||
return new FileStream(path, FileMode.Create, FileAccess.Write);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ public class Configuration : IPluginConfiguration {
|
|||
public string SaveDirectory = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Screenie");
|
||||
public Format SaveFormat = Format.Png;
|
||||
public int SaveFormatData = 90;
|
||||
public string SaveFileNameFormat = "{{ CapturedAtLocal.Year }}/{{ CapturedAtLocal.Month }}/{{ ActiveCharacter.Name }} - {{ Location }}";
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
|
|
|
@ -6,7 +6,7 @@ using Screenie.Ui;
|
|||
namespace Screenie;
|
||||
|
||||
public class Plugin : IDalamudPlugin {
|
||||
internal static string Name = "Heliosphere";
|
||||
internal const string Name = "Screenie";
|
||||
|
||||
[PluginService]
|
||||
internal static IPluginLog Log { get; private set; }
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Blake3" Version="1.0.0" />
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
|
||||
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.ImGuiFileDialog;
|
||||
using Dalamud.Interface.Utility;
|
||||
using HandlebarsDotNet;
|
||||
using ImGuiNET;
|
||||
using Screenie.Util;
|
||||
|
||||
|
@ -11,12 +13,17 @@ namespace Screenie.Ui;
|
|||
internal class PluginUi : IDisposable {
|
||||
private Plugin Plugin { get; }
|
||||
private FileDialogManager FileDialogManager { get; }
|
||||
private ScreenshotMetadata Metadata { get; set; }
|
||||
private HandlebarsTemplate<object, object>? Template { get; set; }
|
||||
|
||||
internal bool Visible;
|
||||
|
||||
private Stopwatch _metaUpdate = Stopwatch.StartNew();
|
||||
|
||||
internal PluginUi(Plugin plugin) {
|
||||
this.Plugin = plugin;
|
||||
this.FileDialogManager = new FileDialogManager();
|
||||
this.Metadata = ScreenshotMetadata.Capture(this.Plugin);
|
||||
|
||||
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
|
||||
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OpenConfigUi;
|
||||
|
@ -42,6 +49,12 @@ internal class PluginUi : IDisposable {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this._metaUpdate.Elapsed >= TimeSpan.FromSeconds(5)) {
|
||||
this.Metadata = ScreenshotMetadata.Capture(this.Plugin);
|
||||
|
||||
this._metaUpdate.Restart();
|
||||
}
|
||||
|
||||
using var end = new OnDispose(ImGui.End);
|
||||
|
||||
ImGui.SetNextWindowSize(new Vector2(350, 500), ImGuiCond.FirstUseEver);
|
||||
|
@ -78,6 +91,18 @@ internal class PluginUi : IDisposable {
|
|||
anyChanged |= ImGui.SliderInt("##format-data", ref this.Plugin.Config.SaveFormatData, 0, 100);
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted("Filename format");
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
var templateChanged = ImGui.InputText("##filename-format", ref this.Plugin.Config.SaveFileNameFormat, 1024);
|
||||
anyChanged |= templateChanged;
|
||||
if (this.Template == null || templateChanged) {
|
||||
this.Template = Handlebars.Compile(this.Plugin.Config.SaveFileNameFormat);
|
||||
}
|
||||
|
||||
if (this.Template != null) {
|
||||
ImGui.TextUnformatted(this.Template(this.Metadata));
|
||||
}
|
||||
|
||||
if (anyChanged) {
|
||||
this.Plugin.SaveConfig();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,15 @@
|
|||
"resolved": "2.1.12",
|
||||
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
|
||||
},
|
||||
"Handlebars.Net": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.1.4, )",
|
||||
"resolved": "2.1.4",
|
||||
"contentHash": "Od7MWDfGxYKRtxETFMlcvCrY8hAqyuXZDX4EsOfiI/jzh+PVBuVxazHBC1HmVqTKX1JnRtoxIMcH95K9UFlYog==",
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.7.0"
|
||||
}
|
||||
},
|
||||
"Microsoft.Windows.CsWin32": {
|
||||
"type": "Direct",
|
||||
"requested": "[0.3.49-beta, )",
|
||||
|
@ -45,6 +54,11 @@
|
|||
"System.Drawing.Common": "7.0.0"
|
||||
}
|
||||
},
|
||||
"Microsoft.CSharp": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.7.0",
|
||||
"contentHash": "pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA=="
|
||||
},
|
||||
"Microsoft.Win32.SystemEvents": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.0.0",
|
||||
|
|
Loading…
Reference in New Issue