Skip to content

Commit

Permalink
Fixed items not being removed after merging them in Metadata Editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrKnarz committed Oct 1, 2024
1 parent 85de2f4 commit bb4031f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Generic/MetadataUtilities/Models/MergeRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ public IEnumerable<Guid> Merge(List<Game> games = null, bool removeAfter = true)
games = API.Instance.Database.Games.ToList();
}

result.AddMissing(item.ReplaceInDb(games, Type, Id, removeAfter));
result.AddMissing(item.ReplaceInDb(games, Type, Id));
}

MetadataFunctions.UpdateGames(result);

if (removeAfter)
{
foreach (var item in SourceObjects.Where(x =>
x.Id != Id && x.Id != default))
{
item.RemoveFromDb();
}
}
}
catch (Exception ex)
{
Expand Down
8 changes: 1 addition & 7 deletions Generic/MetadataUtilities/Models/MetadataObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ public bool RemoveFromDb(bool checkIfUsed = true)

public bool RemoveFromGame(Game game) => TypeManager is IEditableObjectType type && type.RemoveObjectFromGame(game, Id);

public IEnumerable<Guid> ReplaceInDb(List<Game> games, FieldType? newType = null, Guid? newId = null,
bool removeAfter = true)
public IEnumerable<Guid> ReplaceInDb(List<Game> games, FieldType? newType = null, Guid? newId = null)
{
IEnumerable<Guid> gameIds = new List<Guid>();

Expand All @@ -265,11 +264,6 @@ public IEnumerable<Guid> ReplaceInDb(List<Game> games, FieldType? newType = null
? type.ReplaceDbObject(games, Id, newTypeManager, newId)
: type.ReplaceDbObject(games, Id);

if (removeAfter && type.RemoveDbObject(Id))
{
Id = default;
}

return gameIds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public MetadataUtilities Plugin

foreach (var item in SelectedItems)
{
gamesAffected.AddMissing(item.ReplaceInDb(games, null, null, false).ToList());
gamesAffected.AddMissing(item.ReplaceInDb(games).ToList());
}

if (gamesAffected.Count == 0)
Expand Down

0 comments on commit bb4031f

Please sign in to comment.