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
|
|
|
|
|
2018-02-22 15:29:05 +08:00
|
|
|
|
using System;
|
2018-02-15 12:45:39 +08:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-20 16:29:03 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2021-12-03 15:36:27 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2018-02-15 12:45:39 +08:00
|
|
|
|
using osu.Game.Database;
|
2021-05-11 16:00:24 +08:00
|
|
|
|
using osu.Game.IO;
|
2021-11-23 14:31:07 +08:00
|
|
|
|
using osu.Game.Models;
|
|
|
|
|
using Realms;
|
|
|
|
|
|
2018-02-15 12:45:39 +08:00
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
2021-11-23 14:31:07 +08:00
|
|
|
|
[MapTo("Skin")]
|
2021-12-03 15:36:27 +08:00
|
|
|
|
[JsonObject(MemberSerialization.OptIn)]
|
2021-11-23 14:31:07 +08:00
|
|
|
|
public class SkinInfo : RealmObject, IHasRealmFiles, IEquatable<SkinInfo>, IHasGuidPrimaryKey, ISoftDelete, IHasNamedFiles
|
2018-02-15 12:45:39 +08:00
|
|
|
|
{
|
2022-09-17 23:14:49 +08:00
|
|
|
|
internal static readonly Guid TRIANGLES_SKIN = new Guid("2991CFD8-2140-469A-BCB9-2EC23FBCE4AD");
|
2022-09-15 15:02:57 +08:00
|
|
|
|
internal static readonly Guid ARGON_SKIN = new Guid("CFFA69DE-B3E3-4DEE-8563-3C4F425C05D0");
|
2022-12-12 14:52:29 +08:00
|
|
|
|
internal static readonly Guid ARGON_PRO_SKIN = new Guid("9FC9CF5D-0F16-4C71-8256-98868321AC43");
|
2021-11-23 14:31:07 +08:00
|
|
|
|
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 17:19:50 +08:00
|
|
|
|
|
2021-11-23 14:31:07 +08:00
|
|
|
|
[PrimaryKey]
|
2021-12-03 15:36:27 +08:00
|
|
|
|
[JsonProperty]
|
2022-01-20 16:29:03 +08:00
|
|
|
|
public Guid ID { get; set; }
|
2021-11-19 20:53:40 +08:00
|
|
|
|
|
2021-12-03 15:36:27 +08:00
|
|
|
|
[JsonProperty]
|
2022-01-20 16:29:03 +08:00
|
|
|
|
public string Name { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-12-03 15:36:27 +08:00
|
|
|
|
[JsonProperty]
|
2022-01-20 16:29:03 +08:00
|
|
|
|
public string Creator { get; set; } = null!;
|
2018-11-28 18:01:22 +08:00
|
|
|
|
|
2021-12-03 15:36:27 +08:00
|
|
|
|
[JsonProperty]
|
2022-01-20 16:29:03 +08:00
|
|
|
|
public string InstantiationInfo { get; set; } = null!;
|
2021-12-03 15:36:27 +08:00
|
|
|
|
|
2021-11-23 14:31:07 +08:00
|
|
|
|
public string Hash { get; set; } = string.Empty;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-29 16:15:26 +08:00
|
|
|
|
public bool Protected { get; set; }
|
2021-05-11 16:00:24 +08:00
|
|
|
|
|
2021-05-31 17:58:40 +08:00
|
|
|
|
public virtual Skin CreateInstance(IStorageResourceProvider resources)
|
2021-05-11 16:00:24 +08:00
|
|
|
|
{
|
|
|
|
|
var type = string.IsNullOrEmpty(InstantiationInfo)
|
|
|
|
|
// handle the case of skins imported before InstantiationInfo was added.
|
|
|
|
|
? typeof(LegacySkin)
|
2022-09-21 03:27:27 +08:00
|
|
|
|
: Type.GetType(InstantiationInfo);
|
2021-05-11 16:00:24 +08:00
|
|
|
|
|
2022-09-21 03:27:27 +08:00
|
|
|
|
if (type == null)
|
2022-09-15 14:49:26 +08:00
|
|
|
|
{
|
2022-09-21 03:27:27 +08:00
|
|
|
|
// Since the class was renamed from "DefaultSkin" to "TrianglesSkin", the type retrieval would fail
|
2022-09-18 17:20:28 +08:00
|
|
|
|
// for user modified skins. This aims to amicably handle that.
|
2022-09-15 14:49:26 +08:00
|
|
|
|
// If we ever add more default skins in the future this will need some kind of proper migration rather than
|
2022-09-21 03:27:27 +08:00
|
|
|
|
// a single fallback.
|
2022-09-17 23:14:49 +08:00
|
|
|
|
return new TrianglesSkin(this, resources);
|
2022-09-15 14:49:26 +08:00
|
|
|
|
}
|
2022-09-21 03:27:27 +08:00
|
|
|
|
|
2022-12-16 17:16:26 +08:00
|
|
|
|
return (Skin)Activator.CreateInstance(type, this, resources)!;
|
2021-05-11 16:00:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 14:31:07 +08:00
|
|
|
|
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-15 12:45:39 +08:00
|
|
|
|
public bool DeletePending { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-01-20 16:29:03 +08: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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 14:31:07 +08:00
|
|
|
|
public bool Equals(SkinInfo? other)
|
2019-08-29 15:38:39 +08:00
|
|
|
|
{
|
2021-11-23 14:31:07 +08:00
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
|
if (other == null) return false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-23 14:31:07 +08:00
|
|
|
|
return ID == other.ID;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-05-24 21:30:56 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2021-11-23 14:31:07 +08:00
|
|
|
|
string author = string.IsNullOrEmpty(Creator) ? string.Empty : $"({Creator})";
|
2020-05-24 21:30:56 +08:00
|
|
|
|
return $"{Name} {author}".Trim();
|
|
|
|
|
}
|
2021-11-25 15:35:42 +08:00
|
|
|
|
|
|
|
|
|
IEnumerable<INamedFileUsage> IHasNamedFiles.Files => Files;
|
2018-02-15 12:45:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|