osu/osu.Game.Rulesets.Mania/Skinning/ManiaLegacySkinTransformer.cs

137 lines
4.9 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.
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.Skinning
{
public class ManiaLegacySkinTransformer : ISkin
{
private readonly ISkin source;
private readonly ManiaBeatmap beatmap;
private Lazy<bool> isLegacySkin;
/// <summary>
/// Whether texture for the keys exists.
/// Used to determine if the mania ruleset is skinned.
/// </summary>
private Lazy<bool> hasKeyTexture;
public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap)
{
this.source = source;
this.beatmap = (ManiaBeatmap)beatmap;
source.SourceChanged += sourceChanged;
sourceChanged();
}
private void sourceChanged()
{
isLegacySkin = new Lazy<bool>(() => source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
2020-04-01 06:17:23 +00:00
hasKeyTexture = new Lazy<bool>(() => source.GetAnimation(
2020-04-06 10:03:37 +00:00
GetConfig<ManiaSkinConfigurationLookup, string>(
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.KeyImage, 0))?.Value
2020-04-01 09:19:11 +00:00
?? "mania-key1", true, true) != null);
}
public Drawable GetDrawableComponent(ISkinComponent component)
{
switch (component)
{
case GameplaySkinComponent<HitResult> resultComponent:
2019-12-27 02:37:05 +00:00
return getResult(resultComponent);
2020-03-30 14:14:30 +00:00
case ManiaSkinComponent maniaComponent:
if (!isLegacySkin.Value || !hasKeyTexture.Value)
return null;
2020-03-30 14:14:30 +00:00
switch (maniaComponent.Component)
{
case ManiaSkinComponents.ColumnBackground:
return new LegacyColumnBackground(maniaComponent.TargetColumn == beatmap.TotalColumns - 1);
2020-03-31 06:24:13 +00:00
2020-03-31 03:17:44 +00:00
case ManiaSkinComponents.HitTarget:
return new LegacyHitTarget();
2020-03-31 06:24:13 +00:00
2020-03-31 02:23:33 +00:00
case ManiaSkinComponents.KeyArea:
return new LegacyKeyArea();
2020-03-31 06:29:25 +00:00
case ManiaSkinComponents.Note:
return new LegacyNotePiece();
case ManiaSkinComponents.HoldNoteHead:
return new LegacyHoldNoteHeadPiece();
case ManiaSkinComponents.HoldNoteTail:
return new LegacyHoldNoteTailPiece();
2020-03-31 07:42:35 +00:00
case ManiaSkinComponents.HoldNoteBody:
return new LegacyBodyPiece();
2020-04-02 05:29:16 +00:00
case ManiaSkinComponents.HitExplosion:
return new LegacyHitExplosion();
2020-04-08 06:08:13 +00:00
case ManiaSkinComponents.StageBackground:
return new LegacyStageBackground();
2020-04-08 07:20:26 +00:00
case ManiaSkinComponents.StageForeground:
return new LegacyStageForeground();
2020-03-30 14:14:30 +00:00
}
break;
2019-12-27 02:37:05 +00:00
}
return null;
}
2019-12-27 02:37:05 +00:00
private Drawable getResult(GameplaySkinComponent<HitResult> resultComponent)
{
switch (resultComponent.Component)
{
case HitResult.Miss:
return this.GetAnimation("mania-hit0", true, true);
2019-12-27 02:37:05 +00:00
case HitResult.Meh:
return this.GetAnimation("mania-hit50", true, true);
2019-12-27 02:37:05 +00:00
case HitResult.Ok:
return this.GetAnimation("mania-hit100", true, true);
2019-12-27 02:37:05 +00:00
case HitResult.Good:
return this.GetAnimation("mania-hit200", true, true);
2019-12-27 02:37:05 +00:00
case HitResult.Great:
return this.GetAnimation("mania-hit300", true, true);
2019-12-27 02:37:05 +00:00
case HitResult.Perfect:
return this.GetAnimation("mania-hit300g", true, true);
}
return null;
}
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
return source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
return source.GetConfig<TLookup, TValue>(lookup);
}
}
}