1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Use hopefully safer implementation of anchoring judgements to objects

This commit is contained in:
Bartłomiej Dach 2024-05-29 11:11:43 +02:00
parent 22a2adb5e6
commit a6c776dac8
No known key found for this signature in database
3 changed files with 17 additions and 19 deletions

View File

@ -108,7 +108,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private partial class TestDrawableOsuJudgement : DrawableOsuJudgement private partial class TestDrawableOsuJudgement : DrawableOsuJudgement
{ {
public new SkinnableSprite Lighting => base.Lighting; public new SkinnableSprite Lighting => base.Lighting;
public new SkinnableDrawable JudgementBody => base.JudgementBody; public new SkinnableDrawable? JudgementBody => base.JudgementBody;
} }
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -14,10 +12,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
public partial class DrawableOsuJudgement : DrawableJudgement public partial class DrawableOsuJudgement : DrawableJudgement
{ {
internal SkinnableLighting Lighting { get; private set; } internal SkinnableLighting Lighting { get; private set; } = null!;
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } private OsuConfigManager config { get; set; } = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
@ -38,19 +36,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Lighting.ResetAnimation(); Lighting.ResetAnimation();
Lighting.SetColourFrom(JudgedObject, Result); Lighting.SetColourFrom(JudgedObject, Result);
if (JudgedObject is DrawableOsuHitObject osuObject)
{
Position = osuObject.ToSpaceOfOtherDrawable(osuObject.OriginPosition, Parent!);
Scale = new Vector2(osuObject.HitObject.Scale);
}
} }
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
if (JudgedObject is DrawableOsuHitObject osuObject && Parent != null && osuObject.HitObject != null) if (JudgedObject is DrawableOsuHitObject osuObject && JudgedObject.IsInUse)
{ {
Position = osuObject.ToSpaceOfOtherDrawable(osuObject.OriginPosition, Parent!); Position = osuObject.ToSpaceOfOtherDrawable(osuObject.OriginPosition, Parent!);
Scale = new Vector2(osuObject.HitObject.Scale); Scale = new Vector2(osuObject.HitObject.Scale);

View File

@ -1,11 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -24,13 +21,13 @@ namespace osu.Game.Rulesets.Judgements
{ {
private const float judgement_size = 128; private const float judgement_size = 128;
public JudgementResult Result { get; private set; } public JudgementResult? Result { get; private set; }
public DrawableHitObject JudgedObject { get; private set; } public DrawableHitObject? JudgedObject { get; private set; }
public override bool RemoveCompletedTransforms => false; public override bool RemoveCompletedTransforms => false;
protected SkinnableDrawable JudgementBody { get; private set; } protected SkinnableDrawable? JudgementBody { get; private set; }
private readonly Container aboveHitObjectsContent; private readonly Container aboveHitObjectsContent;
@ -97,12 +94,19 @@ namespace osu.Game.Rulesets.Judgements
/// </summary> /// </summary>
/// <param name="result">The applicable judgement.</param> /// <param name="result">The applicable judgement.</param>
/// <param name="judgedObject">The drawable object.</param> /// <param name="judgedObject">The drawable object.</param>
public void Apply([NotNull] JudgementResult result, [CanBeNull] DrawableHitObject judgedObject) public void Apply(JudgementResult result, DrawableHitObject? judgedObject)
{ {
Result = result; Result = result;
JudgedObject = judgedObject; JudgedObject = judgedObject;
} }
protected override void FreeAfterUse()
{
base.FreeAfterUse();
JudgedObject = null;
}
protected override void PrepareForUse() protected override void PrepareForUse()
{ {
base.PrepareForUse(); base.PrepareForUse();
@ -121,6 +125,8 @@ namespace osu.Game.Rulesets.Judgements
ApplyTransformsAt(double.MinValue, true); ApplyTransformsAt(double.MinValue, true);
ClearTransforms(true); ClearTransforms(true);
Debug.Assert(Result != null && JudgementBody != null);
LifetimeStart = Result.TimeAbsolute; LifetimeStart = Result.TimeAbsolute;
using (BeginAbsoluteSequence(Result.TimeAbsolute)) using (BeginAbsoluteSequence(Result.TimeAbsolute))