Skip to content

Commit

Permalink
[refactor] More Data V2 & Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
DueDine committed Jan 21, 2025
1 parent 56d6234 commit 9fca7a2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ContactsTracker/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ContactsTracker;
[Serializable]
public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 0;
public int Version { get; set; } = 1;

public bool EnableLogging { get; set; } = true;

Expand Down
3 changes: 2 additions & 1 deletion ContactsTracker/Data/DataEntryV2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ContactsTracker.Logic;
using System;
using System.Collections.Generic;

namespace ContactsTracker.Data;

Expand All @@ -13,7 +14,7 @@ public class DataEntryV2(ushort territoryId, uint rouletteId)
public DateTime BeginAt { get; set; } = DateTime.Now;
public DateTime EndAt { get; set; } = DateTime.MinValue;
public string PlayerJobAbbr { get; set; } = string.Empty;
public string[] PartyMembers { get; set; } = []; // Flattened to string when saved to CSV
public List<string> PartyMembers { get; set; } = [];

public static DataEntryV2? Instance { get; private set; }

Expand Down
14 changes: 13 additions & 1 deletion ContactsTracker/Data/DatabaseV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class DatabaseV2

public static List<DataEntryV2> Entries { get; private set; } = [];

public static int Count => Entries.Count;

public static void InsertEntry(DataEntryV2 entry)
{
Entries.Add(entry);
Expand Down Expand Up @@ -45,6 +47,16 @@ public static void Load()
}
}

public static bool RemoveEntry(DataEntryV2 entry)
{
if (Entries.Remove(entry))
{
Save();
return true;
}
return false;
}

public static DataEntryV2? LoadInProgressEntry()
{
if (!File.Exists(TempPath))
Expand Down Expand Up @@ -142,7 +154,7 @@ public static bool Import(string filePath)
BeginAt = DateTime.Parse(beginAt!),
EndAt = DateTime.Parse(endAt!),
PlayerJobAbbr = playerJobAbbr!,
PartyMembers = partyMembers!.Split('|')
PartyMembers = [.. partyMembers!.Split('|')]
};
importedEntries.Add(entry);
}
Expand Down
11 changes: 5 additions & 6 deletions ContactsTracker/Logic/EntryLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static unsafe void EndRecord(DataEntryV2? entry, Configuration configurat

if (!configuration.EnableLogParty)
{
entry.PartyMembers[0] = "Party Logging Disabled For this Entry";
entry.PartyMembers.Add("Party Logging Disabled For this Entry");
}
else
{
Expand All @@ -29,7 +29,7 @@ public static unsafe void EndRecord(DataEntryV2? entry, Configuration configurat
DataEntryV2.Reset();
return;
}
entry.PartyMembers[0] = "Solo";
entry.PartyMembers.Add("Solo");
}

if (numOfParty > 1 && numOfParty <= 8)
Expand All @@ -51,12 +51,11 @@ public static unsafe void EndRecord(DataEntryV2? entry, Configuration configurat
names[i] += $" ({jobName})";
}

entry.PartyMembers[i] = names[i];
entry.PartyMembers.Add(names[i]);
}
}
}

// Database.InsertEntry(entry);
DatabaseV2.InsertEntry(entry);
DataEntryV2.Reset();
}
}
}
8 changes: 5 additions & 3 deletions ContactsTracker/Migration/EntryV1ToV2.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ContactsTracker.Data;
using Lumina.Excel.Sheets;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ContactsTracker.Migration;
Expand All @@ -14,6 +15,7 @@ public static bool Migrate()
var TerritoryExcel = Plugin.DataManager.GetExcelSheet<TerritoryType>();

var oldEntries = Database.Entries;
if (oldEntries.Count == 0) return true;

try
{
Expand Down Expand Up @@ -47,8 +49,8 @@ public static bool Migrate()
{
var members = entry.partyMembers.Split('|');
if (members.Length > 1)
members = [.. members.Take(members.Length - 1).Select(m => m.Trim())];
DataEntryV2.Instance!.PartyMembers = members;
members = members.Take(members.Length - 1).Select(m => m.Trim()).ToArray();
DataEntryV2.Instance!.PartyMembers = new List<string>(members);
}
DatabaseV2.InsertEntry(DataEntryV2.Instance);
}
Expand All @@ -61,4 +63,4 @@ public static bool Migrate()
return false;
}
}
}
}
16 changes: 9 additions & 7 deletions ContactsTracker/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class MainWindow : Window, IDisposable
{
private Plugin Plugin;
private int selectedTab = 0;
// private string commentBuffer = string.Empty;
private bool isFileDialogOpen = false;
private bool doubleCheck = false;
private bool enableSearch = false;

Check warning on line 21 in ContactsTracker/Windows/MainWindow.cs

View workflow job for this annotation

GitHub Actions / Build

The field 'MainWindow.enableSearch' is assigned but its value is never used

Check warning on line 21 in ContactsTracker/Windows/MainWindow.cs

View workflow job for this annotation

GitHub Actions / Build

The field 'MainWindow.enableSearch' is assigned but its value is never used
Expand Down Expand Up @@ -235,7 +234,7 @@ private void DrawHistoryTab()
ImGui.Spacing();

ImGuiHelpers.SafeTextWrapped("Party Members:");
if (entry.PartyMembers.Length == 0)
if (entry.PartyMembers.Count == 0)
{
ImGui.SameLine();
ImGuiHelpers.SafeTextWrapped("N/A");
Expand All @@ -244,7 +243,8 @@ private void DrawHistoryTab()
{
foreach (var member in entry.PartyMembers)
{
ImGui.BulletText(member);
if (!string.IsNullOrEmpty(member))
ImGui.BulletText(member);
}
}
ImGui.Spacing();
Expand All @@ -253,12 +253,11 @@ private void DrawHistoryTab()
{
if (Plugin.KeyState[VirtualKey.CONTROL])
{
entries.RemoveAt(selectedTab);
DatabaseV2.Save();
DatabaseV2.RemoveEntry(entry);

if (selectedTab >= entries.Count)
if (selectedTab >= DatabaseV2.Count)
{
selectedTab = Math.Max(-1, entries.Count - 1);
selectedTab = Math.Max(-1, DatabaseV2.Count - 1);
}
}
}
Expand Down Expand Up @@ -493,6 +492,9 @@ private void DrawSettingsTab()
{
ImGui.SetTooltip("Show the button to delete all active entries at Data Tab.");
}

ImGuiHelpers.ScaledDummy(5f);
ImGuiHelpers.SafeTextWrapped($"Configuration Version: {Plugin.Configuration.Version}");
}
}

Expand Down

0 comments on commit 9fca7a2

Please sign in to comment.