From a027b44b076c0ae5cf3c01ed5039f661830cfa0d Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:04:20 +0300 Subject: [PATCH] fix: FIx graph offset on the maps with long sliders at the end --- .../tosu/src/entities/BeatmapPpData/index.ts | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/packages/tosu/src/entities/BeatmapPpData/index.ts b/packages/tosu/src/entities/BeatmapPpData/index.ts index 99349a3f..3cd979d2 100644 --- a/packages/tosu/src/entities/BeatmapPpData/index.ts +++ b/packages/tosu/src/entities/BeatmapPpData/index.ts @@ -200,8 +200,7 @@ export class BeatmapPPData extends AbstractEntity { const { menuData, allTimesData } = this.osuInstance.getServices([ 'menuData', - 'allTimesData', - 'beatmapPpData' + 'allTimesData' ]); const mapPath = path.join( @@ -322,11 +321,6 @@ export class BeatmapPPData extends AbstractEntity { return; } - const offset = strains.sectionLength; - const firstObj = this.timings.firstObj / attributes.clockRate; - const lastObj = this.timings.full / attributes.clockRate; - const mp3Length = menuData.MP3Length / attributes.clockRate; - const beatmapParseTime = performance.now(); wLogger.debug( `BPPD(updateMapMetadata) [${( @@ -334,10 +328,38 @@ export class BeatmapPPData extends AbstractEntity { ).toFixed(2)}ms] Spend on parsing beatmap` ); - const LEFT_OFFSET = Math.floor(firstObj / offset); + let strainsAmount = 0; + switch (strains.mode) { + case 0: + strainsAmount = strains.aim?.length || 0; + break; + + case 1: + strainsAmount = strains.color?.length || 0; + break; + + case 2: + strainsAmount = strains.movement?.length || 0; + break; + + case 3: + strainsAmount = strains.strains?.length || 0; + break; + } + + const sectionOffsetTime = strains.sectionLength; + const firstObjectTime = + this.timings.firstObj / attributes.clockRate; + const lastObjectTime = + firstObjectTime + strainsAmount * sectionOffsetTime; + const mp3LengthTime = menuData.MP3Length / attributes.clockRate; + + const LEFT_OFFSET = Math.floor(firstObjectTime / sectionOffsetTime); const RIGHT_OFFSET = - mp3Length >= lastObj - ? Math.ceil((mp3Length - lastObj) / offset) + mp3LengthTime >= lastObjectTime + ? Math.ceil( + (mp3LengthTime - lastObjectTime) / sectionOffsetTime + ) : 0; const updateWithOffset = ( @@ -410,19 +432,23 @@ export class BeatmapPPData extends AbstractEntity { ); for (let i = 0; i < LEFT_OFFSET; i++) { - resultStrains.xaxis.push(i * offset); + resultStrains.xaxis.push(i * sectionOffsetTime); } const total = resultStrains.series[0].data.length - LEFT_OFFSET - RIGHT_OFFSET; + let lastTime = 0; for (let i = 0; i < total; i++) { - resultStrains.xaxis.push(firstObj + i * offset); + lastTime = firstObjectTime + i * sectionOffsetTime; + resultStrains.xaxis.push(lastTime); } for (let i = 0; i < RIGHT_OFFSET; i++) { - resultStrains.xaxis.push(lastObj + i * offset); + resultStrains.xaxis.push( + lastObjectTime + i * sectionOffsetTime + ); } const endTime = performance.now();