UNPKG

osu-api-extended

Version:

Advanced osu! api wrapper for v1 and v2, with extra stuff

115 lines (114 loc) 5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convert_hits = exports.calculate_total_objects = void 0; const enums_1 = require("../types/enums"); const handleErrors_1 = require("../utility/handleErrors"); const calculate_total_objects = (hits, mode) => { if (Object.keys(hits).length == 0) { return (0, handleErrors_1.handleErrors)('Provide hits (300, 100, 50, etc)'); } ; const geki = parseInt((hits === null || hits === void 0 ? void 0 : hits.geki) || hits.count_geki || hits.perfect || '0'); const h300 = parseInt((hits === null || hits === void 0 ? void 0 : hits[300]) || hits.count_300 || hits.great || '0'); const katu = parseInt((hits === null || hits === void 0 ? void 0 : hits.katu) || hits.count_katu || hits.good || '0'); const h100 = parseInt((hits === null || hits === void 0 ? void 0 : hits[100]) || hits.count_100 || hits.ok || '0'); const h50 = parseInt((hits === null || hits === void 0 ? void 0 : hits[50]) || hits.count_50 || hits.meh || '0'); const h0 = parseInt((hits === null || hits === void 0 ? void 0 : hits[0]) || hits.count_miss || hits.miss || '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)(`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_objects = calculate_total_objects; const convert_hits = (hits, mode) => { if (Object.keys(hits).length == 0) { return (0, handleErrors_1.handleErrors)('Provide hits (300, 100, 50, etc)'); } ; const geki = parseInt((hits === null || hits === void 0 ? void 0 : hits.geki) || hits.count_geki || hits.perfect || '0'); const h300 = parseInt((hits === null || hits === void 0 ? void 0 : hits[300]) || hits.count_300 || hits.great || '0'); const katu = parseInt((hits === null || hits === void 0 ? void 0 : hits.katu) || hits.count_katu || hits.good || '0'); const h100 = parseInt((hits === null || hits === void 0 ? void 0 : hits[100]) || hits.count_100 || hits.ok || '0'); const h50 = parseInt((hits === null || hits === void 0 ? void 0 : hits[50]) || hits.count_50 || hits.meh || '0'); const h0 = parseInt((hits === null || hits === void 0 ? void 0 : hits[0]) || hits.count_miss || hits.miss || '0'); let geki_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits.geki) || hits.count_geki || hits.perfect || '0'); let h300_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits[300]) || hits.count_300 || hits.great || '0'); let katu_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits.katu) || hits.count_katu || hits.good || '0'); let h100_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits[100]) || hits.count_100 || hits.ok || '0'); let h50_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits[50]) || hits.count_50 || hits.meh || '0'); let h0_fc = parseInt((hits === null || hits === void 0 ? void 0 : hits[0]) || hits.count_miss || hits.miss || '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)(`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.convert_hits = convert_hits;