Skip to content

Commit 71b3d51

Browse files
author
Bartłomiej Dach
authored
Rewrite ranked play card song preview playback logic to hopefully work around framework breakage (ppy#37453)
Similar idea to ppy@622216d (which was included in ppy#37218). Probably closes ppy#37420. I wouldn't be myself if I didn't remark that the WTF/sec on ranked play code continues to be quite high as I fix these issues. Like, look at the old code: why does `Enabled` becoming false stop the preview track, but `CardHovered` becoming false *doesn't*? Even though `shouldBePlaying` was explicitly defined as derived from *both flags*? Maybe me changing this to be actually consistent incurs a behaviour change, but like... I can't tell if it is a bug or not. Not to mention this nugget: https://github.com/ppy/osu/blob/0e9664bfdfa69b4b26ff9cf84615c4b83a195a0e/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/HandOfCards.HandCard.cs#L107 https://github.com/ppy/osu/blob/0e9664bfdfa69b4b26ff9cf84615c4b83a195a0e/osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Card/RankedPlayCard.cs#L47-L50 What is this naming even?
1 parent 71356a9 commit 71b3d51

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Card/RankedPlayCard.SongPreview.cs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public partial class SongPreviewContainer : Container, IBeatSyncProvider
4545

4646
private readonly Container overlayLayer;
4747

48-
private bool shouldBePlaying => Enabled.Value && CardHovered.Value;
49-
5048
[Resolved]
5149
private PreviewTrackManager previewTrackManager { get; set; } = null!;
5250

@@ -77,33 +75,6 @@ public SongPreviewContainer()
7775
];
7876
}
7977

80-
protected override void LoadComplete()
81-
{
82-
base.LoadComplete();
83-
84-
Enabled.BindValueChanged(enabled =>
85-
{
86-
if (!enabled.NewValue)
87-
{
88-
previewTrack?.Stop();
89-
return;
90-
}
91-
92-
if (shouldBePlaying)
93-
{
94-
startPreviewIfAvailable();
95-
}
96-
});
97-
98-
CardHovered.BindValueChanged(selected =>
99-
{
100-
if (selected.NewValue && shouldBePlaying)
101-
{
102-
startPreviewIfAvailable();
103-
}
104-
});
105-
}
106-
10778
private PreviewTrack? previewTrack;
10879

10980
public void LoadPreview(APIBeatmap beatmap)
@@ -126,13 +97,31 @@ public void LoadPreview(APIBeatmap beatmap)
12697
{
12798
TrackRunning = { BindTarget = trackRunning }
12899
});
129-
130-
if (shouldBePlaying)
131-
startPreviewIfAvailable();
132100
});
133101
}
134102

135-
private void startPreviewIfAvailable() => previewTrack?.Start();
103+
protected override void Update()
104+
{
105+
base.Update();
106+
107+
updatePlayingState();
108+
}
109+
110+
private void updatePlayingState()
111+
{
112+
if (previewTrack?.IsLoaded != true)
113+
return;
114+
115+
bool shouldBePlaying = Enabled.Value && CardHovered.Value;
116+
117+
if (shouldBePlaying == previewTrack.IsRunning)
118+
return;
119+
120+
if (shouldBePlaying)
121+
previewTrack.Start();
122+
else
123+
previewTrack.Stop();
124+
}
136125

137126
#region IBeatSyncProvider implementation
138127

0 commit comments

Comments
 (0)