Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented category diff and object diff blocks #1

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 7 additions & 8 deletions Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ 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)
{
Type = type;
Description = description;
}

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

public DiffBlock(DiffType type, string? description, string dataKey)
: this(type, description, dataKey, string.Empty) { }

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