Skip to content

Commit

Permalink
fix: switch to new rosu-pp version
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Jun 29, 2024
1 parent e799ebe commit 7870d53
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 135 deletions.
6 changes: 3 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"build": "tsc"
},
"dependencies": {
"semver": "^7.5.4",
"@kotrikd/rosu-pp": "^0.10.0",
"@tosu/updater": "workspace:*",
"@tosu/common": "workspace:*",
"@tosu/updater": "workspace:*",
"rosu-pp-js": "^1.0.2",
"semver": "^7.5.4",
"ws": "^8.16.0"
},
"devDependencies": {
Expand Down
53 changes: 34 additions & 19 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Beatmap, Calculator } from '@kotrikd/rosu-pp';
import {
downloadFile,
getCachePath,
Expand All @@ -11,6 +10,7 @@ import { autoUpdater } from '@tosu/updater';
import { exec } from 'child_process';
import fs from 'fs';
import path from 'path';
import rosu from 'rosu-pp-js';

import { Server, sendJson } from '../index';
import {
Expand Down Expand Up @@ -397,29 +397,44 @@ export default function buildBaseApi(server: Server) {
menuData.Path
);

const parseBeatmap = new Beatmap({ path: beatmapFilePath });
const calculator = new Calculator();

const array = Object.keys(query || {});
for (let i = 0; i < array.length; i++) {
const key = array[i];
const value = query[key];

if (key in calculator && isFinite(+value)) {
calculator[key](+value);
}
}

return sendJson(res, {
attributes: calculator.mapAttributes(parseBeatmap),
performance: calculator.performance(parseBeatmap)
});
const beatmapContent = fs.readFileSync(beatmapFilePath, 'utf8');
const beatmap = new rosu.Beatmap(beatmapContent);
if (query.mode !== undefined) beatmap.convert(query.mode);

const params: { [key: string]: any } = {
// ar: ,
// arWithMods: ,
// cs: ,
// csWithMods: ,
// hardrockOffsets: ,
// hitresultPriority: ,
// hp: ,
// hpWithMods: ,
// od: ,
// odWithMods: ,
};

if (query.clockRate) params.clockRate = +query.clockRate;
if (query.passedObjects)
params.passedObjects = +query.passedObjects;
if (query.combo) params.combo = +query.combo;
if (query.nMisses) params.misses = +query.nMisses;
if (query.n100) params.n100 = +query.n100;
if (query.n300) params.n300 = +query.n300;
if (query.n50) params.n50 = +query.n50;
if (query.nGeki) params.nGeki = +query.nGeki;
if (query.nKatu) params.nKatu = +query.nKatu;
if (query.mods) params.mods = +query.mods;
if (query.accuracy) params.accuracy = +query.acc;

const calculate = new rosu.Performance(params).calculate(beatmap);
return sendJson(res, calculate);
} catch (exc) {
wLogger.error('calculate/pp', (exc as any).message);
wLogger.debug('calculate/pp', exc);

return sendJson(res, {
error: (exc as any).message
error: typeof exc === 'string' ? exc : (exc as any).message
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"compile": "pnpm run genver && pnpm run ts:compile && pnpm run compile:prepare-htmls && pkg --output dist/tosu.exe --debug --config pkg.json --compress brotli dist/index.js && pnpm run ts:run src/postBuild.ts"
},
"dependencies": {
"@kotrikd/rosu-pp": "^0.10.0",
"@tosu/common": "workspace:*",
"@tosu/game-overlay": "workspace:*",
"@tosu/server": "workspace:*",
Expand All @@ -24,6 +23,7 @@
"osu-standard-stable": "^5.0.0",
"osu-taiko-stable": "^5.0.0",
"resedit": "^2.0.0",
"rosu-pp-js": "^1.0.2",
"semver": "^7.5.4",
"tsprocess": "workspace:*"
},
Expand Down
1 change: 1 addition & 0 deletions packages/tosu/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"scripts": "dist/**/*.js",
"assets": [
"dist/**/*.node",
"dist/**/*.wasm",
"dist/target/**/*",
"dist/_version.js",
"dist/assets/**/*"
Expand Down
Loading

0 comments on commit 7870d53

Please sign in to comment.