1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 07:53:06 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs

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

160 lines
6.5 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
2020-06-22 04:44:35 +08:00
using osu.Framework.Audio.Sample;
2020-12-07 11:32:52 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2020-06-22 04:44:35 +08:00
using osu.Game.Audio;
2020-12-07 11:32:52 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
2020-06-22 04:44:35 +08:00
using osu.Game.Rulesets.Objects.Legacy;
2020-12-07 11:32:52 +08:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
2020-12-07 11:32:52 +08:00
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
{
2020-06-22 04:04:10 +08:00
public class ManiaLegacySkinTransformer : LegacySkinTransformer
{
private readonly ManiaBeatmap beatmap;
/// <summary>
2020-06-13 18:47:40 +08:00
/// Mapping of <see cref="HitResult"/> to their corresponding
/// <see cref="LegacyManiaSkinConfigurationLookups"/> value.
/// </summary>
private static readonly IReadOnlyDictionary<HitResult, LegacyManiaSkinConfigurationLookups> hit_result_mapping
= new Dictionary<HitResult, LegacyManiaSkinConfigurationLookups>
2020-06-13 11:31:34 +08:00
{
{ HitResult.Perfect, LegacyManiaSkinConfigurationLookups.Hit300g },
{ HitResult.Great, LegacyManiaSkinConfigurationLookups.Hit300 },
{ HitResult.Good, LegacyManiaSkinConfigurationLookups.Hit200 },
{ HitResult.Ok, LegacyManiaSkinConfigurationLookups.Hit100 },
{ HitResult.Meh, LegacyManiaSkinConfigurationLookups.Hit50 },
{ HitResult.Miss, LegacyManiaSkinConfigurationLookups.Hit0 }
};
/// <summary>
/// Mapping of <see cref="HitResult"/> to their corresponding
/// default filenames.
/// </summary>
private static readonly IReadOnlyDictionary<HitResult, string> default_hit_result_skin_filenames
= new Dictionary<HitResult, string>
2020-06-13 11:31:34 +08:00
{
{ HitResult.Perfect, "mania-hit300g" },
{ HitResult.Great, "mania-hit300" },
{ HitResult.Good, "mania-hit200" },
{ HitResult.Ok, "mania-hit100" },
{ HitResult.Meh, "mania-hit50" },
{ HitResult.Miss, "mania-hit0" }
};
private readonly Lazy<bool> isLegacySkin;
/// <summary>
/// Whether texture for the keys exists.
/// Used to determine if the mania ruleset is skinned.
/// </summary>
private readonly Lazy<bool> hasKeyTexture;
public ManiaLegacySkinTransformer(ISkin skin, IBeatmap beatmap)
: base(skin)
{
this.beatmap = (ManiaBeatmap)beatmap;
isLegacySkin = new Lazy<bool>(() => GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version) != null);
hasKeyTexture = new Lazy<bool>(() =>
{
string keyImage = this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value ?? "mania-key1";
return this.GetAnimation(keyImage, true, true) != null;
});
}
2020-06-22 04:04:10 +08:00
public override Drawable GetDrawableComponent(ISkinComponent component)
{
switch (component)
{
case GameplaySkinComponent<HitResult> resultComponent:
return getResult(resultComponent.Component);
2020-03-30 22:14:30 +08:00
case ManiaSkinComponent maniaComponent:
if (!isLegacySkin.Value || !hasKeyTexture.Value)
return null;
2020-03-30 22:14:30 +08:00
switch (maniaComponent.Component)
{
case ManiaSkinComponents.ColumnBackground:
return new LegacyColumnBackground();
2020-03-31 14:24:13 +08:00
2020-03-31 11:17:44 +08:00
case ManiaSkinComponents.HitTarget:
// Legacy skins sandwich the hit target between the column background and the column light.
// To preserve this ordering, it's created manually inside LegacyStageBackground.
return Drawable.Empty();
2020-03-31 14:24:13 +08:00
2020-03-31 10:23:33 +08:00
case ManiaSkinComponents.KeyArea:
return new LegacyKeyArea();
2020-03-31 14:29:25 +08:00
case ManiaSkinComponents.Note:
return new LegacyNotePiece();
case ManiaSkinComponents.HoldNoteHead:
return new LegacyHoldNoteHeadPiece();
case ManiaSkinComponents.HoldNoteTail:
return new LegacyHoldNoteTailPiece();
2020-03-31 15:42:35 +08:00
case ManiaSkinComponents.HoldNoteBody:
return new LegacyBodyPiece();
2020-04-02 13:29:16 +08:00
case ManiaSkinComponents.HitExplosion:
return new LegacyHitExplosion();
2020-04-08 14:08:13 +08:00
case ManiaSkinComponents.StageBackground:
Debug.Assert(maniaComponent.StageDefinition != null);
return new LegacyStageBackground(maniaComponent.StageDefinition.Value);
2020-04-08 15:20:26 +08:00
case ManiaSkinComponents.StageForeground:
return new LegacyStageForeground();
2020-03-30 22:14:30 +08:00
default:
throw new UnsupportedSkinComponentException(component);
}
2019-12-27 10:37:05 +08:00
}
return base.GetDrawableComponent(component);
2019-12-27 10:37:05 +08:00
}
private Drawable getResult(HitResult result)
2019-12-27 10:37:05 +08:00
{
if (!hit_result_mapping.ContainsKey(result))
2020-09-29 13:29:43 +08:00
return null;
string filename = this.GetManiaSkinConfig<string>(hit_result_mapping[result])?.Value
?? default_hit_result_skin_filenames[result];
var animation = this.GetAnimation(filename, true, true);
return animation == null ? null : new LegacyManiaJudgementPiece(result, animation);
}
public override ISample GetSample(ISampleInfo sampleInfo)
2020-06-22 04:44:35 +08:00
{
// layered hit sounds never play in mania
if (sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample && legacySample.IsLayered)
2021-01-19 16:11:40 +08:00
return new SampleVirtual();
2020-06-22 04:44:35 +08:00
return base.GetSample(sampleInfo);
2020-06-22 04:44:35 +08:00
}
2020-06-22 04:04:10 +08:00
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
return base.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
return base.GetConfig<TLookup, TValue>(lookup);
}
}
}