Skip to content

Commit

Permalink
Implemented category diff and object diff blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperbx committed Nov 2, 2023
1 parent e160169 commit 5acf901
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Source/Libraries/HedgeModManager.CodeCompiler/CodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ string GetCodeDiffName(CSharpCode code)
// Renamed
if (Codes.SingleOrDefault(x => x.Body == code.Body) is { } renamed)
{
if (code.Name != renamed.Name)
if (code.Name != renamed.Name || code.Category != renamed.Category)
{
diff.Renamed($"{GetCodeDiffName(code)} -> {GetCodeDiffName(renamed)}", code.Name, renamed.Name);
diff.Renamed($"{GetCodeDiffName(code)} -> {GetCodeDiffName(renamed)}", code, renamed);

// Remove this code from the added list so we don't display it twice.
if (addedCodes.SingleOrDefault(x => x.Name == renamed.Name) is { } duplicate)
Expand Down
11 changes: 11 additions & 0 deletions Source/Libraries/HedgeModManager.Diagnostics/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public void MakeBlock(DiffType type, string? description, string dataKey, string
mBlocks[(int)type].Add(new DiffBlock(type, description, dataKey, dataValue));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void MakeBlock(DiffType type, string? description, object dataKey, object dataValue)
{
mBlocks[(int)type].Add(new DiffBlock(type, description, dataKey, dataValue));
}

public void Add(DiffBlock block)
{
mBlocks[(int)block.Type].Add(block);
Expand All @@ -50,6 +56,11 @@ public void Renamed(string? description, string oldName, string newName)
MakeBlock(DiffType.Renamed, description, oldName, newName);
}

public void Renamed(string? description, object oldData, object newData)
{
MakeBlock(DiffType.Renamed, description, oldData, newData);
}

public List<DiffBlock> ToList()
{
var list = new List<DiffBlock>(mBlocks.Sum(x => x.Count));
Expand Down
11 changes: 7 additions & 4 deletions Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class DiffBlock
{
public DiffType Type { get; set; }
public string? Description { get; set; }
public KeyValuePair<string, string> Data { get; set; }
public KeyValuePair<object, object> Data { get; set; }

public DiffBlock(DiffType type, string? description)
{
Expand All @@ -16,13 +16,16 @@ public DiffBlock(DiffType type, string? description, string dataKey)
{
Type = type;
Description = description;
Data = new KeyValuePair<string, string>(dataKey, string.Empty);
Data = new(dataKey, string.Empty);
}

public DiffBlock(DiffType type, string? description, string dataKey, string dataValue)
public DiffBlock(DiffType type, string? description, object dataKey, object dataValue)
{
Type = type;
Description = description;
Data = new KeyValuePair<string, string>(dataKey, dataValue);
Data = new(dataKey, dataValue);
}

public DiffBlock(DiffType type, string? description, string dataKey, string dataValue)
: this(type, description, (object)dataKey, (object)dataValue) { }
}

0 comments on commit 5acf901

Please sign in to comment.