Fix automatically created "(modified)" skins getting conflicting names

Applies the already tested and proven method that is used in the editor
to the mutable skin creation flow.
This commit is contained in:
Dean Herbert 2022-04-01 14:11:53 +09:00
parent 0a86bf6fb1
commit 69d4f86122

View File

@ -24,6 +24,7 @@ using osu.Game.Database;
using osu.Game.IO;
using osu.Game.IO.Archives;
using osu.Game.Overlays.Notifications;
using osu.Game.Utils;
namespace osu.Game.Skinning
{
@ -144,20 +145,26 @@ namespace osu.Game.Skinning
if (!s.Protected)
return;
var existingSkinNames = realm.Run(r => r.All<SkinInfo>()
.Where(skin => !skin.DeletePending)
.AsEnumerable()
.Select(skin => skin.Name));
// if the user is attempting to save one of the default skin implementations, create a copy first.
var result = skinModelManager.Import(new SkinInfo
var skinInfo = new SkinInfo
{
Name = s.Name + @" (modified)",
Creator = s.Creator,
InstantiationInfo = s.InstantiationInfo,
});
Name = NamingUtils.GetNextBestName(existingSkinNames, $"{s.Name} (modified)")
};
var result = skinModelManager.Import(skinInfo);
if (result != null)
{
// save once to ensure the required json content is populated.
// currently this only happens on save.
result.PerformRead(skin => Save(skin.CreateInstance(this)));
CurrentSkinInfo.Value = result;
}
});