// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using System; using System.Collections.Generic; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Utils; using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Scoring; using osu.Game.Skinning; using osuTK.Graphics; namespace osu.Game.Rulesets.Mania.Skinning.Legacy { public class ManiaLegacySkinTransformer : LegacySkinTransformer { /// /// Mapping of to their corresponding /// value. /// private static readonly IReadOnlyDictionary hit_result_mapping = new Dictionary { { HitResult.Perfect, LegacyManiaSkinConfigurationLookups.Hit300g }, { HitResult.Great, LegacyManiaSkinConfigurationLookups.Hit300 }, { HitResult.Good, LegacyManiaSkinConfigurationLookups.Hit200 }, { HitResult.Ok, LegacyManiaSkinConfigurationLookups.Hit100 }, { HitResult.Meh, LegacyManiaSkinConfigurationLookups.Hit50 }, { HitResult.Miss, LegacyManiaSkinConfigurationLookups.Hit0 } }; /// /// Mapping of to their corresponding /// default filenames. /// private static readonly IReadOnlyDictionary default_hit_result_skin_filenames = new Dictionary { { 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 isLegacySkin; /// /// Whether texture for the keys exists. /// Used to determine if the mania ruleset is skinned. /// private readonly Lazy hasKeyTexture; private readonly ManiaBeatmap beatmap; public ManiaLegacySkinTransformer(ISkin skin, IBeatmap beatmap) : base(skin) { this.beatmap = (ManiaBeatmap)beatmap; isLegacySkin = new Lazy(() => GetConfig(SkinConfiguration.LegacySetting.Version) != null); hasKeyTexture = new Lazy(() => { string keyImage = this.GetManiaSkinConfig(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value ?? "mania-key1"; return this.GetAnimation(keyImage, true, true) != null; }); } public override Drawable GetDrawableComponent(ISkinComponent component) { switch (component) { case GameplaySkinComponent resultComponent: return getResult(resultComponent.Component); case ManiaSkinComponent maniaComponent: if (!isLegacySkin.Value || !hasKeyTexture.Value) return null; switch (maniaComponent.Component) { case ManiaSkinComponents.ColumnBackground: return new LegacyColumnBackground(); 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(); case ManiaSkinComponents.KeyArea: return new LegacyKeyArea(); case ManiaSkinComponents.Note: return new LegacyNotePiece(); case ManiaSkinComponents.HoldNoteHead: return new LegacyHoldNoteHeadPiece(); case ManiaSkinComponents.HoldNoteTail: return new LegacyHoldNoteTailPiece(); case ManiaSkinComponents.HoldNoteBody: return new LegacyBodyPiece(); case ManiaSkinComponents.HitExplosion: return new LegacyHitExplosion(); case ManiaSkinComponents.StageBackground: return new LegacyStageBackground(); case ManiaSkinComponents.StageForeground: return new LegacyStageForeground(); default: throw new UnsupportedSkinComponentException(component); } } return base.GetDrawableComponent(component); } private Drawable getResult(HitResult result) { if (!hit_result_mapping.ContainsKey(result)) return null; string filename = this.GetManiaSkinConfig(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) { // layered hit sounds never play in mania if (sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample && legacySample.IsLayered) return new SampleVirtual(); return base.GetSample(sampleInfo); } public override IBindable GetConfig(TLookup lookup) { if (lookup is ManiaSkinConfigurationLookup maniaLookup) { var legacyLookup = base.GetConfig(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.ColumnIndex)); if (legacyLookup != null) return legacyLookup; // default legacy fallback. switch (maniaLookup.Lookup) { case LegacyManiaSkinConfigurationLookups.ColumnBackgroundColour: return SkinUtils.As(new Bindable(Color4.Black)); } } return base.GetConfig(lookup); } } }