Skip to content

Commit

Permalink
feat: add version to breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Oct 24, 2023
1 parent dace44e commit e31ede6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
13 changes: 12 additions & 1 deletion DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,20 @@ private async Task ConstructGroups(IDownloadTask_GetVersion info) {
return allSettings;
});

var oldVersion = "???";
var installedPkgs = await this.Plugin.State.GetInstalled();
if (installedPkgs.TryGetValue(info.Variant.Package.Id, out var meta)) {
var variant = meta.Variants.Find(v => v.Id == info.Variant.Id);
if (variant != null) {
oldVersion = variant.Version;
}
}

var change = new BreakingChange {
ModName = info.Variant.Package.Name,
VariantName = info.Variant.Name,
OldVersion = oldVersion,
NewVersion = info.Version,
ModPath = HeliosphereMeta.ModDirectoryName(info.Variant.Package.Id, info.Variant.Package.Name, info.Version, info.Variant.Id),
};

Expand Down Expand Up @@ -1282,4 +1293,4 @@ public override long Position {
get => this._inner.Position;
set => this._inner.Position = value;
}
}
}
8 changes: 8 additions & 0 deletions PackageState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public void Dispose() {
this.InstalledInternal.Dispose();
}

internal async Task<IReadOnlyDictionary<Guid, InstalledPackage>> GetInstalled(CancellationToken token = default) {
using var guard = await this.InstalledInternal.WaitAsync(token);
return guard.Data.ToImmutableDictionary(
entry => entry.Key,
entry => entry.Value
);
}

internal async Task UpdatePackages() {
// get the current update number. if this changes by the time this task
// gets a lock on the update mutex, the update that this task was queued
Expand Down
25 changes: 14 additions & 11 deletions Ui/BreakingChangeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void Draw() {

// draw each breaking change with a button to open that mod
foreach (var change in changes.Data) {
if (!ImGui.TreeNodeEx($"{change.ModName} ({change.VariantName})", ImGuiTreeNodeFlags.DefaultOpen)) {
if (!ImGui.TreeNodeEx($"{change.ModName} ({change.VariantName}): {change.OldVersion} \u2192 {change.NewVersion}", ImGuiTreeNodeFlags.DefaultOpen)) {
continue;
}

Expand All @@ -68,8 +68,8 @@ private void Draw() {
if (ImGui.TreeNodeEx("Removed option groups", ImGuiTreeNodeFlags.DefaultOpen)) {
using var pop3 = new OnDispose(ImGui.TreePop);

ImGui.TextUnformatted("These option groups are no longer available (but may be available under a different name), which means your settings for this group are no longer applied.");
ImGui.Spacing();
ImGui.SameLine();
ImGuiHelper.Help("These option groups are no longer available (but may be available under a different name), which means your settings for this group are no longer applied.");

foreach (var group in change.RemovedGroups) {
UnformattedBullet(group);
Expand All @@ -81,8 +81,8 @@ private void Draw() {
if (ImGui.TreeNodeEx("Changed group type", ImGuiTreeNodeFlags.DefaultOpen)) {
using var pop3 = new OnDispose(ImGui.TreePop);

ImGui.TextUnformatted("These option groups have gone from single-select to multi-select or vice versa, which can change your selected options in unexpected ways.");
ImGui.Spacing();
ImGui.SameLine();
ImGuiHelper.Help("These option groups have gone from single-select to multi-select or vice versa, which can change your selected options in unexpected ways.");

foreach (var group in change.ChangedType) {
UnformattedBullet(group);
Expand All @@ -94,8 +94,8 @@ private void Draw() {
if (ImGui.TreeNodeEx("Removed options", ImGuiTreeNodeFlags.DefaultOpen)) {
using var pop3 = new OnDispose(ImGui.TreePop);

ImGui.TextUnformatted("These option groups have had options removed from the end, which has unselected options you had enabled.");
ImGui.Spacing();
ImGui.SameLine();
ImGuiHelper.Help("These option groups have had options removed from the end, which has unselected options you had enabled.");

foreach (var (group, options) in change.TruncatedOptions) {
if (!ImGui.TreeNodeEx(group, ImGuiTreeNodeFlags.DefaultOpen)) {
Expand All @@ -114,8 +114,8 @@ private void Draw() {
if (ImGui.TreeNodeEx("Changed option names", ImGuiTreeNodeFlags.DefaultOpen)) {
using var pop3 = new OnDispose(ImGui.TreePop);

ImGui.TextUnformatted("These option groups have had their option names changed, which may have unexpectedly changed what options you have selected.");
ImGui.Spacing();
ImGui.SameLine();
ImGuiHelper.Help("These option groups have had their option names changed, which may have unexpectedly changed what options you have selected.");

foreach (var (group, _, _) in change.DifferentOptionNames) {
UnformattedBullet(group);
Expand All @@ -127,7 +127,8 @@ private void Draw() {
if (ImGui.TreeNodeEx("Changed option order", ImGuiTreeNodeFlags.DefaultOpen)) {
using var pop3 = new OnDispose(ImGui.TreePop);

ImGui.TextUnformatted("These option groups have had their options reordered, which may have unexpectedly changed what options you have selected.");
ImGui.SameLine();
ImGuiHelper.Help("These option groups have had their options reordered, which may have unexpectedly changed what options you have selected.");
ImGui.Spacing();

foreach (var (group, _, _) in change.ChangedOptionOrder) {
Expand All @@ -150,6 +151,8 @@ void UnformattedBullet(string text) {
internal class BreakingChange {
internal required string ModName { get; init; }
internal required string VariantName { get; init; }
internal required string OldVersion { get; init; }
internal required string NewVersion { get; init; }
internal required string ModPath { get; init; }
internal List<string> RemovedGroups { get; } = new();
internal List<string> ChangedType { get; } = new();
Expand All @@ -162,4 +165,4 @@ internal class BreakingChange {
|| this.TruncatedOptions.Count > 0
|| this.DifferentOptionNames.Count > 0
|| this.ChangedOptionOrder.Count > 0;
}
}
10 changes: 10 additions & 0 deletions Util/IReadOnlyListExt.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
namespace Heliosphere.Util;

internal static class ReadOnlyListExt {
internal static T? Find<T>(this IEnumerable<T> list, Predicate<T> predicate) {
foreach (var item in list) {
if (predicate(item)) {
return item;
}
}

return default;
}

internal static int FindIndex<T>(this IReadOnlyList<T> list, Predicate<T> predicate) {
for (var i = 0; i < list.Count; i++) {
if (predicate(list[i])) {
Expand Down

0 comments on commit e31ede6

Please sign in to comment.