osu-api-extended
Version:
Advanced osu! api wrapper cover all V2 and V1 endpoints, and provide useful tools
195 lines (194 loc) • 7.2 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculate_hits = exports.calculate_total_passed_objects = void 0;
const enums_1 = require("../types/enums");
const handleErrors_1 = require("../utility/handleErrors");
/**
* Calculate total passed objects
*
*
*
* ### Parameters
* - `hits.geki` or `hits.perfect` or `hits.count_geki` - Amount of geki's
* - `hits[300]` or `hits.great` or `hits.count_300` - Amount of 300's
* - `hits.katu` or `hits.good` or `hits.count_katu` - Amount of katu's
* - `hits[100]` or `hits.ok` or `hits.count_100` - Amount of 100's
* - `hits[50]` or `hits.meh` or `hits.count_50` - Amount of 50's
* - `hits[0]` or `hits.miss` or `hits.count_miss` - Amount of misses
*
* - `mode` - Number/Name of the gamemode
*
*
*
* ### Usage Example
* ```js
* const { tools } = require('osu-api-extended');
*
* function main() {
* try {
* const hits = { 300: 123, 100: 12, 50: 1, 0: 1 };
* const result = tools.calculate_total_passed_objects(hits, 'osu');
* if (result.error != null) {
* console.log(result.error);
* return;
* };
*
*
* console.log(result);
* } catch (error) {
* console.log(error);
* };
* };
*
* main();
* ```
*/
const calculate_total_passed_objects = (hits, mode) => {
if (Object.keys(hits).length == 0) {
return (0, handleErrors_1.handleErrors)(new Error('Provide hits (300, 100, 50, etc)'));
}
;
const geki = parseInt(hits.perfect || hits.count_geki || (hits === null || hits === void 0 ? void 0 : hits.geki) || '0');
const h300 = parseInt(hits.great || hits.count_300 || (hits === null || hits === void 0 ? void 0 : hits[300]) || '0');
const katu = parseInt(hits.good || hits.count_katu || (hits === null || hits === void 0 ? void 0 : hits.katu) || '0');
const h100 = parseInt(hits.ok || hits.count_100 || (hits === null || hits === void 0 ? void 0 : hits[100]) || '0');
const h50 = parseInt(hits.meh || hits.count_50 || (hits === null || hits === void 0 ? void 0 : hits[50]) || '0');
const h0 = parseInt(hits.miss || hits.count_miss || (hits === null || hits === void 0 ? void 0 : hits[0]) || '0');
let total_objects = 0;
switch (mode) {
case 'osu':
case enums_1.GamemodeEnum.osu:
total_objects = h300 + h100 + h50 + h0;
break;
case 'taiko':
case enums_1.GamemodeEnum.taiko:
total_objects = h300 + h100 + h0;
break;
case 'fruits':
case enums_1.GamemodeEnum.fruits:
total_objects = h300 + h100 + katu + h50 + h0;
break;
case 'mania':
case enums_1.GamemodeEnum.mania:
total_objects = h300 + geki + h100 + katu + h50 + h0;
break;
default:
return (0, handleErrors_1.handleErrors)(new Error(`Unsupported gamemode: ${mode}}`));
}
;
return {
amount: total_objects,
mode: mode,
hits: {
geki: geki,
300: h300,
katu: katu,
100: h100,
50: h50,
0: h0,
}
};
};
exports.calculate_total_passed_objects = calculate_total_passed_objects;
/**
* Calculate a play as an FC with the given hits.
*
*
*
* ### Parameters
* - `hits.geki` or `hits.perfect` or `hits.count_geki` - Amount of geki's
* - `hits[300]` or `hits.great` or `hits.count_300` - Amount of 300's
* - `hits.katu` or `hits.good` or `hits.count_katu` - Amount of katu's
* - `hits[100]` or `hits.ok` or `hits.count_100` - Amount of 100's
* - `hits[50]` or `hits.meh` or `hits.count_50` - Amount of 50's
* - `hits[0]` or `hits.miss` or `hits.count_miss` - Amount of misses
*
* - `mode` - Number/Name of the gamemode
*
*
*
* ### Usage Example
* ```js
* const { tools } = require('osu-api-extended');
*
* function main() {
* try {
* const hits = { 300: 123, 100: 12, 50: 1, 0: 1 };
* const result = tools.calculate_hits(hits, 'osu');
* if (result.error != null) {
* console.log(result.error);
* return;
* };
*
*
* console.log(result);
* } catch (error) {
* console.log(error);
* };
* };
*
* main();
* ```
*/
const calculate_hits = (hits, mode) => {
if (Object.keys(hits).length == 0) {
return (0, handleErrors_1.handleErrors)(new Error('Provide hits (300, 100, 50, etc)'));
}
;
const geki = parseInt(hits.perfect || hits.count_geki || (hits === null || hits === void 0 ? void 0 : hits.geki) || '0');
const h300 = parseInt(hits.great || hits.count_300 || (hits === null || hits === void 0 ? void 0 : hits[300]) || '0');
const katu = parseInt(hits.good || hits.count_katu || (hits === null || hits === void 0 ? void 0 : hits.katu) || '0');
const h100 = parseInt(hits.ok || hits.count_100 || (hits === null || hits === void 0 ? void 0 : hits[100]) || '0');
const h50 = parseInt(hits.meh || hits.count_50 || (hits === null || hits === void 0 ? void 0 : hits[50]) || '0');
const h0 = parseInt(hits.miss || hits.count_miss || (hits === null || hits === void 0 ? void 0 : hits[0]) || '0');
let geki_fc = parseInt(hits.perfect || hits.count_geki || (hits === null || hits === void 0 ? void 0 : hits.geki) || '0');
let h300_fc = parseInt(hits.great || hits.count_300 || (hits === null || hits === void 0 ? void 0 : hits[300]) || '0');
let katu_fc = parseInt(hits.good || hits.count_katu || (hits === null || hits === void 0 ? void 0 : hits.katu) || '0');
let h100_fc = parseInt(hits.ok || hits.count_100 || (hits === null || hits === void 0 ? void 0 : hits[100]) || '0');
let h50_fc = parseInt(hits.meh || hits.count_50 || (hits === null || hits === void 0 ? void 0 : hits[50]) || '0');
let h0_fc = parseInt(hits.miss || hits.count_miss || (hits === null || hits === void 0 ? void 0 : hits[0]) || '0');
switch (mode) {
case 'osu':
case enums_1.GamemodeEnum.osu:
h300_fc = h300 + h0;
h0_fc = 0;
break;
case 'taiko':
case enums_1.GamemodeEnum.taiko:
h300_fc = h300 + h0;
h0_fc = 0;
break;
case 'fruits':
case enums_1.GamemodeEnum.fruits:
h300_fc = h300 + h0;
h0_fc = 0;
break;
case 'mania':
case enums_1.GamemodeEnum.mania:
h300_fc = h300 + h0;
h0_fc = 0;
break;
default:
return (0, handleErrors_1.handleErrors)(new Error(`Unsupported gamemode: ${mode}}`));
}
;
return {
hits: {
geki: geki,
300: h300,
katu: katu,
100: h100,
50: h50,
0: h0,
},
fc: {
geki: geki_fc,
300: h300_fc,
katu: katu_fc,
100: h100_fc,
50: h50_fc,
0: h0_fc,
}
};
};
exports.calculate_hits = calculate_hits;
;