@rian8337/osu-difficulty-calculator 1.0.0 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,106 @@
1
- # `osu-difficulty-calculator`
1
+ # About
2
2
 
3
- > TODO: description
3
+ The difficulty and performance calculator portion of my osu! module that uses the current difficulty and performance algorithm.
4
4
 
5
- ## Usage
5
+ # Features
6
6
 
7
+ This module provides an osu! difficulty and performance calculator that uses the current difficulty and performance algorithm for osu!standard gamemode.
8
+
9
+ An error margin should be expected from difficulty and performance calculator due to differences between C# and TypeScript.
10
+
11
+ # Specific Requirements
12
+
13
+ This module has no specific requirements, however installed modules in installation may have specific requirements. It's advised to check them.
14
+
15
+ # Installation
16
+
17
+ ```
18
+ npm i @rian8337/osu-base @rian8337/osu-difficulty-calculator
19
+ ```
20
+
21
+ or
22
+
23
+ ```
24
+ yarn add @rian8337/osu-base @rian8337/osu-difficulty-calculator
7
25
  ```
8
- const osuDifficultyCalculator = require('osu-difficulty-calculator');
9
26
 
10
- // TODO: DEMONSTRATE API
27
+ # Usage
28
+
29
+ ## General usage
30
+
31
+ ```js
32
+ import { MapInfo } from "@rian8337/osu-base";
33
+ import {
34
+ DroidStarRating,
35
+ MapStars,
36
+ OsuStarRating,
37
+ } from "@rian8337/osu-difficulty-calculator";
38
+
39
+ const beatmapInfo = await MapInfo.getInformation({ beatmapID: 901854 });
40
+
41
+ if (!beatmapInfo.title) {
42
+ return console.log("Beatmap not found");
43
+ }
44
+
45
+ // Calculate osu!droid difficulty
46
+ const droidRating = new DroidStarRating().calculate({
47
+ map: beatmapInfo.map,
48
+ });
49
+
50
+ console.log(droidRating);
51
+
52
+ // Calculate osu!standard difficulty
53
+ const osuRating = new OsuStarRating().calculate({
54
+ map: beatmapInfo.map,
55
+ });
56
+
57
+ console.log(osuRating);
58
+
59
+ // Calculate both osu!droid and osu!standard difficulty
60
+ const rating = new MapStars().calculate({
61
+ map: beatmapInfo.map,
62
+ });
63
+
64
+ // osu!droid difficulty
65
+ console.log(rating.droidStars);
66
+ // osu!standard difficulty
67
+ console.log(rating.pcStars);
68
+ ```
69
+
70
+ ## Specifying parameters
71
+
72
+ Parameters can be applied to alter the result of the calculation:
73
+
74
+ - Mods: Modifications that will be considered when calculating the difficulty of a beatmap. Defaults to none.
75
+ - Custom statistics: Used to apply a custom speed multiplier and force AR. Defaults to none.
76
+
77
+ ```js
78
+ import { MapInfo, MapStats, ModUtil } from "@rian8337/osu-base";
79
+ import { MapStars } from "@rian8337/osu-difficulty-calculator";
80
+
81
+ const beatmapInfo = await MapInfo.getInformation({ beatmapID: 901854 });
82
+
83
+ if (!beatmapInfo.title) {
84
+ return console.log("Beatmap not found");
85
+ }
86
+
87
+ const mods = ModUtil.pcStringToMods("HDHR");
88
+
89
+ const stats = new MapStats({
90
+ ar: 9,
91
+ isForceAR: true,
92
+ speedMultiplier: 1.5,
93
+ });
94
+
95
+ // Also available for `DroidStarRating` and `OsuStarRating`
96
+ const rating = new MapStars().calculate({
97
+ map: beatmapInfo.map,
98
+ mods: mods,
99
+ stats: stats,
100
+ });
101
+
102
+ // osu!droid difficulty
103
+ console.log(rating.droidStars);
104
+ // osu!standard difficulty
105
+ console.log(rating.pcStars);
11
106
  ```
@@ -74,18 +74,16 @@ class DroidPerformanceCalculator extends PerformanceCalculator_1.PerformanceCalc
74
74
  // Combo scaling
75
75
  this.aim *= this.comboPenalty;
76
76
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
77
- let hiddenBonus = 1;
78
77
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModHidden)) {
79
78
  // The bonus starts decreasing twice as fast
80
79
  // beyond AR10 and reaches 1 at AR11.
81
80
  if (calculatedAR > 10) {
82
- hiddenBonus += Math.max(0, 0.08 * (11 - calculatedAR));
81
+ this.aim *= 1 + Math.max(0, 0.08 * (11 - calculatedAR));
83
82
  }
84
83
  else {
85
- hiddenBonus += 0.04 * (12 - calculatedAR);
84
+ this.aim *= 1 + 0.04 * (12 - calculatedAR);
86
85
  }
87
86
  }
88
- this.aim *= hiddenBonus;
89
87
  // AR scaling
90
88
  let arFactor = 0;
91
89
  if (calculatedAR > 10.33) {
@@ -77,11 +77,9 @@ class OsuPerformanceCalculator extends PerformanceCalculator_1.PerformanceCalcul
77
77
  // Buff for longer maps with high AR.
78
78
  this.aim *= 1 + arFactor * lengthBonus;
79
79
  // We want to give more reward for lower AR when it comes to aim and HD. This nerfs high AR and buffs lower AR.
80
- let hiddenBonus = 1;
81
80
  if (this.stars.mods.some((m) => m instanceof osu_base_1.ModHidden)) {
82
- hiddenBonus += 0.04 * (12 - calculatedAR);
81
+ this.aim *= 1 + 0.04 * (12 - calculatedAR);
83
82
  }
84
- this.aim *= hiddenBonus;
85
83
  // Scale the aim value with slider factor to nerf very likely dropped sliderends.
86
84
  this.aim *= this.sliderNerfFactor;
87
85
  // Scale the aim value with accuracy.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rian8337/osu-difficulty-calculator",
3
- "version": "1.0.0",
4
- "description": "A module for calculating osu!standard beatmap difficulty with respect to the current difficulty and performance algorithm.",
3
+ "version": "1.0.5",
4
+ "description": "A module for calculating osu!standard beatmap difficulty and performance value with respect to the current difficulty and performance algorithm.",
5
5
  "keywords": [
6
6
  "osu",
7
7
  "osu-difficulty-calculator"
@@ -21,6 +21,8 @@
21
21
  },
22
22
  "scripts": {
23
23
  "build": "tsc",
24
+ "generate-docs": "typedoc src/index.ts",
25
+ "lint": "eslint --ext ts",
24
26
  "prepare": "npm run build",
25
27
  "test": "jest -i"
26
28
  },
@@ -28,10 +30,10 @@
28
30
  "url": "https://github.com/Rian8337/osu-droid-module/issues"
29
31
  },
30
32
  "dependencies": {
31
- "@rian8337/osu-base": "^1.0.0"
33
+ "@rian8337/osu-base": "^1.0.5"
32
34
  },
33
35
  "publishConfig": {
34
36
  "access": "public"
35
37
  },
36
- "gitHead": "e4fdb9c1ed6f90e70651c1aedfdb964b61cb240d"
38
+ "gitHead": "c8c092485a5ae3be16f2bfa0a3defb00163918d7"
37
39
  }
@@ -1,5 +1,15 @@
1
1
  declare module "@rian8337/osu-difficulty-calculator" {
2
- import { Accuracy, Beatmap, HitObject, MapStats, Mod, modes, OsuHitWindow, Slider, Vector2 } from "@rian8337/osu-base";
2
+ import {
3
+ Accuracy,
4
+ Beatmap,
5
+ HitObject,
6
+ MapStats,
7
+ Mod,
8
+ modes,
9
+ OsuHitWindow,
10
+ Slider,
11
+ Vector2,
12
+ } from "@rian8337/osu-base";
3
13
 
4
14
  //#region Classes
5
15
 
@@ -39,7 +49,7 @@ declare module "@rian8337/osu-difficulty-calculator" {
39
49
  flashlightStrain: number;
40
50
  /**
41
51
  * The normalized distance from the "lazy" end position of the previous hitobject to the start position of this hitobject.
42
- *
52
+ *
43
53
  * The "lazy" end position is the position at which the cursor ends up if the previous hitobject is followed with as minimal movement as possible (i.e. on the edge of slider follow circles).
44
54
  */
45
55
  lazyJumpDistance: number;
@@ -393,6 +403,41 @@ declare module "@rian8337/osu-difficulty-calculator" {
393
403
  protected override saveToHitObject(current: DifficultyHitObject): void;
394
404
  }
395
405
 
406
+ /**
407
+ * A star rating calculator that configures which mode to calculate difficulty for and what mods are applied.
408
+ */
409
+ export class MapStars {
410
+ /**
411
+ * The osu!droid star rating of the beatmap.
412
+ */
413
+ readonly droidStars: DroidStarRating;
414
+ /**
415
+ * The osu!standard star rating of the beatmap.
416
+ */
417
+ readonly pcStars: OsuStarRating;
418
+ /**
419
+ * Calculates the star rating of a beatmap.
420
+ */
421
+ calculate(params: {
422
+ /**
423
+ * The beatmap to calculate.
424
+ */
425
+ map: Beatmap;
426
+ /**
427
+ * Applied modifications.
428
+ */
429
+ mods?: Mod[];
430
+ /**
431
+ * Custom map statistics to apply speed multiplier and force AR values as well as old statistics.
432
+ */
433
+ stats?: MapStats;
434
+ }): MapStars;
435
+ /**
436
+ * Returns a string representative of the class.
437
+ */
438
+ toString(): string;
439
+ }
440
+
396
441
  /**
397
442
  * Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
398
443
  */
@@ -822,7 +867,10 @@ declare module "@rian8337/osu-difficulty-calculator" {
822
867
  /**
823
868
  * Calculates the amount of misses + sliderbreaks from combo.
824
869
  */
825
- private calculateEffectiveMissCount(combo: number, maxCombo: number): number;
870
+ private calculateEffectiveMissCount(
871
+ combo: number,
872
+ maxCombo: number
873
+ ): number;
826
874
  }
827
875
 
828
876
  /**
@@ -945,16 +993,6 @@ declare module "@rian8337/osu-difficulty-calculator" {
945
993
  * Calculates every star rating of the beatmap and stores it in this instance.
946
994
  */
947
995
  abstract calculateAll(): void;
948
- /**
949
- * Generates the strain chart of this beatmap and returns the chart as a buffer.
950
- *
951
- * @param beatmapsetID The beatmapset ID to get background image from. If omitted, the background will be plain white.
952
- * @param color The color of the graph.
953
- */
954
- getStrainChart(
955
- beatmapsetID?: number,
956
- color?: string
957
- ): Promise<Buffer | null>;
958
996
  /**
959
997
  * Returns a string representative of the class.
960
998
  */