mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Add skin de-duplication
This commit is contained in:
@ -28,6 +28,28 @@ namespace osu.Game.Skinning
|
||||
|
||||
protected override string ImportFromStablePath => "Skins";
|
||||
|
||||
public SkinManager(Storage storage, DatabaseContextFactory contextFactory, IIpcHost importHost, AudioManager audio)
|
||||
: base(storage, contextFactory, new SkinStore(contextFactory, storage), importHost)
|
||||
{
|
||||
this.audio = audio;
|
||||
|
||||
ItemRemoved += removedInfo =>
|
||||
{
|
||||
// check the removed skin is not the current user choice. if it is, switch back to default.
|
||||
if (removedInfo.ID == CurrentSkinInfo.Value.ID)
|
||||
CurrentSkinInfo.Value = SkinInfo.Default;
|
||||
};
|
||||
|
||||
CurrentSkinInfo.ValueChanged += info => CurrentSkin.Value = getSkin(info);
|
||||
CurrentSkin.ValueChanged += skin =>
|
||||
{
|
||||
if (skin.SkinInfo != CurrentSkinInfo.Value)
|
||||
throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
|
||||
|
||||
SourceChanged?.Invoke();
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all usable <see cref="SkinInfo"/>s. Includes the special default skin plus all skins from <see cref="GetAllUserSkins"/>.
|
||||
/// </summary>
|
||||
@ -45,24 +67,16 @@ namespace osu.Game.Skinning
|
||||
/// <returns>A list of available <see cref="SkinInfo"/>.</returns>
|
||||
public List<SkinInfo> GetAllUserSkins() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList();
|
||||
|
||||
protected override SkinInfo CreateModel(ArchiveReader archive) => new SkinInfo
|
||||
{
|
||||
Name = archive.Name
|
||||
};
|
||||
protected override SkinInfo CheckForExisting(SkinInfo model)
|
||||
=> ModelStore.ConsumableItems.FirstOrDefault(s => s.Name == model.Name && s.Creator == model.Creator);
|
||||
|
||||
protected override SkinInfo CreateModel(ArchiveReader archive) => new SkinInfo { Name = archive.Name };
|
||||
|
||||
protected override void Populate(SkinInfo model, ArchiveReader archive)
|
||||
{
|
||||
base.Populate(model, archive);
|
||||
populate(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populate a <see cref="SkinInfo"/> from its <see cref="SkinConfiguration"/> (if possible).
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
private void populate(SkinInfo model)
|
||||
{
|
||||
Skin reference = GetSkin(model);
|
||||
Skin reference = getSkin(model);
|
||||
if (!string.IsNullOrEmpty(reference.Configuration.SkinInfo.Name))
|
||||
{
|
||||
model.Name = reference.Configuration.SkinInfo.Name;
|
||||
@ -80,7 +94,7 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
/// <param name="skinInfo">The skin to lookup.</param>
|
||||
/// <returns>A <see cref="Skin"/> instance correlating to the provided <see cref="SkinInfo"/>.</returns>
|
||||
public Skin GetSkin(SkinInfo skinInfo)
|
||||
private Skin getSkin(SkinInfo skinInfo)
|
||||
{
|
||||
if (skinInfo == SkinInfo.Default)
|
||||
return new DefaultSkin();
|
||||
@ -88,28 +102,6 @@ namespace osu.Game.Skinning
|
||||
return new LegacySkin(skinInfo, Files.Store, audio);
|
||||
}
|
||||
|
||||
public SkinManager(Storage storage, DatabaseContextFactory contextFactory, IIpcHost importHost, AudioManager audio)
|
||||
: base(storage, contextFactory, new SkinStore(contextFactory, storage), importHost)
|
||||
{
|
||||
this.audio = audio;
|
||||
|
||||
ItemRemoved += removedInfo =>
|
||||
{
|
||||
// check the removed skin is not the current user choice. if it is, switch back to default.
|
||||
if (removedInfo.ID == CurrentSkinInfo.Value.ID)
|
||||
CurrentSkinInfo.Value = SkinInfo.Default;
|
||||
};
|
||||
|
||||
CurrentSkinInfo.ValueChanged += info => CurrentSkin.Value = GetSkin(info);
|
||||
CurrentSkin.ValueChanged += skin =>
|
||||
{
|
||||
if (skin.SkinInfo != CurrentSkinInfo.Value)
|
||||
throw new InvalidOperationException($"Setting {nameof(CurrentSkin)}'s value directly is not supported. Use {nameof(CurrentSkinInfo)} instead.");
|
||||
|
||||
SourceChanged?.Invoke();
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a lookup query on available <see cref="SkinInfo"/>s.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user