osu/osu.Game/Skinning/SkinInfo.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
3.3 KiB
C#
Raw Normal View History

// 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
2018-02-22 07:29:05 +00:00
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.IO;
using osu.Game.Models;
using Realms;
namespace osu.Game.Skinning
{
[ExcludeFromDynamicCompile]
[MapTo("Skin")]
[JsonObject(MemberSerialization.OptIn)]
public class SkinInfo : RealmObject, IHasRealmFiles, IEquatable<SkinInfo>, IHasGuidPrimaryKey, ISoftDelete, IHasNamedFiles
{
2022-09-17 15:14:49 +00:00
internal static readonly Guid TRIANGLES_SKIN = new Guid("2991CFD8-2140-469A-BCB9-2EC23FBCE4AD");
2022-09-15 07:02:57 +00:00
internal static readonly Guid ARGON_SKIN = new Guid("CFFA69DE-B3E3-4DEE-8563-3C4F425C05D0");
internal static readonly Guid CLASSIC_SKIN = new Guid("81F02CD3-EEC6-4865-AC23-FAE26A386187");
internal static readonly Guid RANDOM_SKIN = new Guid("D39DFEFB-477C-4372-B1EA-2BCEA5FB8908");
2018-04-13 09:19:50 +00:00
[PrimaryKey]
[JsonProperty]
public Guid ID { get; set; }
[JsonProperty]
public string Name { get; set; } = null!;
2018-04-13 09:19:50 +00:00
[JsonProperty]
public string Creator { get; set; } = null!;
2018-11-28 10:01:22 +00:00
[JsonProperty]
public string InstantiationInfo { get; set; } = null!;
public string Hash { get; set; } = string.Empty;
2018-04-13 09:19:50 +00:00
2021-11-29 08:15:26 +00:00
public bool Protected { get; set; }
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);
if (type == null)
{
// Since the class was renamed from "DefaultSkin" to "TrianglesSkin", the type retrieval would fail
// for user modified skins. This aims to amicably handle that.
// If we ever add more default skins in the future this will need some kind of proper migration rather than
// a single fallback.
2022-09-17 15:14:49 +00:00
return new TrianglesSkin(this, resources);
}
return (Skin)Activator.CreateInstance(type, this, resources);
}
public IList<RealmNamedFileUsage> Files { get; } = null!;
2018-04-13 09:19:50 +00:00
public bool DeletePending { get; set; }
2018-04-13 09:19:50 +00:00
public SkinInfo(string? name = null, string? creator = null, string? instantiationInfo = null)
{
Name = name ?? string.Empty;
Creator = creator ?? string.Empty;
InstantiationInfo = instantiationInfo ?? string.Empty;
ID = Guid.NewGuid();
}
[UsedImplicitly] // Realm
private SkinInfo()
{
}
public bool Equals(SkinInfo? other)
{
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
2018-04-13 09:19:50 +00:00
return ID == other.ID;
}
2018-04-13 09:19:50 +00:00
public override string ToString()
{
string author = string.IsNullOrEmpty(Creator) ? string.Empty : $"({Creator})";
return $"{Name} {author}".Trim();
}
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
}
}