Skip to content

Commit

Permalink
fix: little json improvments (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
KotRikD authored Dec 20, 2023
1 parent f145a57 commit 78033e9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 53 deletions.
37 changes: 21 additions & 16 deletions packages/tosu/src/api/utils/buildResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataRepo } from '@/entities/DataRepoList';
import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/entities/GamePlayData/Leaderboard';
import { InstanceManager } from '@/objects/instanceManager/instanceManager';
import { OsuInstance } from '@/objects/instanceManager/osuInstance';
import { fixDecimals } from '@/utils/fixDecimals';
import { getOsuModsString } from '@/utils/osuMods';

import {
Expand Down Expand Up @@ -111,26 +112,28 @@ export const buildResult = (
difficulty: menuData.Difficulty
},
stats: {
AR: beatmapPpData.calculatedMapAttributes.ar,
CS: beatmapPpData.calculatedMapAttributes.cs,
OD: beatmapPpData.calculatedMapAttributes.od,
HP: beatmapPpData.calculatedMapAttributes.hp,
SR: beatmapPpData.currAttributes.stars,
AR: fixDecimals(beatmapPpData.calculatedMapAttributes.ar),
CS: fixDecimals(beatmapPpData.calculatedMapAttributes.cs),
OD: fixDecimals(beatmapPpData.calculatedMapAttributes.od),
HP: fixDecimals(beatmapPpData.calculatedMapAttributes.hp),
SR: fixDecimals(beatmapPpData.currAttributes.stars),
BPM: {
common: beatmapPpData.commonBPM,
min: beatmapPpData.minBPM,
max: beatmapPpData.maxBPM
common: fixDecimals(beatmapPpData.commonBPM),
min: fixDecimals(beatmapPpData.minBPM),
max: fixDecimals(beatmapPpData.maxBPM)
},
circles: beatmapPpData.calculatedMapAttributes.circles,
sliders: beatmapPpData.calculatedMapAttributes.sliders,
spinners: beatmapPpData.calculatedMapAttributes.spinners,
holds: beatmapPpData.calculatedMapAttributes.holds,
maxCombo: beatmapPpData.calculatedMapAttributes.maxCombo,
fullSR: beatmapPpData.calculatedMapAttributes.fullStars,
memoryAR: menuData.AR,
memoryCS: menuData.CS,
memoryOD: menuData.OD,
memoryHP: menuData.HP
fullSR: fixDecimals(
beatmapPpData.calculatedMapAttributes.fullStars
),
memoryAR: fixDecimals(menuData.AR),
memoryCS: fixDecimals(menuData.CS),
memoryOD: fixDecimals(menuData.OD),
memoryHP: fixDecimals(menuData.HP)
},
path: {
full: path.join(
Expand Down Expand Up @@ -182,9 +185,11 @@ export const buildResult = (
hitErrorArray: gamePlayData.HitErrors
},
pp: {
current: beatmapPpData.currAttributes.pp,
fc: beatmapPpData.currAttributes.fcPP,
maxThisPlay: beatmapPpData.currAttributes.maxThisPlayPP
current: fixDecimals(beatmapPpData.currAttributes.pp),
fc: fixDecimals(beatmapPpData.currAttributes.fcPP),
maxThisPlay: fixDecimals(
beatmapPpData.currAttributes.maxThisPlayPP
)
},
keyOverlay: {
k1: {
Expand Down
24 changes: 11 additions & 13 deletions packages/tosu/src/entities/BeatmapPpData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ export class BeatmapPPData extends AbstractEntity {

const start_time = performance.now();

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

const mapPath = path.join(
settings.songsFolder,
Expand Down Expand Up @@ -256,12 +258,10 @@ export class BeatmapPPData extends AbstractEntity {
).toFixed(2)}ms on parsing beatmap`
);

const LEFT_OFFSET = Math.floor(beatmapPpData.timings.firstObj / offset);
const LEFT_OFFSET = Math.floor(this.timings.firstObj / offset);
const RIGHT_OFFSET =
menuData.MP3Length > beatmapPpData.timings.full
? Math.ceil(
(menuData.MP3Length - beatmapPpData.timings.full) / offset
)
menuData.MP3Length > this.timings.full
? Math.ceil((menuData.MP3Length - this.timings.full) / offset)
: 0;

const updateWithOffset = (name: string, values: number[]) => {
Expand Down Expand Up @@ -325,15 +325,13 @@ export class BeatmapPPData extends AbstractEntity {
resultStrains.xaxis.push(i * offset);
}

const amount = Math.ceil(beatmapPpData.timings.full / offset);
const amount = Math.ceil(this.timings.full / offset);
for (let i = 0; i < amount; i++) {
resultStrains.xaxis.push(
beatmapPpData.timings.firstObj + i * offset
);
resultStrains.xaxis.push(this.timings.firstObj + i * offset);
}

for (let i = 0; i < RIGHT_OFFSET; i++) {
resultStrains.xaxis.push(beatmapPpData.timings.full + i * offset);
resultStrains.xaxis.push(this.timings.full + i * offset);
}

const end_time = performance.now();
Expand Down
47 changes: 23 additions & 24 deletions packages/tosu/src/entities/TourneyUserProfileData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,32 @@ export class TourneyUserProfileData extends AbstractEntity {
return;
}

// [[UserInfo - 0x5]] + 0x4
this.Accuracy = process.readDouble(this.UserInfoBase + 0x4);
if (this.Accuracy < 0) {
// TODO: fix it some better way
try {
// [[UserInfo - 0x5]] + 0x4
this.Accuracy = process.readDouble(this.UserInfoBase + 0x4);
// [[UserInfo - 0x5]] + UserInfoAddr
this.RankedScore = process.readLong(this.UserInfoBase + 0xc);
// [[UserInfo - 0x5]] + 0x7C
this.PlayCount = process.readInt(this.UserInfoBase + 0x7c);
// [[UserInfo - 0x5]] + 0x84
this.GlobalRank = process.readInt(this.UserInfoBase + 0x84);
// [[UserInfo - 0x5]] + 0x9C
this.PP = process.readInt(this.UserInfoBase + 0x9c);
// [[[UserInfo - 0x5]] + 0x30]
this.Name = process.readSharpString(
process.readInt(this.UserInfoBase + 0x30)
);
// [[[UserInfo - 0x5]] + 0x2C]
this.Country = process.readSharpString(
process.readInt(this.UserInfoBase + 0x2c)
);
// [[UserInfo - 0x5]] + 0x70
this.UserID = process.readInt(this.UserInfoBase + 0x70);
} catch (exc) {
wLogger.error('[TourneyUserProfileData] signature failed');
this.UserInfoBase = 0;
return;
}

// [[UserInfo - 0x5]] + UserInfoAddr
this.RankedScore = process.readLong(this.UserInfoBase + 0xc);
// [[UserInfo - 0x5]] + 0x7C
this.PlayCount = process.readInt(this.UserInfoBase + 0x7c);
// [[UserInfo - 0x5]] + 0x84
this.GlobalRank = process.readInt(this.UserInfoBase + 0x84);
// [[UserInfo - 0x5]] + 0x9C
this.PP = process.readInt(this.UserInfoBase + 0x9c);
// [[[UserInfo - 0x5]] + 0x30]
this.Name = process.readSharpString(
process.readInt(this.UserInfoBase + 0x30)
);
// [[[UserInfo - 0x5]] + 0x2C]
this.Country = process.readSharpString(
process.readInt(this.UserInfoBase + 0x2c)
);
// [[UserInfo - 0x5]] + 0x70
this.UserID = process.readInt(this.UserInfoBase + 0x70);

wLogger.debug(`[TourneyUserProfileData:updateState] updated`);
}
}
8 changes: 8 additions & 0 deletions packages/tosu/src/utils/fixDecimals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Simple function to convert 4.123123132131 -> 4.13
*
* @param decimalNumber number with big amount of numbers after dot
* @returns float number with two digits after
*/
export const fixDecimals = (decimalNumber: number) =>
Math.ceil(decimalNumber * 100) / 100;

0 comments on commit 78033e9

Please sign in to comment.