2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-05-14 21:45:58 +00:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Database;
|
2021-05-12 21:34:25 +00:00
|
|
|
|
using osu.Game.Extensions;
|
2021-05-11 08:00:24 +00:00
|
|
|
|
using osu.Game.IO;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class SkinInfo : IHasFiles<SkinFileInfo>, IEquatable<SkinInfo>, IHasPrimaryKey, ISoftDelete
|
|
|
|
|
{
|
2020-11-11 02:54:40 +00:00
|
|
|
|
internal const int DEFAULT_SKIN = 0;
|
|
|
|
|
internal const int CLASSIC_SKIN = -1;
|
|
|
|
|
internal const int RANDOM_SKIN = -2;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
2021-10-21 04:36:04 +00:00
|
|
|
|
public string Name { get; set; } = string.Empty;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-21 04:36:04 +00:00
|
|
|
|
public string Creator { get; set; } = string.Empty;
|
2018-11-28 10:01:22 +00:00
|
|
|
|
|
2021-10-21 04:36:04 +00:00
|
|
|
|
public string Hash { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-05-12 20:42:26 +00:00
|
|
|
|
public string InstantiationInfo { get; set; }
|
2021-05-11 08:00:24 +00:00
|
|
|
|
|
2021-05-31 09:58:40 +00:00
|
|
|
|
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
2021-05-11 08:00:24 +00:00
|
|
|
|
{
|
|
|
|
|
var type = string.IsNullOrEmpty(InstantiationInfo)
|
|
|
|
|
// handle the case of skins imported before InstantiationInfo was added.
|
|
|
|
|
? typeof(LegacySkin)
|
2021-05-14 21:45:58 +00:00
|
|
|
|
: Type.GetType(InstantiationInfo).AsNonNull();
|
2021-05-11 08:00:24 +00:00
|
|
|
|
|
|
|
|
|
return (Skin)Activator.CreateInstance(type, this, resources);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 04:42:07 +00:00
|
|
|
|
public List<SkinFileInfo> Files { get; } = new List<SkinFileInfo>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public bool DeletePending { get; set; }
|
|
|
|
|
|
2019-08-29 07:38:39 +00:00
|
|
|
|
public static SkinInfo Default { get; } = new SkinInfo
|
|
|
|
|
{
|
2020-11-11 02:54:40 +00:00
|
|
|
|
ID = DEFAULT_SKIN,
|
2021-07-04 03:39:50 +00:00
|
|
|
|
Name = "osu! (triangles)",
|
2021-05-11 08:00:24 +00:00
|
|
|
|
Creator = "team osu!",
|
2021-05-12 21:34:25 +00:00
|
|
|
|
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()
|
2019-08-29 07:38:39 +00:00
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public bool Equals(SkinInfo other) => other != null && ID == other.ID;
|
|
|
|
|
|
2020-05-24 13:30:56 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
string author = Creator == null ? string.Empty : $"({Creator})";
|
|
|
|
|
return $"{Name} {author}".Trim();
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|