Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for next major versions of the osu! dependencies #8

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"typescript": "^4.6.4"
},
"peerDependencies": {
"osu-catch-stable": "^3.2.3",
"osu-classes": "^2.2.1",
"osu-catch-stable": "^4.0.0",
"osu-classes": "^3.0.1",
"osu-downloader": "^0.8.1",
"osu-mania-stable": "^4.0.4",
"osu-parsers": "^4.0.0",
"osu-standard-stable": "^4.0.4",
"osu-taiko-stable": "^4.0.5"
"osu-mania-stable": "^5.0.0",
"osu-parsers": "^4.1.4",
"osu-standard-stable": "^5.0.0",
"osu-taiko-stable": "^5.0.0"
}
}
2 changes: 1 addition & 1 deletion src/Calculators/ScoreCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class ScoreCalculator {
ruleset,
});

score.info.pp = performance.totalPerformance;
score.info.totalPerformance = performance.totalPerformance;

return {
scoreInfo: score.info.toJSON(),
Expand Down
54 changes: 38 additions & 16 deletions src/Core/ScoreSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import {
ScoreInfo,
MathUtils,
IScore,
HitResult,
HitStatistics,
} from 'osu-classes';

import {
generateHitStatistics,
getValidHitStatistics,
toCombination,
} from './Utils';

import {
IBeatmapAttributes,
IScoreSimulationOptions,
} from './Interfaces';

import { GameMode } from './Enums';
import type { IBeatmapAttributes, IScoreSimulationOptions } from './Interfaces';

/**
* A score simulator.
Expand Down Expand Up @@ -52,7 +57,7 @@ export class ScoreSimulator {
const multiplier = MathUtils.clamp(percentage, 0, 100) / 100;

const scoreCombo = options.maxCombo ?? Math.round(beatmapCombo * multiplier);
const misses = statistics.miss ?? 0;
const misses = statistics.get(HitResult.Miss);

// We need to limit max combo with score misses.
const limitedCombo = Math.min(scoreCombo, beatmapCombo - misses);
Expand Down Expand Up @@ -81,29 +86,46 @@ export class ScoreSimulator {
return this.simulateMax(attributes);
}

const statistics = getValidHitStatistics(scoreInfo.statistics);
const statistics = scoreInfo.statistics;
const totalHits = attributes.totalHits ?? 0;

switch (scoreInfo.rulesetId) {
case GameMode.Fruits:
statistics.great = totalHits - statistics.largeTickHit
- statistics.smallTickHit - statistics.smallTickMiss - statistics.miss;
case GameMode.Fruits: {
const largeTickHit = statistics.get(HitResult.LargeTickHit);
const smallTickHit = statistics.get(HitResult.SmallTickHit);
const smallTickMiss = statistics.get(HitResult.SmallTickMiss);
const miss = statistics.get(HitResult.Miss);

statistics.set(
HitResult.Great,
totalHits - largeTickHit - smallTickHit - smallTickMiss - miss,
);

statistics.largeTickHit += statistics.miss;
statistics.set(HitResult.LargeTickHit, largeTickHit + miss);

break;
}

case GameMode.Mania:
statistics.perfect = totalHits - statistics.great
- statistics.good - statistics.ok - statistics.meh;
case GameMode.Mania: {
const great = statistics.get(HitResult.Great);
const good = statistics.get(HitResult.Good);
const ok = statistics.get(HitResult.Ok);
const meh = statistics.get(HitResult.Meh);

statistics.set(HitResult.Perfect, totalHits - great - good - ok - meh);

break;
}

default: {
const ok = statistics.get(HitResult.Ok);
const meh = statistics.get(HitResult.Meh);

default:
statistics.great = totalHits - statistics.ok - statistics.meh;
statistics.set(HitResult.Great, totalHits - ok - meh);
}
}

statistics.miss = 0;
statistics.set(HitResult.Miss, 0);

return this._generateScoreInfo({
...scoreInfo,
Expand Down Expand Up @@ -146,13 +168,13 @@ export class ScoreSimulator {
userId: options?.userId ?? 0,
username: options?.username ?? 'osu!',
maxCombo: options?.maxCombo ?? 0,
statistics: getValidHitStatistics(options?.statistics),
statistics: options?.statistics ?? new HitStatistics(),
rawMods: options?.rawMods ?? 0,
rulesetId: options?.rulesetId ?? 0,
perfect: options?.perfect ?? false,
beatmapHashMD5: options?.beatmapHashMD5,
date: options?.date ?? new Date(),
pp: options?.pp ?? null,
totalPerformance: options?.totalPerformance ?? null,
});

if (options?.mods) scoreInfo.mods = options.mods;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Utils/Beatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createBeatmapInfo(beatmap?: IBeatmap, hash?: string): IBeatmapIn
length: (beatmap?.length ?? 0) / 1000,
bpmMin: beatmap?.bpmMin,
bpmMax: beatmap?.bpmMax,
bpmMode: beatmap?.bpmMode,
bpm: beatmap?.bpm,
circleSize: beatmap?.difficulty.circleSize,
approachRate: beatmap?.difficulty.approachRate,
overallDifficulty: beatmap?.difficulty.overallDifficulty,
Expand All @@ -46,7 +46,7 @@ export function createBeatmapInfo(beatmap?: IBeatmap, hash?: string): IBeatmapIn
mods: getMods(beatmap),
maxCombo: getMaxCombo(beatmap),
isConvert: beatmap?.originalMode !== beatmap?.mode,
md5: hash ?? '',
hashMD5: hash ?? '',
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Utils/Conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function toScoreInfo(data?: IScoreInfo | IJsonableScoreInfo): ScoreInfo {

scoreInfo.id = jsonable?.id;
scoreInfo.totalScore = jsonable?.totalScore;
scoreInfo.pp = jsonable?.pp;
scoreInfo.totalPerformance = jsonable?.totalPerformance;
scoreInfo.maxCombo = jsonable?.maxCombo;
scoreInfo.passed = jsonable?.passed;
scoreInfo.perfect = jsonable?.perfect;
Expand All @@ -50,7 +50,7 @@ export function toScoreInfo(data?: IScoreInfo | IJsonableScoreInfo): ScoreInfo {
scoreInfo.username = jsonable?.username;
scoreInfo.userId = jsonable?.userId;
scoreInfo.beatmapId = jsonable?.beatmapId;
scoreInfo.date = jsonable?.date;
scoreInfo.date = jsonable?.date ? new Date(jsonable?.date) : new Date();
scoreInfo.beatmapHashMD5 = jsonable?.beatmapHashMD5;
scoreInfo.rulesetId = jsonable?.rulesetId;
scoreInfo.mods = toCombination(jsonable.mods, jsonable.rulesetId);
Expand Down
Loading