2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-05-11 16:00:24 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.IO.Stores;
|
2019-05-25 14:09:31 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Database;
|
2021-05-11 16:00:24 +08:00
|
|
|
|
using osu.Game.IO;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class SkinInfo : IHasFiles<SkinFileInfo>, IEquatable<SkinInfo>, IHasPrimaryKey, ISoftDelete
|
|
|
|
|
{
|
2020-11-11 10:54:40 +08:00
|
|
|
|
internal const int DEFAULT_SKIN = 0;
|
|
|
|
|
internal const int CLASSIC_SKIN = -1;
|
|
|
|
|
internal const int RANDOM_SKIN = -2;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
2018-11-28 18:01:22 +08:00
|
|
|
|
public string Hash { get; set; }
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public string Creator { get; set; }
|
|
|
|
|
|
2021-05-11 16:00:24 +08:00
|
|
|
|
private string instantiationInfo;
|
|
|
|
|
|
|
|
|
|
public string InstantiationInfo
|
|
|
|
|
{
|
|
|
|
|
get => instantiationInfo;
|
|
|
|
|
set => instantiationInfo = abbreviateInstantiationInfo(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string abbreviateInstantiationInfo(string value)
|
|
|
|
|
{
|
|
|
|
|
// exclude version onwards, matching only on namespace and type.
|
|
|
|
|
// this is mainly to allow for new versions of already loaded rulesets to "upgrade" from old.
|
|
|
|
|
return string.Join(',', value.Split(',').Take(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual Skin CreateInstance(IResourceStore<byte[]> legacyDefaultResources, IStorageResourceProvider resources)
|
|
|
|
|
{
|
|
|
|
|
var type = string.IsNullOrEmpty(InstantiationInfo)
|
|
|
|
|
// handle the case of skins imported before InstantiationInfo was added.
|
|
|
|
|
? typeof(LegacySkin)
|
|
|
|
|
: Type.GetType(InstantiationInfo);
|
|
|
|
|
|
|
|
|
|
if (type == typeof(DefaultLegacySkin))
|
|
|
|
|
return (Skin)Activator.CreateInstance(type, this, legacyDefaultResources, resources);
|
|
|
|
|
|
|
|
|
|
return (Skin)Activator.CreateInstance(type, this, resources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SkinFileInfo> Files { get; set; } = new List<SkinFileInfo>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-05-25 14:09:31 +08:00
|
|
|
|
public List<DatabasedSetting> Settings { get; set; }
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool DeletePending { get; set; }
|
|
|
|
|
|
2019-08-29 15:38:39 +08:00
|
|
|
|
public static SkinInfo Default { get; } = new SkinInfo
|
|
|
|
|
{
|
2020-11-11 10:54:40 +08:00
|
|
|
|
ID = DEFAULT_SKIN,
|
2019-08-29 15:38:39 +08:00
|
|
|
|
Name = "osu!lazer",
|
2021-05-11 16:00:24 +08:00
|
|
|
|
Creator = "team osu!",
|
|
|
|
|
InstantiationInfo = typeof(DefaultSkin).AssemblyQualifiedName,
|
2019-08-29 15:38:39 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public bool Equals(SkinInfo other) => other != null && ID == other.ID;
|
|
|
|
|
|
2020-05-24 21:30:56 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
string author = Creator == null ? string.Empty : $"({Creator})";
|
|
|
|
|
return $"{Name} {author}".Trim();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|