1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 19:03:08 +08:00

Add SetHitObjects() to IHitPolicy instead of using ctor

This commit is contained in:
smoogipoo 2021-02-05 14:09:25 +09:00
parent 08aae011c1
commit 8adf37d958
3 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// 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.
using System.Collections.Generic;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -8,6 +9,12 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public interface IHitPolicy public interface IHitPolicy
{ {
/// <summary>
/// Sets the <see cref="DrawableHitObject"/>s which this <see cref="IHitPolicy"/> controls.
/// </summary>
/// <param name="hitObjects">An enumeration of the <see cref="DrawableHitObject"/>s.</param>
void SetHitObjects(IEnumerable<DrawableHitObject> hitObjects);
/// <summary> /// <summary>
/// Determines whether a <see cref="DrawableHitObject"/> can be hit at a point in time. /// Determines whether a <see cref="DrawableHitObject"/> can be hit at a point in time.
/// </summary> /// </summary>

View File

@ -54,7 +54,8 @@ namespace osu.Game.Rulesets.Osu.UI
approachCircles = new ProxyContainer { RelativeSizeAxes = Axes.Both }, approachCircles = new ProxyContainer { RelativeSizeAxes = Axes.Both },
}; };
hitPolicy = new StartTimeOrderedHitPolicy(HitObjectContainer); hitPolicy = new StartTimeOrderedHitPolicy();
hitPolicy.SetHitObjects(HitObjectContainer.AliveObjects);
var hitWindows = new OsuHitWindows(); var hitWindows = new OsuHitWindows();

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
@ -20,12 +19,9 @@ namespace osu.Game.Rulesets.Osu.UI
/// </summary> /// </summary>
public class StartTimeOrderedHitPolicy : IHitPolicy public class StartTimeOrderedHitPolicy : IHitPolicy
{ {
private readonly HitObjectContainer hitObjectContainer; private IEnumerable<DrawableHitObject> hitObjects;
public StartTimeOrderedHitPolicy(HitObjectContainer hitObjectContainer) public void SetHitObjects(IEnumerable<DrawableHitObject> hitObjects) => this.hitObjects = hitObjects;
{
this.hitObjectContainer = hitObjectContainer;
}
public bool IsHittable(DrawableHitObject hitObject, double time) public bool IsHittable(DrawableHitObject hitObject, double time)
{ {
@ -77,7 +73,7 @@ namespace osu.Game.Rulesets.Osu.UI
private IEnumerable<DrawableHitObject> enumerateHitObjectsUpTo(double targetTime) private IEnumerable<DrawableHitObject> enumerateHitObjectsUpTo(double targetTime)
{ {
foreach (var obj in hitObjectContainer.AliveObjects) foreach (var obj in hitObjects)
{ {
if (obj.HitObject.StartTime >= targetTime) if (obj.HitObject.StartTime >= targetTime)
yield break; yield break;