Skip to content

Commit

Permalink
fix: Combine functions into one file + remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Feb 19, 2024
1 parent c1662e3 commit b494b52
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 399 deletions.
51 changes: 0 additions & 51 deletions packages/tosu/src/api/utils/accuracy.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/tosu/src/api/utils/buildResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import { DataRepo } from '@/entities/DataRepoList';
import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/entities/GamePlayData/Leaderboard';
import { InstanceManager } from '@/objects/instanceManager/instanceManager';
import { fixDecimals } from '@/utils/fixDecimals';
import { fixDecimals } from '@/utils/converters';
import { getOsuModsString } from '@/utils/osuMods';

import {
Expand Down
9 changes: 4 additions & 5 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import path from 'path';
import { DataRepo } from '@/entities/DataRepoList';
import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/entities/GamePlayData/Leaderboard';
import { InstanceManager } from '@/objects/instanceManager/instanceManager';
import { fixDecimals } from '@/utils/fixDecimals';
import { calculateAccuracy, calculateGrade } from '@/utils/calculators';
import { fixDecimals } from '@/utils/converters';
import { getOsuModsString } from '@/utils/osuMods';

import {
Expand All @@ -18,9 +19,7 @@ import {
TourneyClients,
UserLoginStatus
} from '../types/v2';
import accuracyCalculator from './accuracy';
import { CountryCodes } from './countryCodes';
import rankCalculate from './rank';

const convertMemoryPlayerToResult = (
memoryPlayer: MemoryLeaderboardPlayer,
Expand All @@ -46,7 +45,7 @@ const convertMemoryPlayerToResult = (
name: memoryPlayer.Name,

score: memoryPlayer.Score,
accuracy: accuracyCalculator(hits, gameMode),
accuracy: calculateAccuracy({ hits, mode: gameMode }),

hits: hits,

Expand All @@ -58,7 +57,7 @@ const convertMemoryPlayerToResult = (
number: memoryPlayer.Mods,
name: modsName
},
rank: rankCalculate({
rank: calculateGrade({
mods: modsName,
mode: gameMode,
hits: hits
Expand Down
124 changes: 0 additions & 124 deletions packages/tosu/src/api/utils/rank.ts

This file was deleted.

47 changes: 26 additions & 21 deletions packages/tosu/src/entities/GamePlayData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { Process } from 'tsprocess/dist/process';

import { DataRepo } from '@/entities/DataRepoList';
import { Leaderboard } from '@/entities/GamePlayData/Leaderboard';
import { calculateGrade } from '@/utils/calculateGrade';
import { calculateGrade, calculatePassedObjects } from '@/utils/calculators';
import { OsuMods } from '@/utils/osuMods.types';
import { resolvePassedObjects } from '@/utils/resolvePassedObjects';

import { AbstractEntity } from '../AbstractEntity';
import { MenuData } from '../MenuData';
Expand Down Expand Up @@ -382,25 +381,31 @@ export class GamePlayData extends AbstractEntity {
this.Hit50 -
this.HitMiss;

this.GradeCurrent = calculateGrade(
this.Mode,
this.Mods,
this.Hit300,
this.Hit100,
this.Hit50,
this.HitMiss,
this.Accuracy
);
this.GradeCurrent = calculateGrade({
mods: this.Mods,
mode: this.Mode,
hits: {
300: this.Hit300,
geki: 0,
100: this.Hit100,
katu: 0,
50: this.Hit50,
0: this.HitMiss
}
});

this.GradeExpected = calculateGrade(
this.Mode,
this.Mods,
this.Hit300 + remaining,
this.Hit100,
this.Hit50,
this.HitMiss,
this.Accuracy
);
this.GradeExpected = calculateGrade({
mods: this.Mods,
mode: this.Mode,
hits: {
300: this.Hit300 + remaining,
geki: 0,
100: this.Hit100,
katu: 0,
50: this.Hit50,
0: this.HitMiss
}
});
}

private updateLeaderboard(
Expand Down Expand Up @@ -461,7 +466,7 @@ export class GamePlayData extends AbstractEntity {
}

const scoreParams = {
passedObjects: resolvePassedObjects(
passedObjects: calculatePassedObjects(
this.Mode,
this.Hit300,
this.Hit100,
Expand Down
34 changes: 14 additions & 20 deletions packages/tosu/src/entities/ResultsScreenData/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { wLogger } from '@tosu/common';

import { DataRepo } from '@/entities/DataRepoList';
import { calculateAccuracy } from '@/utils/calculateAccuracy';
import { calculateGrade } from '@/utils/calculateGrade';
import { netDateBinaryToDate } from '@/utils/netDateBinaryToDate';
import { calculateGrade } from '@/utils/calculators';
import { netDateBinaryToDate } from '@/utils/converters';
import { OsuMods } from '@/utils/osuMods.types';

import { AbstractEntity } from '../AbstractEntity';
Expand Down Expand Up @@ -104,23 +103,18 @@ export class ResultsScreenData extends AbstractEntity {
this.HitKatu = process.readShort(resultScreenBase + 0x90);
// HitMiss int16 `mem:"[Ruleset + 0x38] + 0x92"`
this.HitMiss = process.readShort(resultScreenBase + 0x92);
this.Grade = calculateGrade(
this.Mode,
this.Mods,
this.Hit300,
this.Hit100,
this.Hit50,
this.HitMiss,
calculateAccuracy(
this.Mode,
this.Hit300,
this.Hit100,
this.Hit50,
this.HitMiss,
this.HitKatu,
this.HitGeki
) * 100
);
this.Grade = calculateGrade({
mods: this.Mods,
mode: this.Mode,
hits: {
300: this.Hit300,
geki: 0,
100: this.Hit100,
katu: 0,
50: this.Hit50,
0: this.HitMiss
}
});
this.Date = netDateBinaryToDate(
process.readInt(resultScreenBase + 0xa4),
process.readInt(resultScreenBase + 0xa0)
Expand Down
38 changes: 0 additions & 38 deletions packages/tosu/src/utils/calculateAccuracy.ts

This file was deleted.

Loading

0 comments on commit b494b52

Please sign in to comment.