2022-07-31 14:42:18 +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.
|
|
|
|
|
|
|
|
using System;
|
2022-08-01 05:04:06 +00:00
|
|
|
using System.Collections.Generic;
|
2022-07-31 14:42:18 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.IO;
|
|
|
|
using osu.Game.IO.Archives;
|
2024-08-23 11:44:35 +00:00
|
|
|
using osu.Game.Screens.Menu;
|
2022-08-01 05:04:06 +00:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2022-08-01 05:16:26 +00:00
|
|
|
using osu.Game.Screens.Play.HUD.HitErrorMeters;
|
2022-07-31 14:42:18 +00:00
|
|
|
using osu.Game.Skinning;
|
2023-11-15 05:07:51 +00:00
|
|
|
using osu.Game.Skinning.Components;
|
2022-07-31 14:42:18 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Skins
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Test that the main components (which are serialised based on namespace/class name)
|
|
|
|
/// remain compatible with any changes.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// If this test breaks, check any naming or class structure changes.
|
|
|
|
/// Migration rules may need to be added to <see cref="Skin"/>.
|
|
|
|
/// </remarks>
|
|
|
|
[TestFixture]
|
|
|
|
public class SkinDeserialisationTest
|
|
|
|
{
|
2022-08-01 05:04:06 +00:00
|
|
|
private static readonly string[] available_skins =
|
|
|
|
{
|
|
|
|
// Covers song progress before namespace changes, and most other components.
|
|
|
|
"Archives/modified-default-20220723.osk",
|
2022-08-01 05:16:26 +00:00
|
|
|
"Archives/modified-classic-20220723.osk",
|
|
|
|
// Covers legacy song progress, UR counter, colour hit error metre.
|
2022-08-18 22:49:03 +00:00
|
|
|
"Archives/modified-classic-20220801.osk",
|
|
|
|
// Covers clicks/s counter
|
2022-10-12 09:55:50 +00:00
|
|
|
"Archives/modified-default-20220818.osk",
|
|
|
|
// Covers longest combo counter
|
2022-11-02 15:37:48 +00:00
|
|
|
"Archives/modified-default-20221012.osk",
|
2023-01-09 21:07:18 +00:00
|
|
|
// Covers Argon variant of song progress bar
|
|
|
|
"Archives/modified-argon-20221024.osk",
|
2022-11-02 15:37:48 +00:00
|
|
|
// Covers TextElement and BeatmapInfoDrawable
|
2022-12-05 18:34:03 +00:00
|
|
|
"Archives/modified-default-20221102.osk",
|
|
|
|
// Covers BPM counter.
|
2023-01-11 10:16:24 +00:00
|
|
|
"Archives/modified-default-20221205.osk",
|
|
|
|
// Covers judgement counter.
|
2023-03-05 23:46:51 +00:00
|
|
|
"Archives/modified-default-20230117.osk",
|
|
|
|
// Covers player avatar and flag.
|
|
|
|
"Archives/modified-argon-20230305.osk",
|
2023-06-16 16:26:30 +00:00
|
|
|
// Covers key counters
|
2023-08-06 10:15:14 +00:00
|
|
|
"Archives/modified-argon-pro-20230618.osk",
|
2023-10-01 12:12:24 +00:00
|
|
|
// Covers "Argon" health display
|
2023-10-26 08:04:55 +00:00
|
|
|
"Archives/modified-argon-pro-20231001.osk",
|
2023-11-06 07:51:31 +00:00
|
|
|
// Covers player name text component.
|
|
|
|
"Archives/modified-argon-20231106.osk",
|
2023-11-04 23:01:26 +00:00
|
|
|
// Covers "Argon" accuracy/score/combo counters, and wedges
|
2023-11-07 23:12:37 +00:00
|
|
|
"Archives/modified-argon-20231108.osk",
|
2024-03-05 01:30:57 +00:00
|
|
|
// Covers "Argon" performance points counter
|
|
|
|
"Archives/modified-argon-20240305.osk",
|
2023-08-09 00:33:50 +00:00
|
|
|
// Covers default rank display
|
|
|
|
"Archives/modified-default-20230809.osk",
|
|
|
|
// Covers legacy rank display
|
2024-07-24 04:18:05 +00:00
|
|
|
"Archives/modified-classic-20230809.osk",
|
2024-07-24 06:13:45 +00:00
|
|
|
// Covers legacy key counter
|
2024-07-24 04:18:05 +00:00
|
|
|
"Archives/modified-classic-20240724.osk"
|
2022-08-01 05:04:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// If this test fails, new test resources should be added to include new components.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestSkinnableComponentsCoveredByDeserialisationTests()
|
|
|
|
{
|
|
|
|
HashSet<Type> instantiatedTypes = new HashSet<Type>();
|
|
|
|
|
|
|
|
foreach (string oskFile in available_skins)
|
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource(oskFile))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
|
|
|
|
2023-02-16 10:58:04 +00:00
|
|
|
foreach (var target in skin.LayoutInfos)
|
2022-08-01 05:04:06 +00:00
|
|
|
{
|
2023-02-17 07:22:41 +00:00
|
|
|
foreach (var info in target.Value.AllDrawables)
|
2022-08-01 05:04:06 +00:00
|
|
|
instantiatedTypes.Add(info.Type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 07:01:26 +00:00
|
|
|
var editableTypes = SerialisedDrawableInfo.GetAllAvailableDrawables().Where(t => (Activator.CreateInstance(t) as ISerialisableDrawable)?.IsEditable == true);
|
2022-08-01 05:16:26 +00:00
|
|
|
|
|
|
|
Assert.That(instantiatedTypes, Is.EquivalentTo(editableTypes));
|
2022-08-01 05:04:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-31 14:42:18 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseModifiedDefault()
|
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource("Archives/modified-default-20220723.osk"))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
|
|
|
|
2023-02-16 10:58:04 +00:00
|
|
|
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
|
2024-08-22 09:45:44 +00:00
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(9));
|
2022-07-31 14:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-15 05:07:51 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseModifiedArgon()
|
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource("Archives/modified-argon-20231106.osk"))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
|
|
|
|
|
|
|
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
|
2024-08-22 09:45:44 +00:00
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(10));
|
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(PlayerName)));
|
2023-11-15 05:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-23 11:44:35 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseInvalidDrawables()
|
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource("Archives/argon-invalid-drawable.osk"))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
|
|
|
|
|
|
|
Assert.That(skin.LayoutInfos.Any(kvp => kvp.Value.AllDrawables.Any(d => d.Type == typeof(StarFountain))), Is.False);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 14:42:18 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDeserialiseModifiedClassic()
|
|
|
|
{
|
|
|
|
using (var stream = TestResources.OpenResource("Archives/modified-classic-20220723.osk"))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
|
|
|
|
2023-02-16 10:58:04 +00:00
|
|
|
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
|
2024-08-22 09:45:44 +00:00
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(6));
|
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.SongSelect].AllDrawables.ToArray(), Has.Length.EqualTo(1));
|
2022-07-31 14:42:18 +00:00
|
|
|
|
2024-08-22 09:45:44 +00:00
|
|
|
var skinnableInfo = skin.LayoutInfos[GlobalSkinnableContainers.SongSelect].AllDrawables.First();
|
2022-07-31 14:42:18 +00:00
|
|
|
|
|
|
|
Assert.That(skinnableInfo.Type, Is.EqualTo(typeof(SkinnableSprite)));
|
|
|
|
Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name"));
|
|
|
|
Assert.That(skinnableInfo.Settings.First().Value, Is.EqualTo("ppy_logo-2.png"));
|
|
|
|
}
|
2022-08-01 05:16:26 +00:00
|
|
|
|
|
|
|
using (var stream = TestResources.OpenResource("Archives/modified-classic-20220801.osk"))
|
|
|
|
using (var storage = new ZipArchiveReader(stream))
|
|
|
|
{
|
|
|
|
var skin = new TestSkin(new SkinInfo(), null, storage);
|
2024-08-22 09:45:44 +00:00
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(8));
|
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
|
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
|
|
|
|
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
|
2022-08-01 05:16:26 +00:00
|
|
|
}
|
2022-07-31 14:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSkin : Skin
|
|
|
|
{
|
2023-11-16 11:16:23 +00:00
|
|
|
public TestSkin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? fallbackStore = null, string configurationFilename = "skin.ini")
|
|
|
|
: base(skin, resources, fallbackStore, configurationFilename)
|
2022-07-31 14:42:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public override ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|