Skip to content

Commit

Permalink
feat: Added realtime BPM
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Aug 25, 2024
1 parent 5650da6 commit da28dd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/tosu/src/api/types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export interface Hp {
}

export interface Bpm {
realtime: number;
common: number;
min: number;
max: number;
Expand Down
1 change: 1 addition & 0 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {
},

bpm: {
realtime: fixDecimals(beatmapPpData.realtimeBPM),
common: fixDecimals(beatmapPpData.commonBPM),
min: fixDecimals(beatmapPpData.minBPM),
max: fixDecimals(beatmapPpData.maxBPM)
Expand Down
14 changes: 14 additions & 0 deletions packages/tosu/src/entities/BeatmapPpData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class BeatmapPPData extends AbstractEntity {
beatmapContent?: string;
strains: number[];
strainsAll: BeatmapStrains;
realtimeBPM: number;
commonBPM: number;
minBPM: number;
maxBPM: number;
Expand Down Expand Up @@ -94,6 +95,7 @@ export class BeatmapPPData extends AbstractEntity {
xaxis: []
};
this.Mode = 0;
this.realtimeBPM = 0.0;
this.commonBPM = 0.0;
this.minBPM = 0.0;
this.maxBPM = 0.0;
Expand Down Expand Up @@ -563,4 +565,16 @@ export class BeatmapPPData extends AbstractEntity {
wLogger.debug(exc);
}
}

updateRealTimeBPM(timeMS: number) {
if (!this.lazerBeatmap) return;

this.realtimeBPM =
this.lazerBeatmap.controlPoints.timingPoints
// @ts-ignore
.toReversed()
.find((r) => r.startTime <= timeMS && r.bpm !== 0)?.bpm ||
this.lazerBeatmap.controlPoints.timingPoints[0]?.bpm ||
0.0;
}
}
2 changes: 2 additions & 0 deletions packages/tosu/src/objects/instanceManager/osuInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export class OsuInstance {
this.previousMP3Length = menuData.MP3Length;
}

beatmapPpData.updateRealTimeBPM(allTimesData.PlayTime);

switch (allTimesData.Status) {
case 0:
bassDensityData.updateState();
Expand Down

0 comments on commit da28dd6

Please sign in to comment.