mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:43:19 +08:00
Replace EF SkinInfo
with realm implementation
This commit is contained in:
parent
5f067172b4
commit
e283379f0e
@ -25,7 +25,7 @@ namespace osu.Game.Database
|
|||||||
public DbSet<BeatmapSetInfo> BeatmapSetInfo { get; set; }
|
public DbSet<BeatmapSetInfo> BeatmapSetInfo { get; set; }
|
||||||
public DbSet<FileInfo> FileInfo { get; set; }
|
public DbSet<FileInfo> FileInfo { get; set; }
|
||||||
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
||||||
public DbSet<SkinInfo> SkinInfo { get; set; }
|
public DbSet<EFSkinInfo> SkinInfo { get; set; }
|
||||||
public DbSet<ScoreInfo> ScoreInfo { get; set; }
|
public DbSet<ScoreInfo> ScoreInfo { get; set; }
|
||||||
|
|
||||||
// migrated to realm
|
// migrated to realm
|
||||||
@ -133,8 +133,8 @@ namespace osu.Game.Database
|
|||||||
modelBuilder.Entity<BeatmapSetInfo>().HasIndex(b => b.DeletePending);
|
modelBuilder.Entity<BeatmapSetInfo>().HasIndex(b => b.DeletePending);
|
||||||
modelBuilder.Entity<BeatmapSetInfo>().HasIndex(b => b.Hash).IsUnique();
|
modelBuilder.Entity<BeatmapSetInfo>().HasIndex(b => b.Hash).IsUnique();
|
||||||
|
|
||||||
modelBuilder.Entity<SkinInfo>().HasIndex(b => b.Hash).IsUnique();
|
modelBuilder.Entity<EFSkinInfo>().HasIndex(b => b.Hash).IsUnique();
|
||||||
modelBuilder.Entity<SkinInfo>().HasIndex(b => b.DeletePending);
|
modelBuilder.Entity<EFSkinInfo>().HasIndex(b => b.DeletePending);
|
||||||
|
|
||||||
modelBuilder.Entity<DatabasedSetting>().HasIndex(b => new { b.RulesetID, b.Variant });
|
modelBuilder.Entity<DatabasedSetting>().HasIndex(b => new { b.RulesetID, b.Variant });
|
||||||
|
|
||||||
|
@ -1,33 +1,32 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Skinning;
|
|
||||||
using Realms;
|
|
||||||
|
|
||||||
#nullable enable
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
[Table(@"SkinInfo")]
|
||||||
|
public class EFSkinInfo : IHasFiles<SkinFileInfo>, IEquatable<EFSkinInfo>, IHasPrimaryKey, ISoftDelete
|
||||||
|
{
|
||||||
|
internal const int DEFAULT_SKIN = 0;
|
||||||
|
internal const int CLASSIC_SKIN = -1;
|
||||||
|
internal const int RANDOM_SKIN = -2;
|
||||||
|
|
||||||
namespace osu.Game.Models
|
public int ID { get; set; }
|
||||||
{
|
|
||||||
[ExcludeFromDynamicCompile]
|
|
||||||
[MapTo("Skin")]
|
|
||||||
public class RealmSkin : RealmObject, IHasRealmFiles, IEquatable<RealmSkin>, IHasGuidPrimaryKey, ISoftDelete
|
|
||||||
{
|
|
||||||
public Guid ID { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Creator { get; set; } = string.Empty;
|
public string Creator { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Hash { get; set; } = string.Empty;
|
public string Hash { get; set; }
|
||||||
|
|
||||||
public string InstantiationInfo { get; set; } = string.Empty;
|
public string InstantiationInfo { get; set; }
|
||||||
|
|
||||||
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
||||||
{
|
{
|
||||||
@ -39,28 +38,23 @@ namespace osu.Game.Models
|
|||||||
return (Skin)Activator.CreateInstance(type, this, resources);
|
return (Skin)Activator.CreateInstance(type, this, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
public List<SkinFileInfo> Files { get; set; } = new List<SkinFileInfo>();
|
||||||
|
|
||||||
public bool DeletePending { get; set; }
|
public bool DeletePending { get; set; }
|
||||||
|
|
||||||
public static RealmSkin Default { get; } = new RealmSkin
|
public static EFSkinInfo Default { get; } = new EFSkinInfo
|
||||||
{
|
{
|
||||||
|
ID = DEFAULT_SKIN,
|
||||||
Name = "osu! (triangles)",
|
Name = "osu! (triangles)",
|
||||||
Creator = "team osu!",
|
Creator = "team osu!",
|
||||||
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
|
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
|
||||||
};
|
};
|
||||||
|
|
||||||
public bool Equals(RealmSkin? other)
|
public bool Equals(EFSkinInfo other) => other != null && ID == other.ID;
|
||||||
{
|
|
||||||
if (ReferenceEquals(this, other)) return true;
|
|
||||||
if (other == null) return false;
|
|
||||||
|
|
||||||
return ID == other.ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string author = string.IsNullOrEmpty(Creator) ? string.Empty : $"({Creator})";
|
string author = Creator == null ? string.Empty : $"({Creator})";
|
||||||
return $"{Name} {author}".Trim();
|
return $"{Name} {author}".Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,30 +1,38 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
|
using osu.Game.Models;
|
||||||
|
using Realms;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
public class SkinInfo : IHasFiles<SkinFileInfo>, IEquatable<SkinInfo>, IHasPrimaryKey, ISoftDelete, IHasNamedFiles
|
[ExcludeFromDynamicCompile]
|
||||||
|
[MapTo("Skin")]
|
||||||
|
public class SkinInfo : RealmObject, IHasRealmFiles, IEquatable<SkinInfo>, IHasGuidPrimaryKey, ISoftDelete, IHasNamedFiles
|
||||||
{
|
{
|
||||||
internal const int DEFAULT_SKIN = 0;
|
internal static readonly Guid DEFAULT_SKIN = new Guid("2991CFD8-2140-469A-BCB9-2EC23FBCE4AD");
|
||||||
internal const int CLASSIC_SKIN = -1;
|
internal static readonly Guid CLASSIC_SKIN = new Guid("81F02CD3-EEC6-4865-AC23-FAE26A386187");
|
||||||
internal const int RANDOM_SKIN = -2;
|
internal static readonly Guid RANDOM_SKIN = new Guid("D39DFEFB-477C-4372-B1EA-2BCEA5FB8908");
|
||||||
|
|
||||||
public int ID { get; set; }
|
[PrimaryKey]
|
||||||
|
public Guid ID { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Creator { get; set; } = string.Empty;
|
public string Creator { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string InstantiationInfo { get; set; }
|
public string InstantiationInfo { get; set; } = string.Empty;
|
||||||
|
|
||||||
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
||||||
{
|
{
|
||||||
@ -36,23 +44,28 @@ namespace osu.Game.Skinning
|
|||||||
return (Skin)Activator.CreateInstance(type, this, resources);
|
return (Skin)Activator.CreateInstance(type, this, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SkinFileInfo> Files { get; } = new List<SkinFileInfo>();
|
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
||||||
|
|
||||||
public bool DeletePending { get; set; }
|
public bool DeletePending { get; set; }
|
||||||
|
|
||||||
public static SkinInfo Default { get; } = new SkinInfo
|
public static SkinInfo Default { get; } = new SkinInfo
|
||||||
{
|
{
|
||||||
ID = DEFAULT_SKIN,
|
|
||||||
Name = "osu! (triangles)",
|
Name = "osu! (triangles)",
|
||||||
Creator = "team osu!",
|
Creator = "team osu!",
|
||||||
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
|
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
|
||||||
};
|
};
|
||||||
|
|
||||||
public bool Equals(SkinInfo other) => other != null && ID == other.ID;
|
public bool Equals(SkinInfo? other)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
if (other == null) return false;
|
||||||
|
|
||||||
|
return ID == other.ID;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string author = Creator == null ? string.Empty : $"({Creator})";
|
string author = string.IsNullOrEmpty(Creator) ? string.Empty : $"({Creator})";
|
||||||
return $"{Name} {author}".Trim();
|
return $"{Name} {author}".Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ using osu.Game.Database;
|
|||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
public class SkinStore : MutableDatabaseBackedStoreWithFileIncludes<SkinInfo, SkinFileInfo>
|
public class SkinStore : MutableDatabaseBackedStoreWithFileIncludes<EFSkinInfo, SkinFileInfo>
|
||||||
{
|
{
|
||||||
public SkinStore(DatabaseContextFactory contextFactory, Storage storage = null)
|
public SkinStore(DatabaseContextFactory contextFactory, Storage storage = null)
|
||||||
: base(contextFactory, storage)
|
: base(contextFactory, storage)
|
||||||
|
Loading…
Reference in New Issue
Block a user