Skip to content

Commit

Permalink
add OsuModKeepInScope
Browse files Browse the repository at this point in the history
  • Loading branch information
cdwcgt committed Jul 7, 2024
1 parent 3f13848 commit f43688d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
66 changes: 66 additions & 0 deletions osu.Game.Rulesets.Osu/Mods/OsuModKeepInScope.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osuTK;

namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModKeepInScope : ModFailCondition, IUpdatableByPlayfield, IApplicableToPlayer, IApplicableToBeatmap
{
public override string Name => "Keep in Scope";
public override string Acronym => "KS";
public override ModType Type => ModType.Fun;
public override LocalisableString Description => "Don't move out screen";
public override double ScoreMultiplier => 1;
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(ModAutoplay), typeof(ModNoFail) };

private readonly IBindable<bool> isBreakTime = new Bindable<bool>();
private Vector2 playfieldPosition;
private Vector2 playfieldSize;

public void ApplyToPlayer(Player player)
{
isBreakTime.BindTo(player.IsBreakTime);
}

public void ApplyToBeatmap(IBeatmap beatmap)
{
float borderPadding = OsuHitObject.OBJECT_RADIUS * LegacyRulesetExtensions.CalculateScaleFromCircleSize(beatmap.Difficulty.CircleSize, true);
playfieldSize = OsuPlayfield.BASE_SIZE + new Vector2(borderPadding * 2);

// Relative to OsuCursor's Anchor
playfieldPosition = new Vector2(-borderPadding);
}

public void Update(Playfield playfield)
{
var cursorPos = playfield.Cursor.AsNonNull().ActiveCursor.DrawPosition;

if (!isBreakTime.Value && !isWithinBounds(cursorPos, playfieldPosition, playfieldSize))
TriggerFailure();
}

private static bool isWithinBounds(Vector2 point, Vector2 containerPosition, Vector2 containerSize)
{
return point.X >= containerPosition.X &&
point.X <= containerPosition.X + containerSize.X &&
point.Y >= containerPosition.Y &&
point.Y <= containerPosition.Y + containerSize.Y;
}

protected override bool FailCondition(HealthProcessor healthProcessor, JudgementResult result) => false;
}
}
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Osu/OsuRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
new OsuModFreezeFrame(),
new OsuModBubbles(),
new OsuModSynesthesia(),
new OsuModDepth()
new OsuModDepth(),
new OsuModKeepInScope()
};

case ModType.System:
Expand Down

0 comments on commit f43688d

Please sign in to comment.