feat: organise screenshots by character

This commit is contained in:
Anna 2024-02-18 14:24:25 -05:00
parent 9440dc6af2
commit 538b88c63f
Signed by: anna
GPG Key ID: D0943384CD9F87D1
4 changed files with 48 additions and 23 deletions

View File

@ -9,6 +9,7 @@ using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
using Screenie.Util;
using Map = Lumina.Excel.GeneratedSheets.Map;
namespace Screenie;
@ -117,7 +118,7 @@ public class ScreenshotMetadata {
var mods = plugin.Penumbra.GetMods();
var modsInUse = new HashSet<PenumbraMod>();
if (modDir != null && paths != null && mods != null) {
var baseUri = new Uri($"{modDir}/");
var baseUri = new Uri($"{Path.TrimEndingDirectorySeparator(modDir)}/");
foreach (var dict in paths.Values) {
foreach (var path in dict.Keys) {
if (!Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var pathUri)) {
@ -193,8 +194,10 @@ public class Character {
}
[JsonConstructor]
internal Character() {
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private Character() {
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private static float ConvertRawPositionToMapCoordinate(float pos, float scale, short offset) {
var num2 = (pos + offset) * scale;

View File

@ -1,3 +1,4 @@
using System.Data;
using ImGuiNET;
using Newtonsoft.Json;
using Screenie.Util;
@ -24,8 +25,22 @@ internal class DatabaseTab : ITab {
this.Update();
}
foreach (var meta in this.Screenshots) {
ImGui.TextUnformatted(meta.Path);
var byChara = this.Screenshots.GroupBy(shot => {
var chara = shot.Metadata.ActiveCharacter;
if (chara == null) {
return default;
}
return (chara.Name, chara.HomeWorld);
});
foreach (var group in byChara) {
var (name, homeWorld) = group.Key;
if (ImGui.CollapsingHeader($"{name} ({homeWorld})")) {
foreach (var shot in group) {
ImGui.TextUnformatted(shot.Path);
}
}
}
}
@ -39,30 +54,30 @@ internal class DatabaseTab : ITab {
this.Screenshots.Clear();
while (reader.Read()) {
var meta = new SavedMetadata {
Blake3Hash = reader.GetFieldValue<string>(0),
Path = reader.GetFieldValue<string>(1),
Blake3Hash = reader.GetFieldValue<string>("hash"),
Path = reader.GetFieldValue<string>("path"),
Metadata = new ScreenshotMetadata {
ActiveCharacter = JsonConvert.DeserializeObject<Character>(
reader.GetFieldValue<string>(2)
reader.GetFieldValue<string>("active_character")
),
Location = reader.GetNullableFieldValue<string>(3),
LocationSub = reader.GetNullableFieldValue<string>(4),
Area = reader.GetNullableFieldValue<string>(5),
AreaSub = reader.GetNullableFieldValue<string>(6),
TerritoryType = (uint) reader.GetFieldValue<int>(7),
World = reader.GetNullableFieldValue<string>(8),
WorldId = (uint) reader.GetFieldValue<int>(9),
CapturedAtLocal = reader.GetFieldValue<DateTime>(10),
CapturedAtUtc = reader.GetFieldValue<DateTime>(11),
EorzeaTime = reader.GetFieldValue<string>(12),
Weather = reader.GetNullableFieldValue<string>(13),
Ward = (uint?) reader.GetNullableFieldValue<int>(14),
Plot = (uint?) reader.GetNullableFieldValue<int>(15),
Location = reader.GetNullableFieldValue<string>("location"),
LocationSub = reader.GetNullableFieldValue<string>("location_sub"),
Area = reader.GetNullableFieldValue<string>("area"),
AreaSub = reader.GetNullableFieldValue<string>("area_sub"),
TerritoryType = (uint) reader.GetFieldValue<int>("territory_type"),
World = reader.GetNullableFieldValue<string>("world"),
WorldId = (uint) reader.GetFieldValue<int>("world_id"),
CapturedAtLocal = reader.GetFieldValue<DateTime>("captured_at_local"),
CapturedAtUtc = reader.GetFieldValue<DateTime>("captured_at_utc"),
EorzeaTime = reader.GetFieldValue<string>("eorzea_time"),
Weather = reader.GetNullableFieldValue<string>("weather"),
Ward = (uint?) reader.GetNullableFieldValue<int>("ward"),
Plot = (uint?) reader.GetNullableFieldValue<int>("plot"),
VisibleCharacters = JsonConvert.DeserializeObject<Character[]>(
reader.GetFieldValue<string>(16)
reader.GetFieldValue<string>("visible_characters")
) ?? [],
ModsInUse = JsonConvert.DeserializeObject<PenumbraMod[]>(
reader.GetFieldValue<string>(17)
reader.GetFieldValue<string>("mods_in_use")
) ?? [],
},
};

View File

@ -1,3 +1,4 @@
using System.Data;
using System.Data.SQLite;
namespace Screenie.Util;
@ -8,4 +9,10 @@ internal static class SQLiteDataReaderExt {
? default
: reader.GetFieldValue<T>(index);
}
internal static T? GetNullableFieldValue<T>(this SQLiteDataReader reader, string name) {
return reader.IsDBNull(name)
? default
: reader.GetFieldValue<T>(name);
}
}

View File

@ -1,4 +1,4 @@
namespace Screenie;
namespace Screenie.Util;
internal static class StringExt {
internal static string? EmptyToNull(this string? text) {