feat: start on penumbra integration

This commit is contained in:
Anna 2024-02-18 11:00:46 -05:00
parent 1e50cfe32d
commit f2f2e09e62
Signed by: anna
GPG Key ID: D0943384CD9F87D1
9 changed files with 83 additions and 25 deletions

View File

@ -43,6 +43,18 @@ internal class Command : IDisposable {
return;
}
if (this.Plugin.Penumbra.GetPlayerResourcePaths() is { } paths) {
foreach (var (objId, data) in paths) {
Plugin.Log.Info($"{objId}");
foreach (var (key, value) in data) {
Plugin.Log.Info($" {key}");
foreach (var str in value) {
Plugin.Log.Info($" {str}");
}
}
}
}
Task.Factory.StartNew(async () => {
using var bitmap = bitmapOuter;

View File

@ -52,15 +52,37 @@ public enum Format {
WebpLossless,
WebpLossy,
Jpg,
// AvifLossless,
// AvifLossy,
// HeicLossless,
// HeicLossy,
}
public static class FormatExt {
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),
};
}
public static ImageFormat? ToImageFormat(this Format format) {
return format switch {
Format.Png => ImageFormat.Png,
Format.WebpLossless => null,
Format.WebpLossy => null,
Format.Jpg => ImageFormat.Jpeg,
// Format.AvifLossless => null,
// Format.AvifLossy => null,
// Format.HeicLossless => null,
// Format.HeicLossy => null,
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
}

View File

@ -18,15 +18,6 @@ internal class Database : IDisposable {
this.RunMigrations();
}
internal Database(string dir) {
Directory.CreateDirectory(dir);
var dbPath = Path.Join(dir, "database.sqlite");
this.Connection = new SQLiteConnection($"Data Source={dbPath}");
this.Connection.Open();
this.RunMigrations();
}
public void Dispose() {
this.Connection.Close();
this.Connection.Dispose();

21
PenumbraIpc.cs Normal file
View File

@ -0,0 +1,21 @@
using Penumbra.Api.Helpers;
using Screenie;
internal class PenumbraIpc {
private Plugin Plugin { get; }
private FuncSubscriber<IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>> GetPlayerResourcePathsSubscriber { get; }
internal PenumbraIpc(Plugin plugin) {
this.Plugin = plugin;
this.GetPlayerResourcePathsSubscriber = Penumbra.Api.Ipc.GetPlayerResourcePaths.Subscriber(this.Plugin.Interface);
}
internal IReadOnlyDictionary<ushort, IReadOnlyDictionary<string, string[]>>? GetPlayerResourcePaths() {
try {
return this.GetPlayerResourcePathsSubscriber.Invoke();
} catch {
return null;
}
}
}

View File

@ -5,11 +5,13 @@ using Screenie.Ui;
namespace Screenie;
public class Plugin : IDalamudPlugin {
public sealed class Plugin : IDalamudPlugin {
internal const string Name = "Screenie";
[PluginService]
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
internal static IPluginLog Log { get; private set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
[PluginService]
internal DalamudPluginInterface Interface { get; init; }
@ -36,32 +38,33 @@ public class Plugin : IDalamudPlugin {
internal IObjectTable ObjectTable { get; init; }
internal Configuration Config { get; }
internal PenumbraIpc Penumbra { get; }
internal Database Database { get; }
internal LinkHandlers LinkHandlers { get; }
internal PluginUi Ui { get; }
private Command Command { get; }
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public Plugin() {
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
this.Penumbra = new PenumbraIpc(this);
this.Database = new Database(this);
this.LinkHandlers = new LinkHandlers(this);
this.Ui = new PluginUi(this);
this.Command = new Command(this);
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public void Dispose() {
this.Command.Dispose();
this.Ui.Dispose();
this.LinkHandlers.Dispose();
this.Database.Dispose();
// this.Penumbra.Dispose();
}
internal void SaveConfig() {
this.Interface.SavePluginConfig(this.Config);
}
public static void Main() {
using var db = new Database("/home/anna/code/Screenie");
}
}

View File

@ -13,6 +13,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>IDE0003</NoWarn>
</PropertyGroup>
<PropertyGroup>
@ -56,17 +57,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blake3" Version="1.0.0"/>
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
<PackageReference Include="Blake3" Version="1.0.0" />
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Penumbra.Api" Version="1.0.14"/>
<PackageReference Include="Scriban" Version="5.9.1"/>
<PackageReference Include="SQLite" Version="3.13.0"/>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118"/>
<PackageReference Include="System.Drawing.Common" Version="8.0.2"/>
<PackageReference Include="WebP_Net" Version="1.1.1"/>
<PackageReference Include="Penumbra.Api" Version="1.0.14" />
<PackageReference Include="Scriban" Version="5.9.1" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="System.Drawing.Common" Version="8.0.2" />
<PackageReference Include="WebP_Net" Version="1.1.1" />
</ItemGroup>
</Project>

View File

@ -36,6 +36,7 @@ public class ScreenshotMetadata {
public required uint? Ward;
public required uint? Plot;
public required Character[] VisibleCharacters;
public required PenumbraMod[] ModsInUse;
internal static ScreenshotMetadata Capture(Plugin plugin) {
EorzeaTime eorzea;
@ -127,6 +128,7 @@ public class ScreenshotMetadata {
Ward = ward,
Plot = plot,
VisibleCharacters = visible,
ModsInUse = Array.Empty<PenumbraMod>(), // TODO
};
}
}
@ -193,3 +195,9 @@ public struct EorzeaTime {
this.Second = (ulong) Math.Floor(eorzea / SecondConst % 60);
}
}
[Serializable]
public class PenumbraMod {
public required string Path;
public required string Name;
}

View File

@ -69,10 +69,10 @@ internal class PluginUi : IDisposable {
ImGui.TextUnformatted("Save format");
ImGui.SetNextItemWidth(-1);
if (ImGui.BeginCombo("##file-format", Enum.GetName(this.Plugin.Config.SaveFormat))) {
if (ImGui.BeginCombo("##file-format", this.Plugin.Config.SaveFormat.Name())) {
using var endCombo = new OnDispose(ImGui.EndCombo);
foreach (var format in Enum.GetValues<Format>()) {
if (ImGui.Selectable(Enum.GetName(format), this.Plugin.Config.SaveFormat == format)) {
if (ImGui.Selectable(format.Name(), this.Plugin.Config.SaveFormat == format)) {
this.Plugin.Config.SaveFormat = format;
anyChanged = true;
}
@ -149,7 +149,7 @@ internal class PluginUi : IDisposable {
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Folder)) {
if (ImGuiComponents.IconButton("browse-save-dir", FontAwesomeIcon.Folder)) {
this.FileDialogManager.OpenFolderDialog(
"Choose screenshots folder",
(b, s) => {

BIN
database.sqlite Normal file

Binary file not shown.