Skip to content

Commit

Permalink
fix: FIx graph offset on the maps with long sliders at the end
Browse files Browse the repository at this point in the history
cyperdark committed Jun 30, 2024
1 parent a9a4e0c commit a027b44
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions packages/tosu/src/entities/BeatmapPpData/index.ts
Original file line number Diff line number Diff line change
@@ -200,8 +200,7 @@ export class BeatmapPPData extends AbstractEntity {

const { menuData, allTimesData } = this.osuInstance.getServices([
'menuData',
'allTimesData',
'beatmapPpData'
'allTimesData'
]);

const mapPath = path.join(
@@ -322,22 +321,45 @@ 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) [${(
beatmapParseTime - calculationTime
).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();

0 comments on commit a027b44

Please sign in to comment.