2019-08-21 06:11:33 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-24 08:43:03 +00:00
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
2022-03-23 15:21:19 +00:00
#nullable enable
2020-04-01 14:32:33 +00:00
using System ;
2019-09-03 08:57:34 +00:00
using System.Collections.Generic ;
2020-04-01 04:38:03 +00:00
using System.Diagnostics ;
2018-03-05 12:27:37 +00:00
using System.IO ;
using System.Linq ;
2019-09-04 06:59:09 +00:00
using JetBrains.Annotations ;
2018-02-22 08:16:48 +00:00
using osu.Framework.Audio.Sample ;
2019-09-03 08:57:34 +00:00
using osu.Framework.Bindables ;
2018-02-22 08:16:48 +00:00
using osu.Framework.Graphics ;
2020-07-17 07:54:30 +00:00
using osu.Framework.Graphics.OpenGL.Textures ;
2018-02-22 08:16:48 +00:00
using osu.Framework.Graphics.Textures ;
using osu.Framework.IO.Stores ;
2019-08-23 11:32:43 +00:00
using osu.Game.Audio ;
2020-04-02 08:56:12 +00:00
using osu.Game.Beatmaps.Formats ;
2022-03-23 04:14:56 +00:00
using osu.Game.Database ;
2019-09-09 22:43:30 +00:00
using osu.Game.IO ;
2021-05-05 04:12:17 +00:00
using osu.Game.Rulesets.Objects.Types ;
2019-08-30 06:12:03 +00:00
using osu.Game.Rulesets.Scoring ;
2021-05-17 09:26:15 +00:00
using osu.Game.Screens.Play ;
2020-10-14 08:21:56 +00:00
using osu.Game.Screens.Play.HUD ;
2021-05-18 06:50:40 +00:00
using osu.Game.Screens.Play.HUD.HitErrorMeters ;
2019-07-30 14:06:18 +00:00
using osuTK.Graphics ;
2018-04-13 09:19:50 +00:00
2018-02-22 08:16:48 +00:00
namespace osu.Game.Skinning
{
public class LegacySkin : Skin
{
2020-04-01 14:32:33 +00:00
/// <summary>
/// Whether texture for the keys exists.
/// Used to determine if the mania ruleset is skinned.
/// </summary>
private readonly Lazy < bool > hasKeyTexture ;
protected virtual bool AllowManiaSkin = > hasKeyTexture . Value ;
2020-03-31 01:14:36 +00:00
2020-07-28 21:52:09 +00:00
/// <summary>
/// Whether this skin can use samples with a custom bank (custom sample set in stable terminology).
/// Added in order to match sample lookup logic from stable (in stable, only the beatmap skin could use samples with a custom sample bank).
/// </summary>
protected virtual bool UseCustomSampleBanks = > false ;
2020-03-31 01:14:36 +00:00
private readonly Dictionary < int , LegacyManiaSkinConfiguration > maniaConfigurations = new Dictionary < int , LegacyManiaSkinConfiguration > ( ) ;
2021-05-12 20:18:15 +00:00
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
2020-12-21 06:14:32 +00:00
public LegacySkin ( SkinInfo skin , IStorageResourceProvider resources )
2022-03-23 06:05:01 +00:00
: this ( skin , resources , null )
2018-02-22 08:16:48 +00:00
{
2018-03-22 03:50:23 +00:00
}
2018-04-13 09:19:50 +00:00
2021-05-31 06:13:56 +00:00
/// <summary>
/// Construct a new legacy skin instance.
/// </summary>
/// <param name="skin">The model for this skin.</param>
/// <param name="resources">Access to raw game resources.</param>
2022-03-23 06:02:01 +00:00
/// <param name="storage">An optional store which will be used for looking up skin resources. If null, one will be created from realm <see cref="IHasRealmFiles"/> pattern.</param>
2021-05-31 06:13:56 +00:00
/// <param name="configurationFilename">The user-facing filename of the configuration file to be parsed. Can accept an .osu or skin.ini file.</param>
2022-03-23 15:21:19 +00:00
protected LegacySkin ( SkinInfo skin , IStorageResourceProvider ? resources , IResourceStore < byte [ ] > ? storage , string configurationFilename = @"skin.ini" )
2022-03-23 05:53:00 +00:00
: base ( skin , resources , storage , configurationFilename )
2018-03-22 03:50:23 +00:00
{
2020-04-01 14:32:33 +00:00
// todo: this shouldn't really be duplicated here (from ManiaLegacySkinTransformer). we need to come up with a better solution.
hasKeyTexture = new Lazy < bool > ( ( ) = > this . GetAnimation (
2020-04-07 07:53:29 +00:00
lookupForMania < string > ( new LegacyManiaSkinConfigurationLookup ( 4 , LegacyManiaSkinConfigurationLookups . KeyImage , 0 ) ) ? . Value ? ? "mania-key1" , true ,
true ) ! = null ) ;
2018-03-14 11:45:04 +00:00
}
2018-04-13 09:19:50 +00:00
2021-10-22 05:41:59 +00:00
protected override void ParseConfigurationStream ( Stream stream )
{
base . ParseConfigurationStream ( stream ) ;
stream . Seek ( 0 , SeekOrigin . Begin ) ;
using ( LineBufferedReader reader = new LineBufferedReader ( stream ) )
{
var maniaList = new LegacyManiaSkinDecoder ( ) . Decode ( reader ) ;
foreach ( var config in maniaList )
maniaConfigurations [ config . Keys ] = config ;
}
}
2022-03-23 15:21:19 +00:00
public override IBindable < TValue > ? GetConfig < TLookup , TValue > ( TLookup lookup )
2019-09-03 08:57:34 +00:00
{
switch ( lookup )
{
2020-02-07 05:58:07 +00:00
case GlobalSkinColours colour :
switch ( colour )
2019-09-03 08:57:34 +00:00
{
2020-02-07 05:58:07 +00:00
case GlobalSkinColours . ComboColours :
2019-11-06 20:20:36 +00:00
var comboColours = Configuration . ComboColours ;
if ( comboColours ! = null )
2019-11-07 12:54:30 +00:00
return SkinUtils . As < TValue > ( new Bindable < IReadOnlyList < Color4 > > ( comboColours ) ) ;
2019-10-09 18:08:07 +00:00
break ;
2020-02-07 05:58:07 +00:00
default :
2020-04-02 08:56:12 +00:00
return SkinUtils . As < TValue > ( getCustomColour ( Configuration , colour . ToString ( ) ) ) ;
2019-09-03 08:57:34 +00:00
}
break ;
2021-05-05 04:12:17 +00:00
case SkinComboColourLookup comboColour :
return SkinUtils . As < TValue > ( GetComboColour ( Configuration , comboColour . ColourIndex , comboColour . Combo ) ) ;
2019-09-03 08:57:34 +00:00
case SkinCustomColourLookup customColour :
2020-04-02 08:56:12 +00:00
return SkinUtils . As < TValue > ( getCustomColour ( Configuration , customColour . Lookup . ToString ( ) ) ) ;
2019-09-03 08:57:34 +00:00
2020-03-31 09:22:46 +00:00
case LegacyManiaSkinConfigurationLookup maniaLookup :
2020-03-31 01:14:36 +00:00
if ( ! AllowManiaSkin )
2021-05-31 06:27:14 +00:00
break ;
2020-03-31 01:14:36 +00:00
2020-04-01 14:46:50 +00:00
var result = lookupForMania < TValue > ( maniaLookup ) ;
if ( result ! = null )
return result ;
2020-03-31 01:14:36 +00:00
break ;
2021-10-22 05:41:59 +00:00
case SkinConfiguration . LegacySetting legacy :
2020-08-02 17:50:17 +00:00
return legacySettingLookup < TValue > ( legacy ) ;
2020-07-29 07:34:09 +00:00
2019-09-03 08:57:34 +00:00
default :
2020-08-02 17:46:29 +00:00
return genericLookup < TLookup , TValue > ( lookup ) ;
2019-09-03 08:57:34 +00:00
}
return null ;
}
2022-03-23 15:21:19 +00:00
private IBindable < TValue > ? lookupForMania < TValue > ( LegacyManiaSkinConfigurationLookup maniaLookup )
2020-04-01 14:46:50 +00:00
{
if ( ! maniaConfigurations . TryGetValue ( maniaLookup . Keys , out var existing ) )
maniaConfigurations [ maniaLookup . Keys ] = existing = new LegacyManiaSkinConfiguration ( maniaLookup . Keys ) ;
switch ( maniaLookup . Lookup )
{
case LegacyManiaSkinConfigurationLookups . ColumnWidth :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnWidth [ maniaLookup . TargetColumn . Value ] ) ) ;
case LegacyManiaSkinConfigurationLookups . ColumnSpacing :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnSpacing [ maniaLookup . TargetColumn . Value ] ) ) ;
case LegacyManiaSkinConfigurationLookups . HitPosition :
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . HitPosition ) ) ;
2020-12-13 16:00:46 +00:00
case LegacyManiaSkinConfigurationLookups . ScorePosition :
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ScorePosition ) ) ;
2020-04-01 14:46:50 +00:00
case LegacyManiaSkinConfigurationLookups . LightPosition :
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . LightPosition ) ) ;
case LegacyManiaSkinConfigurationLookups . ShowJudgementLine :
return SkinUtils . As < TValue > ( new Bindable < bool > ( existing . ShowJudgementLine ) ) ;
2020-04-02 05:29:16 +00:00
2020-08-25 06:35:37 +00:00
case LegacyManiaSkinConfigurationLookups . ExplosionImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "LightingN" ) ) ;
2020-04-02 05:29:16 +00:00
case LegacyManiaSkinConfigurationLookups . ExplosionScale :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
2021-10-22 05:41:59 +00:00
if ( GetConfig < SkinConfiguration . LegacySetting , decimal > ( SkinConfiguration . LegacySetting . Version ) ? . Value < 2.5 m )
2020-04-02 05:29:16 +00:00
return SkinUtils . As < TValue > ( new Bindable < float > ( 1 ) ) ;
if ( existing . ExplosionWidth [ maniaLookup . TargetColumn . Value ] ! = 0 )
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ExplosionWidth [ maniaLookup . TargetColumn . Value ] / LegacyManiaSkinConfiguration . DEFAULT_COLUMN_SIZE ) ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnWidth [ maniaLookup . TargetColumn . Value ] / LegacyManiaSkinConfiguration . DEFAULT_COLUMN_SIZE ) ) ;
2020-04-02 14:57:03 +00:00
2020-04-02 09:10:17 +00:00
case LegacyManiaSkinConfigurationLookups . ColumnLineColour :
return SkinUtils . As < TValue > ( getCustomColour ( existing , "ColourColumnLine" ) ) ;
2020-04-07 07:50:08 +00:00
case LegacyManiaSkinConfigurationLookups . JudgementLineColour :
return SkinUtils . As < TValue > ( getCustomColour ( existing , "ColourJudgementLine" ) ) ;
2020-04-07 07:53:29 +00:00
case LegacyManiaSkinConfigurationLookups . ColumnBackgroundColour :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
2020-04-07 08:11:32 +00:00
return SkinUtils . As < TValue > ( getCustomColour ( existing , $"Colour{maniaLookup.TargetColumn + 1}" ) ) ;
2020-04-07 07:53:29 +00:00
case LegacyManiaSkinConfigurationLookups . ColumnLightColour :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
2020-04-07 08:11:32 +00:00
return SkinUtils . As < TValue > ( getCustomColour ( existing , $"ColourLight{maniaLookup.TargetColumn + 1}" ) ) ;
2020-04-07 14:36:42 +00:00
2020-04-07 07:07:18 +00:00
case LegacyManiaSkinConfigurationLookups . MinimumColumnWidth :
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . MinimumColumnWidth ) ) ;
2020-04-07 13:41:22 +00:00
2020-04-06 10:04:02 +00:00
case LegacyManiaSkinConfigurationLookups . NoteImage :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"NoteImage{maniaLookup.TargetColumn}" ) ) ;
case LegacyManiaSkinConfigurationLookups . HoldNoteHeadImage :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"NoteImage{maniaLookup.TargetColumn}H" ) ) ;
case LegacyManiaSkinConfigurationLookups . HoldNoteTailImage :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"NoteImage{maniaLookup.TargetColumn}T" ) ) ;
case LegacyManiaSkinConfigurationLookups . HoldNoteBodyImage :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"NoteImage{maniaLookup.TargetColumn}L" ) ) ;
2020-08-26 11:21:41 +00:00
case LegacyManiaSkinConfigurationLookups . HoldNoteLightImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "LightingL" ) ) ;
case LegacyManiaSkinConfigurationLookups . HoldNoteLightScale :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
2021-10-22 05:41:59 +00:00
if ( GetConfig < SkinConfiguration . LegacySetting , decimal > ( SkinConfiguration . LegacySetting . Version ) ? . Value < 2.5 m )
2020-08-26 11:21:41 +00:00
return SkinUtils . As < TValue > ( new Bindable < float > ( 1 ) ) ;
if ( existing . HoldNoteLightWidth [ maniaLookup . TargetColumn . Value ] ! = 0 )
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . HoldNoteLightWidth [ maniaLookup . TargetColumn . Value ] / LegacyManiaSkinConfiguration . DEFAULT_COLUMN_SIZE ) ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnWidth [ maniaLookup . TargetColumn . Value ] / LegacyManiaSkinConfiguration . DEFAULT_COLUMN_SIZE ) ) ;
2020-04-06 10:04:02 +00:00
case LegacyManiaSkinConfigurationLookups . KeyImage :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"KeyImage{maniaLookup.TargetColumn}" ) ) ;
case LegacyManiaSkinConfigurationLookups . KeyImageDown :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( getManiaImage ( existing , $"KeyImage{maniaLookup.TargetColumn}D" ) ) ;
2020-04-08 06:36:07 +00:00
case LegacyManiaSkinConfigurationLookups . LeftStageImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "StageLeft" ) ) ;
case LegacyManiaSkinConfigurationLookups . RightStageImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "StageRight" ) ) ;
2020-04-21 08:14:04 +00:00
2020-07-05 05:02:50 +00:00
case LegacyManiaSkinConfigurationLookups . BottomStageImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "StageBottom" ) ) ;
case LegacyManiaSkinConfigurationLookups . LightImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "StageLight" ) ) ;
case LegacyManiaSkinConfigurationLookups . HitTargetImage :
return SkinUtils . As < TValue > ( getManiaImage ( existing , "StageHint" ) ) ;
2020-04-21 08:14:04 +00:00
case LegacyManiaSkinConfigurationLookups . LeftLineWidth :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnLineWidth [ maniaLookup . TargetColumn . Value ] ) ) ;
case LegacyManiaSkinConfigurationLookups . RightLineWidth :
Debug . Assert ( maniaLookup . TargetColumn ! = null ) ;
return SkinUtils . As < TValue > ( new Bindable < float > ( existing . ColumnLineWidth [ maniaLookup . TargetColumn . Value + 1 ] ) ) ;
2020-06-12 13:22:22 +00:00
case LegacyManiaSkinConfigurationLookups . Hit0 :
case LegacyManiaSkinConfigurationLookups . Hit50 :
case LegacyManiaSkinConfigurationLookups . Hit100 :
case LegacyManiaSkinConfigurationLookups . Hit200 :
case LegacyManiaSkinConfigurationLookups . Hit300 :
case LegacyManiaSkinConfigurationLookups . Hit300g :
2020-06-13 12:19:06 +00:00
return SkinUtils . As < TValue > ( getManiaImage ( existing , maniaLookup . Lookup . ToString ( ) ) ) ;
2020-08-26 06:37:16 +00:00
case LegacyManiaSkinConfigurationLookups . KeysUnderNotes :
return SkinUtils . As < TValue > ( new Bindable < bool > ( existing . KeysUnderNotes ) ) ;
2020-04-01 14:46:50 +00:00
}
return null ;
}
2021-05-05 04:12:17 +00:00
/// <summary>
/// Retrieves the correct combo colour for a given colour index and information on the combo.
/// </summary>
/// <param name="source">The source to retrieve the combo colours from.</param>
/// <param name="colourIndex">The preferred index for retrieving the combo colour with.</param>
/// <param name="combo">Information on the combo whose using the returned colour.</param>
2022-03-23 15:21:19 +00:00
protected virtual IBindable < Color4 > ? GetComboColour ( IHasComboColours source , int colourIndex , IHasComboInformation combo )
2021-05-05 04:12:17 +00:00
{
var colour = source . ComboColours ? [ colourIndex % source . ComboColours . Count ] ;
return colour . HasValue ? new Bindable < Color4 > ( colour . Value ) : null ;
}
2022-03-23 15:21:19 +00:00
private IBindable < Color4 > ? getCustomColour ( IHasCustomColours source , string lookup )
2020-04-02 08:56:12 +00:00
= > source . CustomColours . TryGetValue ( lookup , out var col ) ? new Bindable < Color4 > ( col ) : null ;
2019-09-03 08:57:34 +00:00
2022-03-23 15:21:19 +00:00
private IBindable < string > ? getManiaImage ( LegacyManiaSkinConfiguration source , string lookup )
2021-10-27 04:04:41 +00:00
= > source . ImageLookups . TryGetValue ( lookup , out string image ) ? new Bindable < string > ( image ) : null ;
2020-04-06 10:04:02 +00:00
2022-03-23 15:21:19 +00:00
private IBindable < TValue > ? legacySettingLookup < TValue > ( SkinConfiguration . LegacySetting legacySetting )
2022-03-25 06:53:55 +00:00
where TValue : notnull
2020-08-02 17:50:17 +00:00
{
switch ( legacySetting )
{
2021-10-22 05:41:59 +00:00
case SkinConfiguration . LegacySetting . Version :
return SkinUtils . As < TValue > ( new Bindable < decimal > ( Configuration . LegacyVersion ? ? SkinConfiguration . LATEST_VERSION ) ) ;
2020-08-02 17:50:17 +00:00
default :
2021-10-22 05:41:59 +00:00
return genericLookup < SkinConfiguration . LegacySetting , TValue > ( legacySetting ) ;
2020-08-02 17:50:17 +00:00
}
}
2022-03-23 15:21:19 +00:00
private IBindable < TValue > ? genericLookup < TLookup , TValue > ( TLookup lookup )
2022-03-25 06:53:55 +00:00
where TLookup : notnull
where TValue : notnull
2020-08-02 17:46:29 +00:00
{
try
{
2021-10-27 04:04:41 +00:00
if ( Configuration . ConfigDictionary . TryGetValue ( lookup . ToString ( ) , out string val ) )
2020-08-02 17:46:29 +00:00
{
// special case for handling skins which use 1 or 0 to signify a boolean state.
2022-06-06 10:43:08 +00:00
// ..or in some cases 2 (https://github.com/ppy/osu/issues/18579).
2020-08-02 17:46:29 +00:00
if ( typeof ( TValue ) = = typeof ( bool ) )
2022-06-06 10:43:08 +00:00
{
val = bool . TryParse ( val , out bool boolVal )
? Convert . ChangeType ( boolVal , typeof ( bool ) ) . ToString ( )
: Convert . ChangeType ( Convert . ToInt32 ( val ) , typeof ( bool ) ) . ToString ( ) ;
}
2020-08-02 17:46:29 +00:00
var bindable = new Bindable < TValue > ( ) ;
if ( val ! = null )
bindable . Parse ( val ) ;
return bindable ;
}
}
catch
{
}
return null ;
}
2022-03-23 15:21:19 +00:00
public override Drawable ? GetDrawableComponent ( ISkinComponent component )
2018-02-22 08:16:48 +00:00
{
2021-05-10 13:43:48 +00:00
if ( base . GetDrawableComponent ( component ) is Drawable c )
return c ;
2019-08-30 06:12:03 +00:00
switch ( component )
2018-03-12 02:30:13 +00:00
{
2021-05-10 13:43:48 +00:00
case SkinnableTargetComponent target :
switch ( target . Target )
2020-10-14 08:21:56 +00:00
{
2021-05-10 13:43:48 +00:00
case SkinnableTarget . MainHUDComponents :
2021-05-13 09:51:23 +00:00
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer ( container = >
2021-05-11 04:12:24 +00:00
{
var score = container . OfType < LegacyScoreCounter > ( ) . FirstOrDefault ( ) ;
var accuracy = container . OfType < GameplayAccuracyCounter > ( ) . FirstOrDefault ( ) ;
2021-05-23 07:46:32 +00:00
var combo = container . OfType < LegacyComboCounter > ( ) . FirstOrDefault ( ) ;
2021-05-11 04:12:24 +00:00
if ( score ! = null & & accuracy ! = null )
{
accuracy . Y = container . ToLocalSpace ( score . ScreenSpaceDrawQuad . BottomRight ) . Y ;
}
2021-05-18 06:50:40 +00:00
var songProgress = container . OfType < SongProgress > ( ) . FirstOrDefault ( ) ;
var hitError = container . OfType < HitErrorMeter > ( ) . FirstOrDefault ( ) ;
if ( hitError ! = null )
{
hitError . Anchor = Anchor . BottomCentre ;
hitError . Origin = Anchor . CentreLeft ;
hitError . Rotation = - 90 ;
2021-05-23 07:46:32 +00:00
}
2021-05-18 06:50:40 +00:00
2021-05-23 07:46:32 +00:00
if ( songProgress ! = null )
{
if ( hitError ! = null ) hitError . Y - = SongProgress . MAX_HEIGHT ;
if ( combo ! = null ) combo . Y - = SongProgress . MAX_HEIGHT ;
2021-05-18 06:50:40 +00:00
}
2021-05-11 04:12:24 +00:00
} )
2021-05-10 13:43:48 +00:00
{
2022-03-24 03:36:16 +00:00
Children = new Drawable [ ]
{
new LegacyComboCounter ( ) ,
new LegacyScoreCounter ( ) ,
new LegacyAccuracyCounter ( ) ,
new LegacyHealthDisplay ( ) ,
new SongProgress ( ) ,
new BarHitErrorMeter ( ) ,
}
2021-05-10 13:43:48 +00:00
} ;
2021-05-11 04:12:24 +00:00
return skinnableTargetWrapper ;
2020-10-14 08:21:56 +00:00
}
return null ;
2019-08-30 06:10:11 +00:00
case GameplaySkinComponent < HitResult > resultComponent :
2021-06-06 02:08:54 +00:00
// TODO: this should be inside the judgement pieces.
2022-03-23 15:21:19 +00:00
Func < Drawable ? > createDrawable = ( ) = > getJudgementAnimation ( resultComponent . Component ) ;
2020-11-18 06:38:26 +00:00
2020-11-18 08:15:45 +00:00
// kind of wasteful that we throw this away, but should do for now.
2020-11-18 06:38:26 +00:00
if ( createDrawable ( ) ! = null )
{
2021-01-15 05:51:26 +00:00
var particle = getParticleTexture ( resultComponent . Component ) ;
if ( particle ! = null )
return new LegacyJudgementPieceNew ( resultComponent . Component , createDrawable , particle ) ;
2020-11-18 06:38:26 +00:00
else
return new LegacyJudgementPieceOld ( resultComponent . Component , createDrawable ) ;
}
2019-04-01 03:16:05 +00:00
2022-04-22 21:35:45 +00:00
return null ;
2019-04-01 03:16:05 +00:00
2022-04-22 22:08:53 +00:00
case SkinnableSprite . SpriteComponent sprite :
return this . GetAnimation ( sprite . LookupName , false , false ) ;
2022-04-22 22:06:35 +00:00
default :
2022-04-22 22:08:53 +00:00
throw new UnsupportedSkinComponentException ( component ) ;
2022-04-22 22:06:35 +00:00
}
2020-11-17 06:44:15 +00:00
}
2019-04-01 03:16:05 +00:00
2022-03-23 15:21:19 +00:00
private Texture ? getParticleTexture ( HitResult result )
2020-11-18 06:38:26 +00:00
{
switch ( result )
{
case HitResult . Meh :
2020-11-19 06:47:02 +00:00
return GetTexture ( "particle50" ) ;
2020-11-18 06:38:26 +00:00
case HitResult . Ok :
2020-11-19 06:47:02 +00:00
return GetTexture ( "particle100" ) ;
2020-11-18 06:38:26 +00:00
case HitResult . Great :
2020-11-19 06:47:02 +00:00
return GetTexture ( "particle300" ) ;
2020-11-18 06:38:26 +00:00
}
return null ;
}
2022-03-23 15:21:19 +00:00
private Drawable ? getJudgementAnimation ( HitResult result )
2020-11-17 06:44:15 +00:00
{
switch ( result )
{
case HitResult . Miss :
return this . GetAnimation ( "hit0" , true , false ) ;
2019-08-30 06:12:03 +00:00
2020-11-17 06:44:15 +00:00
case HitResult . Meh :
return this . GetAnimation ( "hit50" , true , false ) ;
case HitResult . Ok :
return this . GetAnimation ( "hit100" , true , false ) ;
case HitResult . Great :
return this . GetAnimation ( "hit300" , true , false ) ;
2018-03-12 02:30:13 +00:00
}
2018-04-13 09:19:50 +00:00
2020-11-17 06:44:15 +00:00
return null ;
2019-08-19 10:23:54 +00:00
}
2022-03-23 15:21:19 +00:00
public override Texture ? GetTexture ( string componentName , WrapMode wrapModeS , WrapMode wrapModeT )
2019-08-27 08:18:32 +00:00
{
2021-10-27 04:04:41 +00:00
foreach ( string name in getFallbackNames ( componentName ) )
2020-04-06 10:02:50 +00:00
{
2022-01-16 18:44:04 +00:00
// some component names (especially user-controlled ones, like `HitX` in mania)
// may contain `@2x` scale specifications.
// stable happens to check for that and strip them, so do the same to match stable behaviour.
string lookupName = name . Replace ( @"@2x" , string . Empty ) ;
2020-04-06 10:02:50 +00:00
float ratio = 2 ;
2022-04-07 12:07:14 +00:00
string twoTimesFilename = $"{Path.ChangeExtension(lookupName, null)}@2x{Path.GetExtension(lookupName)}" ;
2022-04-07 05:16:16 +00:00
var texture = Textures ? . Get ( twoTimesFilename , wrapModeS , wrapModeT ) ;
2019-08-27 08:18:32 +00:00
2020-04-06 10:02:50 +00:00
if ( texture = = null )
{
ratio = 1 ;
2022-01-16 18:44:04 +00:00
texture = Textures ? . Get ( lookupName , wrapModeS , wrapModeT ) ;
2020-04-06 10:02:50 +00:00
}
2019-08-27 08:18:32 +00:00
2020-04-07 20:50:25 +00:00
if ( texture = = null )
continue ;
2019-08-27 08:18:32 +00:00
2020-04-07 20:50:25 +00:00
texture . ScaleAdjust = ratio ;
2020-04-06 10:02:50 +00:00
return texture ;
2019-08-27 08:18:32 +00:00
}
2020-04-06 10:02:50 +00:00
return null ;
2019-08-27 08:18:32 +00:00
}
2022-03-23 15:21:19 +00:00
public override ISample ? GetSample ( ISampleInfo sampleInfo )
2019-08-22 09:50:47 +00:00
{
2020-10-30 03:28:40 +00:00
IEnumerable < string > lookupNames ;
2020-07-28 21:52:09 +00:00
if ( sampleInfo is HitSampleInfo hitSample )
lookupNames = getLegacyLookupNames ( hitSample ) ;
2020-10-30 02:14:08 +00:00
else
{
lookupNames = sampleInfo . LookupNames . SelectMany ( getFallbackNames ) ;
}
2020-07-28 21:52:09 +00:00
2021-10-27 04:04:41 +00:00
foreach ( string lookup in lookupNames )
2019-08-22 09:50:47 +00:00
{
2020-01-02 05:07:22 +00:00
var sample = Samples ? . Get ( lookup ) ;
2019-08-23 11:32:43 +00:00
if ( sample ! = null )
2021-06-01 09:56:22 +00:00
{
2019-08-23 11:32:43 +00:00
return sample ;
2021-06-01 09:56:22 +00:00
}
2019-08-22 09:50:47 +00:00
}
2019-08-23 11:32:43 +00:00
return null ;
2019-08-22 09:50:47 +00:00
}
2019-08-27 08:18:32 +00:00
2020-07-28 21:52:09 +00:00
private IEnumerable < string > getLegacyLookupNames ( HitSampleInfo hitSample )
{
2020-10-30 02:14:08 +00:00
var lookupNames = hitSample . LookupNames . SelectMany ( getFallbackNames ) ;
2020-07-28 21:52:09 +00:00
if ( ! UseCustomSampleBanks & & ! string . IsNullOrEmpty ( hitSample . Suffix ) )
2020-10-30 02:14:08 +00:00
{
2020-07-28 21:52:09 +00:00
// for compatibility with stable, exclude the lookup names with the custom sample bank suffix, if they are not valid for use in this skin.
// using .EndsWith() is intentional as it ensures parity in all edge cases
// (see LegacyTaikoSampleInfo for an example of one - prioritising the taiko prefix should still apply, but the sample bank should not).
2020-10-30 13:33:05 +00:00
lookupNames = lookupNames . Where ( name = > ! name . EndsWith ( hitSample . Suffix , StringComparison . Ordinal ) ) ;
2020-10-30 02:14:08 +00:00
}
2020-07-28 21:52:09 +00:00
2021-10-27 04:04:41 +00:00
foreach ( string l in lookupNames )
2020-10-30 13:33:05 +00:00
yield return l ;
2020-07-30 20:07:07 +00:00
// also for compatibility, try falling back to non-bank samples (so-called "universal" samples) as the last resort.
// going forward specifying banks shall always be required, even for elements that wouldn't require it on stable,
// which is why this is done locally here.
2020-10-30 02:14:08 +00:00
yield return hitSample . Name ;
}
private IEnumerable < string > getFallbackNames ( string componentName )
{
// May be something like "Gameplay/osu/approachcircle" from lazer, or "Arrows/note1" from a user skin.
yield return componentName ;
2020-07-30 20:07:07 +00:00
2020-10-30 02:14:08 +00:00
// Fall back to using the last piece for components coming from lazer (e.g. "Gameplay/osu/approachcircle" -> "approachcircle").
2021-06-01 09:00:24 +00:00
yield return componentName . Split ( '/' ) . Last ( ) ;
2020-07-28 21:52:09 +00:00
}
2018-02-22 08:16:48 +00:00
}
}