1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-22 02:33:21 +08:00
osu-lazer/osu.Game/Skinning/EFSkinInfo.cs

66 lines
2.1 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2021-11-23 13:54:57 +08:00
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-11-23 13:54:57 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
2021-11-23 13:54:57 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.IO;
namespace osu.Game.Skinning
2021-11-23 13:54:57 +08:00
{
[Table(@"SkinInfo")]
public class EFSkinInfo : IHasFiles<SkinFileInfo>, IEquatable<EFSkinInfo>, IHasPrimaryKey, ISoftDelete
2021-11-23 13:54:57 +08:00
{
internal const int DEFAULT_SKIN = 0;
internal const int CLASSIC_SKIN = -1;
internal const int RANDOM_SKIN = -2;
public int ID { get; set; }
2021-11-23 13:54:57 +08:00
public string Name { get; set; } = string.Empty;
public string Creator { get; set; } = string.Empty;
public string Hash { get; set; }
2021-11-23 13:54:57 +08:00
public string InstantiationInfo { get; set; }
2021-11-23 13:54:57 +08:00
public virtual Skin CreateInstance(IStorageResourceProvider resources)
{
var type = string.IsNullOrEmpty(InstantiationInfo)
// handle the case of skins imported before InstantiationInfo was added.
? typeof(LegacySkin)
: Type.GetType(InstantiationInfo).AsNonNull();
return (Skin)Activator.CreateInstance(type, this, resources);
}
public List<SkinFileInfo> Files { get; set; } = new List<SkinFileInfo>();
2021-11-23 13:54:57 +08:00
public bool DeletePending { get; set; }
public static EFSkinInfo Default { get; } = new EFSkinInfo
2021-11-23 13:54:57 +08:00
{
ID = DEFAULT_SKIN,
2021-11-23 13:54:57 +08:00
Name = "osu! (triangles)",
Creator = "team osu!",
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
};
public bool Equals(EFSkinInfo other) => other != null && ID == other.ID;
2021-11-23 13:54:57 +08:00
public override string ToString()
{
string author = Creator == null ? string.Empty : $"({Creator})";
2021-11-23 13:54:57 +08:00
return $"{Name} {author}".Trim();
}
public bool IsManaged => ID > 0;
2021-11-23 13:54:57 +08:00
}
}