UNPKG

rosu-pp-js

Version:

Difficulty and performance calculation for osu!

1,575 lines (1,504 loc) 84.1 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder, TextEncoder, inspect } = require(`util`); const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); function getObject(idx) { return heap[idx]; } let heap_next = heap.length; function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { wasm.__wbindgen_export_0(addHeapObject(e)); } } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } function debugString(val) { // primitive types const type = typeof val; if (type == 'number' || type == 'boolean' || val == null) { return `${val}`; } if (type == 'string') { return `"${val}"`; } if (type == 'symbol') { const description = val.description; if (description == null) { return 'Symbol'; } else { return `Symbol(${description})`; } } if (type == 'function') { const name = val.name; if (typeof name == 'string' && name.length > 0) { return `Function(${name})`; } else { return 'Function'; } } // objects if (Array.isArray(val)) { const length = val.length; let debug = '['; if (length > 0) { debug += debugString(val[0]); } for(let i = 1; i < length; i++) { debug += ', ' + debugString(val[i]); } debug += ']'; return debug; } // Test for built-in const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); let className; if (builtInMatches && builtInMatches.length > 1) { className = builtInMatches[1]; } else { // Failed to match the standard '[object ClassName]' return toString.call(val); } if (className == 'Object') { // we're a user defined class or Object // JSON.stringify avoids problems with cycles, and is generally much // easier than looping through ownProperties of `val`. try { return 'Object(' + JSON.stringify(val) + ')'; } catch (_) { return 'Object'; } } // errors if (val instanceof Error) { return `${val.name}: ${val.message}\n${val.stack}`; } // TODO we could test for more things here, like `Set`s and `Map`s. return className; } let WASM_VECTOR_LEN = 0; let cachedTextEncoder = new TextEncoder('utf-8'); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8ArrayMemory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } function isLikeNone(x) { return x === undefined || x === null; } let stack_pointer = 128; function addBorrowedObject(obj) { if (stack_pointer == 1) throw new Error('out of js stack'); heap[--stack_pointer] = obj; return stack_pointer; } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getDataViewMemory0(); const result = []; for (let i = ptr; i < ptr + 4 * len; i += 4) { result.push(takeObject(mem.getUint32(i, true))); } return result; } let cachedFloat64ArrayMemory0 = null; function getFloat64ArrayMemory0() { if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) { cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer); } return cachedFloat64ArrayMemory0; } function getArrayF64FromWasm0(ptr, len) { ptr = ptr >>> 0; return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len); } /** * @enum {0 | 1 | 2 | 3} */ module.exports.GameMode = Object.freeze({ Osu: 0, "0": "Osu", Taiko: 1, "1": "Taiko", Catch: 2, "2": "Catch", Mania: 3, "3": "Mania", }); /** * While generating remaining hitresults, decide how they should be distributed. * @enum {0 | 1 | 2} */ module.exports.HitResultPriority = Object.freeze({ /** * Prioritize good hitresults over bad ones */ BestCase: 0, "0": "BestCase", /** * Prioritize bad hitresults over good ones */ WorstCase: 1, "1": "WorstCase", /** * Prioritize fast hitresults generation */ Fastest: 2, "2": "Fastest", }); const BeatmapFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_beatmap_free(ptr >>> 0, 1)); /** * All beatmap data that is relevant for difficulty and performance * calculation. * * It is recommended to call the method `Beatmap.free` on instances that are * no longer in use to avoid the risk of leaking memory. */ class Beatmap { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BeatmapFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_beatmap_free(ptr, 0); } /** * Create a new beatmap instance by parsing an `.osu` file's content. * @throws Throws an error if decoding the map failed * @param {BeatmapContent} args */ constructor(args) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.beatmap_new(retptr, addBorrowedObject(args)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } this.__wbg_ptr = r0 >>> 0; BeatmapFinalization.register(this, this.__wbg_ptr, this); return this; } finally { wasm.__wbindgen_add_to_stack_pointer(16); heap[stack_pointer++] = undefined; } } /** * Convert a beatmap to a specific mode. * @throws Throws an error if conversion fails or mods are invalid * @param {GameMode} mode * @param {Object | null} [mods] */ convert(mode, mods) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.beatmap_convert(retptr, this.__wbg_ptr, mode, isLikeNone(mods) ? 0 : addHeapObject(mods)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Check whether hitobjects appear too suspicious for further calculation. * * Sometimes a beatmap isn't created for gameplay but rather to test * the limits of osu! itself. Difficulty- and/or performance calculation * should likely be avoided on these maps due to potential performance * issues. * @returns {boolean} */ isSuspicious() { const ret = wasm.beatmap_isSuspicious(this.__wbg_ptr); return ret !== 0; } /** * @returns {number} */ get bpm() { const ret = wasm.beatmap_bpm(this.__wbg_ptr); return ret; } /** * @returns {GameMode} */ get mode() { const ret = wasm.beatmap_mode(this.__wbg_ptr); return ret; } /** * @returns {number} */ get nBreaks() { const ret = wasm.beatmap_nBreaks(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get nObjects() { const ret = wasm.beatmap_nObjects(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get nCircles() { const ret = wasm.beatmap_nCircles(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get nSliders() { const ret = wasm.beatmap_nSliders(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get nSpinners() { const ret = wasm.beatmap_nSpinners(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get nHolds() { const ret = wasm.beatmap_nHolds(this.__wbg_ptr); return ret >>> 0; } /** * @returns {number} */ get version() { const ret = wasm.beatmap_version(this.__wbg_ptr); return ret; } /** * @returns {boolean} */ get isConvert() { const ret = wasm.beatmap_isConvert(this.__wbg_ptr); return ret !== 0; } /** * @returns {number} */ get stackLeniency() { const ret = wasm.beatmap_stackLeniency(this.__wbg_ptr); return ret; } /** * @returns {number} */ get ar() { const ret = wasm.beatmap_ar(this.__wbg_ptr); return ret; } /** * @returns {number} */ get cs() { const ret = wasm.beatmap_cs(this.__wbg_ptr); return ret; } /** * @returns {number} */ get hp() { const ret = wasm.beatmap_hp(this.__wbg_ptr); return ret; } /** * @returns {number} */ get od() { const ret = wasm.beatmap_od(this.__wbg_ptr); return ret; } /** * @returns {number} */ get sliderMultiplier() { const ret = wasm.beatmap_sliderMultiplier(this.__wbg_ptr); return ret; } /** * @returns {number} */ get sliderTickRate() { const ret = wasm.beatmap_sliderTickRate(this.__wbg_ptr); return ret; } } module.exports.Beatmap = Beatmap; const BeatmapAttributesFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_beatmapattributes_free(ptr >>> 0, 1)); class BeatmapAttributes { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(BeatmapAttributes.prototype); obj.__wbg_ptr = ptr; BeatmapAttributesFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } toJSON() { return { ar: this.ar, od: this.od, cs: this.cs, hp: this.hp, clockRate: this.clockRate, arHitWindow: this.arHitWindow, odGreatHitWindow: this.odGreatHitWindow, odOkHitWindow: this.odOkHitWindow, odMehHitWindow: this.odMehHitWindow, }; } toString() { return JSON.stringify(this); } [inspect.custom]() { return Object.assign(Object.create({constructor: this.constructor}), this.toJSON()); } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BeatmapAttributesFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_beatmapattributes_free(ptr, 0); } /** * The approach rate. * @returns {number} */ get ar() { const ret = wasm.__wbg_get_beatmapattributes_ar(this.__wbg_ptr); return ret; } /** * The overall difficulty. * @returns {number} */ get od() { const ret = wasm.__wbg_get_beatmapattributes_od(this.__wbg_ptr); return ret; } /** * The circle size. * @returns {number} */ get cs() { const ret = wasm.__wbg_get_beatmapattributes_cs(this.__wbg_ptr); return ret; } /** * The health drain rate * @returns {number} */ get hp() { const ret = wasm.__wbg_get_beatmapattributes_hp(this.__wbg_ptr); return ret; } /** * The clock rate with respect to mods. * @returns {number} */ get clockRate() { const ret = wasm.__wbg_get_beatmapattributes_clockRate(this.__wbg_ptr); return ret; } /** * Hit window for approach rate i.e. TimePreempt in milliseconds. * @returns {number} */ get arHitWindow() { const ret = wasm.__wbg_get_beatmapattributes_arHitWindow(this.__wbg_ptr); return ret; } /** * Hit window for overall difficulty i.e. time to hit a 300 ("Great") in * milliseconds. * @returns {number} */ get odGreatHitWindow() { const ret = wasm.__wbg_get_beatmapattributes_odGreatHitWindow(this.__wbg_ptr); return ret; } /** * Hit window for overall difficulty i.e. time to hit a 100 ("Ok") in * milliseconds. * * Not available for osu!mania. * @returns {number | undefined} */ get odOkHitWindow() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_beatmapattributes_odOkHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Hit window for overall difficulty i.e. time to hit a 50 ("Meh") in * milliseconds. * * Only available for osu!. * @returns {number | undefined} */ get odMehHitWindow() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_beatmapattributes_odMehHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } module.exports.BeatmapAttributes = BeatmapAttributes; const BeatmapAttributesBuilderFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_beatmapattributesbuilder_free(ptr >>> 0, 1)); class BeatmapAttributesBuilder { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BeatmapAttributesBuilderFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_beatmapattributesbuilder_free(ptr, 0); } /** * Create a new `BeatmapAttributesBuilder`. * @param {BeatmapAttributesArgs | null} [args] */ constructor(args) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.beatmapattributesbuilder_new(retptr, isLikeNone(args) ? 0 : addHeapObject(args)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } this.__wbg_ptr = r0 >>> 0; BeatmapAttributesBuilderFinalization.register(this, this.__wbg_ptr, this); return this; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Calculate the `BeatmapAttributes`. * @returns {BeatmapAttributes} */ build() { const ptr = this.__destroy_into_raw(); const ret = wasm.beatmapattributesbuilder_build(ptr); return BeatmapAttributes.__wrap(ret); } /** * @param {Object | null} [mods] */ set mods(mods) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.beatmapattributesbuilder_set_mods(retptr, this.__wbg_ptr, isLikeNone(mods) ? 0 : addHeapObject(mods)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @param {number | null} [clock_rate] */ set clockRate(clock_rate) { wasm.beatmapattributesbuilder_set_clock_rate(this.__wbg_ptr, !isLikeNone(clock_rate), isLikeNone(clock_rate) ? 0 : clock_rate); } /** * @param {number | null} [ar] */ set ar(ar) { wasm.beatmapattributesbuilder_set_ar(this.__wbg_ptr, isLikeNone(ar) ? 0x100000001 : Math.fround(ar)); } /** * @param {boolean | null} [ar_with_mods] */ set arWithMods(ar_with_mods) { wasm.beatmapattributesbuilder_set_ar_with_mods(this.__wbg_ptr, isLikeNone(ar_with_mods) ? 0xFFFFFF : ar_with_mods ? 1 : 0); } /** * @param {number | null} [cs] */ set cs(cs) { wasm.beatmapattributesbuilder_set_cs(this.__wbg_ptr, isLikeNone(cs) ? 0x100000001 : Math.fround(cs)); } /** * @param {boolean | null} [cs_with_mods] */ set csWithMods(cs_with_mods) { wasm.beatmapattributesbuilder_set_cs_with_mods(this.__wbg_ptr, isLikeNone(cs_with_mods) ? 0xFFFFFF : cs_with_mods ? 1 : 0); } /** * @param {number | null} [hp] */ set hp(hp) { wasm.beatmapattributesbuilder_set_hp(this.__wbg_ptr, isLikeNone(hp) ? 0x100000001 : Math.fround(hp)); } /** * @param {boolean | null} [hp_with_mods] */ set hpWithMods(hp_with_mods) { wasm.beatmapattributesbuilder_set_hp_with_mods(this.__wbg_ptr, isLikeNone(hp_with_mods) ? 0xFFFFFF : hp_with_mods ? 1 : 0); } /** * @param {number | null} [od] */ set od(od) { wasm.beatmapattributesbuilder_set_od(this.__wbg_ptr, isLikeNone(od) ? 0x100000001 : Math.fround(od)); } /** * @param {boolean | null} [od_with_mods] */ set odWithMods(od_with_mods) { wasm.beatmapattributesbuilder_set_od_with_mods(this.__wbg_ptr, isLikeNone(od_with_mods) ? 0xFFFFFF : od_with_mods ? 1 : 0); } /** * @param {GameMode | null} [mode] */ set mode(mode) { wasm.beatmapattributesbuilder_set_mode(this.__wbg_ptr, isLikeNone(mode) ? 4 : mode); } /** * @param {boolean | null} [is_convert] */ set isConvert(is_convert) { wasm.beatmapattributesbuilder_set_is_convert(this.__wbg_ptr, isLikeNone(is_convert) ? 0xFFFFFF : is_convert ? 1 : 0); } /** * @param {Beatmap | null} [map] */ set map(map) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.beatmapattributesbuilder_set_map(retptr, this.__wbg_ptr, isLikeNone(map) ? 0 : addHeapObject(map)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } module.exports.BeatmapAttributesBuilder = BeatmapAttributesBuilder; const DifficultyFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_difficulty_free(ptr >>> 0, 1)); /** * Builder for a difficulty calculation. */ class Difficulty { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; DifficultyFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_difficulty_free(ptr, 0); } /** * Create a new difficulty calculator. * @param {DifficultyArgs | null} [args] */ constructor(args) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.difficulty_new(retptr, isLikeNone(args) ? 0 : addHeapObject(args)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } this.__wbg_ptr = r0 >>> 0; DifficultyFinalization.register(this, this.__wbg_ptr, this); return this; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Perform the difficulty calculation. * @param {Beatmap} map * @returns {DifficultyAttributes} */ calculate(map) { _assertClass(map, Beatmap); const ret = wasm.difficulty_calculate(this.__wbg_ptr, map.__wbg_ptr); return DifficultyAttributes.__wrap(ret); } /** * Perform the difficulty calculation but instead of evaluating strain * values, return them as is. * * Suitable to plot the difficulty over time. * @param {Beatmap} map * @returns {Strains} */ strains(map) { _assertClass(map, Beatmap); const ret = wasm.difficulty_strains(this.__wbg_ptr, map.__wbg_ptr); return Strains.__wrap(ret); } /** * Returns a gradual difficulty calculator for the current difficulty settings. * @param {Beatmap} map * @returns {GradualDifficulty} */ gradualDifficulty(map) { _assertClass(map, Beatmap); const ret = wasm.difficulty_gradualDifficulty(this.__wbg_ptr, map.__wbg_ptr); return GradualDifficulty.__wrap(ret); } /** * Returns a gradual performance calculator for the current difficulty settings. * @param {Beatmap} map * @returns {GradualPerformance} */ gradualPerformance(map) { _assertClass(map, Beatmap); const ret = wasm.difficulty_gradualPerformance(this.__wbg_ptr, map.__wbg_ptr); return GradualPerformance.__wrap(ret); } /** * @param {Object | null} [mods] */ set mods(mods) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.difficulty_set_mods(retptr, this.__wbg_ptr, isLikeNone(mods) ? 0 : addHeapObject(mods)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @param {boolean | null} [lazer] */ set lazer(lazer) { wasm.difficulty_set_lazer(this.__wbg_ptr, isLikeNone(lazer) ? 0xFFFFFF : lazer ? 1 : 0); } /** * @param {number | null} [clock_rate] */ set clockRate(clock_rate) { wasm.beatmapattributesbuilder_set_clock_rate(this.__wbg_ptr, !isLikeNone(clock_rate), isLikeNone(clock_rate) ? 0 : clock_rate); } /** * @param {number | null} [ar] */ set ar(ar) { wasm.beatmapattributesbuilder_set_ar(this.__wbg_ptr, isLikeNone(ar) ? 0x100000001 : Math.fround(ar)); } /** * @param {boolean | null} [ar_with_mods] */ set arWithMods(ar_with_mods) { wasm.difficulty_set_ar_with_mods(this.__wbg_ptr, isLikeNone(ar_with_mods) ? 0xFFFFFF : ar_with_mods ? 1 : 0); } /** * @param {number | null} [cs] */ set cs(cs) { wasm.beatmapattributesbuilder_set_cs(this.__wbg_ptr, isLikeNone(cs) ? 0x100000001 : Math.fround(cs)); } /** * @param {boolean | null} [cs_with_mods] */ set csWithMods(cs_with_mods) { wasm.difficulty_set_cs_with_mods(this.__wbg_ptr, isLikeNone(cs_with_mods) ? 0xFFFFFF : cs_with_mods ? 1 : 0); } /** * @param {number | null} [hp] */ set hp(hp) { wasm.beatmapattributesbuilder_set_hp(this.__wbg_ptr, isLikeNone(hp) ? 0x100000001 : Math.fround(hp)); } /** * @param {boolean | null} [hp_with_mods] */ set hpWithMods(hp_with_mods) { wasm.difficulty_set_hp_with_mods(this.__wbg_ptr, isLikeNone(hp_with_mods) ? 0xFFFFFF : hp_with_mods ? 1 : 0); } /** * @param {number | null} [od] */ set od(od) { wasm.beatmapattributesbuilder_set_od(this.__wbg_ptr, isLikeNone(od) ? 0x100000001 : Math.fround(od)); } /** * @param {boolean | null} [od_with_mods] */ set odWithMods(od_with_mods) { wasm.difficulty_set_od_with_mods(this.__wbg_ptr, isLikeNone(od_with_mods) ? 0xFFFFFF : od_with_mods ? 1 : 0); } /** * @param {number | null} [passed_objects] */ set passedObjects(passed_objects) { wasm.difficulty_set_passed_objects(this.__wbg_ptr, isLikeNone(passed_objects) ? 0x100000001 : (passed_objects) >>> 0); } /** * @param {boolean | null} [hardrock_offsets] */ set hardrockOffsets(hardrock_offsets) { wasm.difficulty_set_hardrock_offsets(this.__wbg_ptr, isLikeNone(hardrock_offsets) ? 0xFFFFFF : hardrock_offsets ? 1 : 0); } } module.exports.Difficulty = Difficulty; const DifficultyAttributesFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_difficultyattributes_free(ptr >>> 0, 1)); /** * The result of a difficulty calculation. */ class DifficultyAttributes { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(DifficultyAttributes.prototype); obj.__wbg_ptr = ptr; DifficultyAttributesFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } toJSON() { return { mode: this.mode, stars: this.stars, isConvert: this.isConvert, aim: this.aim, aimDifficultSliderCount: this.aimDifficultSliderCount, speed: this.speed, flashlight: this.flashlight, sliderFactor: this.sliderFactor, speedNoteCount: this.speedNoteCount, aimDifficultStrainCount: this.aimDifficultStrainCount, speedDifficultStrainCount: this.speedDifficultStrainCount, hp: this.hp, nCircles: this.nCircles, nSliders: this.nSliders, nLargeTicks: this.nLargeTicks, nSpinners: this.nSpinners, stamina: this.stamina, rhythm: this.rhythm, color: this.color, reading: this.reading, nFruits: this.nFruits, nDroplets: this.nDroplets, nTinyDroplets: this.nTinyDroplets, nObjects: this.nObjects, nHoldNotes: this.nHoldNotes, ar: this.ar, greatHitWindow: this.greatHitWindow, okHitWindow: this.okHitWindow, mehHitWindow: this.mehHitWindow, monoStaminaFactor: this.monoStaminaFactor, maxCombo: this.maxCombo, }; } toString() { return JSON.stringify(this); } [inspect.custom]() { return Object.assign(Object.create({constructor: this.constructor}), this.toJSON()); } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; DifficultyAttributesFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_difficultyattributes_free(ptr, 0); } /** * The attributes' gamemode. * @returns {GameMode} */ get mode() { const ret = wasm.__wbg_get_difficultyattributes_mode(this.__wbg_ptr); return ret; } /** * The final star rating. * @returns {number} */ get stars() { const ret = wasm.__wbg_get_difficultyattributes_stars(this.__wbg_ptr); return ret; } /** * Whether the map was a convert i.e. an osu! map. * @returns {boolean} */ get isConvert() { const ret = wasm.__wbg_get_difficultyattributes_isConvert(this.__wbg_ptr); return ret !== 0; } /** * The difficulty of the aim skill. * * Only available for osu!. * @returns {number | undefined} */ get aim() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_beatmapattributes_odOkHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The number of sliders weighted by difficulty. * * Only available for osu!. * @returns {number | undefined} */ get aimDifficultSliderCount() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_beatmapattributes_odMehHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The difficulty of the speed skill. * * Only available for osu!. * @returns {number | undefined} */ get speed() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_speed(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The difficulty of the flashlight skill. * * Only available for osu!. * @returns {number | undefined} */ get flashlight() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_flashlight(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The ratio of the aim strain with and without considering sliders * * Only available for osu!. * @returns {number | undefined} */ get sliderFactor() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_sliderFactor(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The number of clickable objects weighted by difficulty. * * Only available for osu!. * @returns {number | undefined} */ get speedNoteCount() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_speedNoteCount(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Weighted sum of aim strains. * * Only available for osu!. * @returns {number | undefined} */ get aimDifficultStrainCount() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_aimDifficultStrainCount(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Weighted sum of speed strains. * * Only available for osu!. * @returns {number | undefined} */ get speedDifficultStrainCount() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_speedDifficultStrainCount(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The health drain rate. * * Only available for osu!. * @returns {number | undefined} */ get hp() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_hp(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The amount of circles. * * Only available for osu!. * @returns {number | undefined} */ get nCircles() { const ret = wasm.__wbg_get_difficultyattributes_nCircles(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of sliders. * * Only available for osu!. * @returns {number | undefined} */ get nSliders() { const ret = wasm.__wbg_get_difficultyattributes_nSliders(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of "large ticks". * * The meaning depends on the kind of score: * - if set on osu!stable, this value is irrelevant * - if set on osu!lazer *with* slider accuracy, this value is the amount * of hit slider ticks and repeats * - if set on osu!lazer *without* slider accuracy, this value is the * amount of hit slider heads, ticks, and repeats * * Only available for osu!. * @returns {number | undefined} */ get nLargeTicks() { const ret = wasm.__wbg_get_difficultyattributes_nLargeTicks(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of spinners. * * Only available for osu!. * @returns {number | undefined} */ get nSpinners() { const ret = wasm.__wbg_get_difficultyattributes_nSpinners(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The difficulty of the stamina skill. * * Only available for osu!taiko. * @returns {number | undefined} */ get stamina() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_stamina(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The difficulty of the rhythm skill. * * Only available for osu!taiko. * @returns {number | undefined} */ get rhythm() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_rhythm(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The difficulty of the color skill. * * Only available for osu!taiko. * @returns {number | undefined} */ get color() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_color(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The difficulty of the reading skill. * * Only available for osu!taiko. * @returns {number | undefined} */ get reading() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_reading(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The amount of fruits. * * Only available for osu!catch. * @returns {number | undefined} */ get nFruits() { const ret = wasm.__wbg_get_difficultyattributes_nFruits(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of droplets. * * Only available for osu!catch. * @returns {number | undefined} */ get nDroplets() { const ret = wasm.__wbg_get_difficultyattributes_nDroplets(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of tiny droplets. * * Only available for osu!catch. * @returns {number | undefined} */ get nTinyDroplets() { const ret = wasm.__wbg_get_difficultyattributes_nTinyDroplets(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of hitobjects in the map. * * Only available for osu!mania. * @returns {number | undefined} */ get nObjects() { const ret = wasm.__wbg_get_difficultyattributes_nObjects(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The amount of hold notes in the map. * * Only available for osu!mania. * @returns {number | undefined} */ get nHoldNotes() { const ret = wasm.__wbg_get_difficultyattributes_nHoldNotes(this.__wbg_ptr); return ret === 0x100000001 ? undefined : ret; } /** * The approach rate. * * Only available for osu! and osu!catch. * @returns {number | undefined} */ get ar() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_ar(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The perceived hit window for an n300 inclusive of rate-adjusting mods * (DT/HT/etc) * * Only available for osu! and osu!taiko. * @returns {number | undefined} */ get greatHitWindow() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_greatHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The perceived hit window for an n100 inclusive of rate-adjusting mods * (DT/HT/etc) * * Only available for osu! and osu!taiko. * @returns {number | undefined} */ get okHitWindow() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_okHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The perceived hit window for an n50 inclusive of rate-adjusting mods * (DT/HT/etc) * * Only available for osu!. * @returns {number | undefined} */ get mehHitWindow() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_mehHitWindow(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * The ratio of stamina difficulty from mono-color (single color) streams to total * stamina difficulty. * * Only available for osu!taiko. * @returns {number | undefined} */ get monoStaminaFactor() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.__wbg_get_difficultyattributes_monoStaminaFactor(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r2 = getDataViewMemory0().getFloat64(retptr + 8 * 1, true); return r0 === 0 ? undefined : r2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Return the maximum combo. * @returns {number} */ get maxCombo() { const ret = wasm.__wbg_get_difficultyattributes_maxCombo(this.__wbg_ptr); return ret >>> 0; } } module.exports.DifficultyAttributes = DifficultyAttributes; const GradualDifficultyFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_gradualdifficulty_free(ptr >>> 0, 1)); /** * Gradually calculate difficulty attributes after each hitobject. */ class GradualDifficulty { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(GradualDifficulty.prototype); obj.__wbg_ptr = ptr; GradualDifficultyFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; GradualDifficultyFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_gradualdifficulty_free(ptr, 0); } /** * @param {Difficulty} difficulty * @param {Beatmap} map */ constructor(difficulty, map) { _assertClass(difficulty, Difficulty); _assertClass(map, Beatmap); const ret = wasm.difficulty_gradualDifficulty(difficulty.__wbg_ptr, map.__wbg_ptr); this.__wbg_ptr = ret >>> 0; GradualDifficultyFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Advances the iterator and returns the next attributes. * @returns {DifficultyAttributes | undefined} */ next() { const ret = wasm.gradualdifficulty_next(this.__wbg_ptr); return ret === 0 ? undefined : DifficultyAttributes.__wrap(ret); } /** * Returns the `n`th attributes of the iterator. * * Note that the count starts from zero, so `nth(0)` returns the first * value, `nth(1)` the second, and so on. * @param {number} n * @returns {DifficultyAttributes | undefined} */ nth(n) { const ret = wasm.gradualdifficulty_nth(this.__wbg_ptr, n); return ret === 0 ? undefined : DifficultyAttributes.__wrap(ret); } /** * Advances the iterator to the end to collect all remaining attributes * into a list and return them. * @returns {DifficultyAttributes[]} */ collect() { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.gradualdifficulty_collect(retptr, ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); wasm.__wbindgen_export_3(r0, r1 * 4, 4); return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the amount of remaining items. * @returns {number} */ get nRemaining() { const ret = wasm.gradualdifficulty_nRemaining(this.__wbg_ptr); return ret >>> 0; } } module.exports.GradualDifficulty = GradualDifficulty; const GradualPerformanceFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_gradualperformance_free(ptr >>> 0, 1)); /** * Gradually calculate performance attributes after each hitresult. */ class GradualPerformance { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(GradualPerformance.prototype); obj.__wbg_ptr = ptr; GradualPerformanceFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; GradualPerformanceFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_gradualperformance_free(ptr, 0); } /** * @param {Difficulty} difficulty * @param {Beatmap} map */ constructor(difficulty, map) { _assertClass(difficulty, Difficulty); _assertClass(map, Beatmap); const ret = wasm.difficulty_gradualPerformance(difficulty.__wbg_ptr, map.__wbg_ptr); this.__wbg_ptr = ret >>> 0; GradualPerformanceFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Process the next hit object and calculate the performance attributes * for the resulting score state. * @param {ScoreState} state * @returns {PerformanceAttributes | undefined} */ next(state) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);