Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relax mod replaying #36

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions libs/osu/core/src/gameplay/GameStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Slider } from "../hitobjects/Slider";
import { OsuAction, ReplayFrame } from "../replays/Replay";
import { MainHitObjectVerdict } from "./Verdicts";
import { HitCircle } from "../hitobjects/HitCircle";
import { RELAX_LENIENCY } from "../mods/Mods";

/**
* In the real osu game, the slider body will be evaluated at every game tick (?), which is something we can not do.
Expand Down Expand Up @@ -232,7 +233,8 @@ export class GameStateEvaluator {

handleAliveHitCircles() {
// There is only action if there is also a click in this frame ...
if (!this.hasFreshClickThisFrame) {
const hasRelax = this.beatmap.appliedMods.includes("RELAX");
if (!this.hasFreshClickThisFrame && !hasRelax) {
return;
}
const { noteLockStyle } = this.options;
Expand Down Expand Up @@ -271,7 +273,10 @@ export class GameStateEvaluator {
break;
}

// If this hitobject is too early for relax, then the other ones will be as well, so break.
const delta = currentTime - hitCircle.hitTime;
if (hasRelax && delta < -RELAX_LENIENCY) break;

let judged = false;
for (const verdict of ["GREAT", "OK", "MEH"] as const) {
if (isWithinHitWindow(this.hitWindows, delta, verdict)) {
Expand Down Expand Up @@ -315,7 +320,8 @@ export class GameStateEvaluator {

const headHitTime: number | undefined = this.headHitTime(slider.head.id);
const wasTracking: boolean = this.gameState.sliderBodyState.get(id)?.isTracking ?? false;
const isTracking = determineTracking(wasTracking, slider, cursorPosition, time, pressingSince, headHitTime);
const hasRelax = this.beatmap.appliedMods.includes("RELAX");
const isTracking = determineTracking(wasTracking, slider, cursorPosition, time, pressingSince, headHitTime, hasRelax);
this.gameState.sliderBodyState.set(id, { isTracking });
}
}
Expand Down Expand Up @@ -389,10 +395,11 @@ function determineTracking(
time: number,
pressingSince: PressingSinceTimings,
headHitTime?: number,
hasRelax?: boolean
): boolean {
const keyIsBeingPressed = pressingSince.findIndex((x) => x !== NOT_PRESSING) >= 0;
// Zeroth condition
if (!keyIsBeingPressed) return false;
if (!keyIsBeingPressed && !hasRelax) return false;

// First condition
if (time < slider.startTime || slider.endTime <= time) return false;
Expand Down
3 changes: 3 additions & 0 deletions libs/osu/core/src/mods/Mods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ export const ModSettings: Record<OsuClassicMod, ModSetting> = {
SPUN_OUT: { name: "Spun Out" },
SUDDEN_DEATH: { name: "Sudden Death" },
};

// How early before a hitobject's time Relax can hit. (in ms)
export const RELAX_LENIENCY = 12;