Skip to content

Commit

Permalink
Add check for first control point
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Schürz committed Jan 6, 2025
1 parent 5d925d3 commit 89c1843
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/common/src/controlPoints/ControlPointInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ export class ControlPointInfo extends AbstractCrdt<ControlPointMutation> {
return this.controlPointLists.flatMap(list => list.filter(it => almostEquals(it.time, time, 1)));
}

override get childObjects(): AbstractCrdt[] {
override get childObjects(): AbstractCrdt<any>[] {
return this.allControlPoints;
}

get allControlPoints(): ControlPoint[] {
return this.controlPointLists.flatMap(it => it.items);
}
}
39 changes: 39 additions & 0 deletions packages/common/src/verifier/checks/timing/CheckFirstLine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { CheckMetadata } from '../../BeatmapCheck';
import type { Issue } from '../../Issue';
import type { VerifierBeatmap } from '../../VerifierBeatmap';
import { TimingPoint } from '../../../controlPoints/TimingPoint';
import { minBy } from '../../../utils/arrayUtils';
import { BeatmapCheck } from '../../BeatmapCheck';
import { IssueTemplate } from '../../template/IssueTemplate';

export class CheckFirstLine extends BeatmapCheck<any> {
override get metadata(): CheckMetadata {
return {
category: 'Timing',
message: 'First line toggles kiai or is inherited.',
author: 'Naxess',
};
}

override templates = {
inherited: new IssueTemplate('problem', '{0:timestamp} First timing line is inherited.', 'timestamp - ').withCause('The first timing line of a beatmap is inherited.'),
togglesKiai: new IssueTemplate('problem', '{0:timestamp} First timing line toggles kiai.', 'timestamp - ').withCause('The first timing line of a beatmap has kiai enabled.'),
noLines: new IssueTemplate('problem', 'There are no timing lines.').withCause('A beatmap has no timing lines.'),
};

override async * getIssues(beatmap: VerifierBeatmap<any>): AsyncGenerator<Issue, void, undefined> {
const firstTimingPoint = beatmap.controlPoints.timingPoints.first;
if (!firstTimingPoint) {
yield this.createIssue(this.templates.noLines, beatmap);
return;
}

const firstControlPoint = minBy(beatmap.controlPoints.allControlPoints, it => it.time);

if (!(firstControlPoint instanceof TimingPoint) && firstControlPoint.time < firstTimingPoint.time)
yield this.createIssue(this.templates.inherited, beatmap, firstControlPoint.time);

if (beatmap.controlPoints.effectPointAt(firstTimingPoint.time).kiaiMode)
yield this.createIssue(this.templates.togglesKiai, beatmap, firstControlPoint.time);
}
}

0 comments on commit 89c1843

Please sign in to comment.