mirror of
https://github.com/ppy/osu
synced 2025-01-12 17:19:38 +00:00
Add/use IHitObjectContainer interface instead of IEnumerables
This commit is contained in:
parent
64a2c7825e
commit
f4a31287bf
osu.Game.Rulesets.Osu/UI
osu.Game/Rulesets/UI
@ -1,19 +1,18 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.UI
|
||||
{
|
||||
public interface IHitPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the <see cref="DrawableHitObject"/>s which this <see cref="IHitPolicy"/> controls.
|
||||
/// The <see cref="IHitObjectContainer"/> containing the <see cref="DrawableHitObject"/>s which this <see cref="IHitPolicy"/> applies to.
|
||||
/// </summary>
|
||||
/// <param name="hitObjects">An enumeration of the <see cref="DrawableHitObject"/>s.</param>
|
||||
void SetHitObjects(IEnumerable<DrawableHitObject> hitObjects);
|
||||
IHitObjectContainer HitObjectContainer { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a <see cref="DrawableHitObject"/> can be hit at a point in time.
|
||||
|
@ -54,8 +54,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
approachCircles = new ProxyContainer { RelativeSizeAxes = Axes.Both },
|
||||
};
|
||||
|
||||
hitPolicy = new StartTimeOrderedHitPolicy();
|
||||
hitPolicy.SetHitObjects(HitObjectContainer.AliveObjects);
|
||||
hitPolicy = new StartTimeOrderedHitPolicy { HitObjectContainer = HitObjectContainer };
|
||||
|
||||
var hitWindows = new OsuHitWindows();
|
||||
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.UI
|
||||
{
|
||||
@ -19,9 +20,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
/// </summary>
|
||||
public class StartTimeOrderedHitPolicy : IHitPolicy
|
||||
{
|
||||
private IEnumerable<DrawableHitObject> hitObjects;
|
||||
|
||||
public void SetHitObjects(IEnumerable<DrawableHitObject> hitObjects) => this.hitObjects = hitObjects;
|
||||
public IHitObjectContainer HitObjectContainer { get; set; }
|
||||
|
||||
public bool IsHittable(DrawableHitObject hitObject, double time)
|
||||
{
|
||||
@ -73,7 +72,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
|
||||
private IEnumerable<DrawableHitObject> enumerateHitObjectsUpTo(double targetTime)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
foreach (var obj in HitObjectContainer.AliveObjects)
|
||||
{
|
||||
if (obj.HitObject.StartTime >= targetTime)
|
||||
yield break;
|
||||
|
@ -17,19 +17,10 @@ using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
public class HitObjectContainer : LifetimeManagementContainer
|
||||
public class HitObjectContainer : LifetimeManagementContainer, IHitObjectContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// All currently in-use <see cref="DrawableHitObject"/>s.
|
||||
/// </summary>
|
||||
public IEnumerable<DrawableHitObject> Objects => InternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
||||
|
||||
/// <summary>
|
||||
/// All currently in-use <see cref="DrawableHitObject"/>s that are alive.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If this <see cref="HitObjectContainer"/> uses pooled objects, this is equivalent to <see cref="Objects"/>.
|
||||
/// </remarks>
|
||||
public IEnumerable<DrawableHitObject> AliveObjects => AliveInternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
||||
|
||||
/// <summary>
|
||||
|
24
osu.Game/Rulesets/UI/IHitObjectContainer.cs
Normal file
24
osu.Game/Rulesets/UI/IHitObjectContainer.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
public interface IHitObjectContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// All currently in-use <see cref="DrawableHitObject"/>s.
|
||||
/// </summary>
|
||||
IEnumerable<DrawableHitObject> Objects { get; }
|
||||
|
||||
/// <summary>
|
||||
/// All currently in-use <see cref="DrawableHitObject"/>s that are alive.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If this <see cref="IHitObjectContainer"/> uses pooled objects, this is equivalent to <see cref="Objects"/>.
|
||||
/// </remarks>
|
||||
IEnumerable<DrawableHitObject> AliveObjects { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user