@rian8337/osu-base 1.0.0

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/beatmap/Beatmap.js +223 -0
  4. package/dist/beatmap/Parser.js +620 -0
  5. package/dist/beatmap/hitobjects/Circle.js +20 -0
  6. package/dist/beatmap/hitobjects/HitObject.js +74 -0
  7. package/dist/beatmap/hitobjects/Slider.js +143 -0
  8. package/dist/beatmap/hitobjects/Spinner.js +26 -0
  9. package/dist/beatmap/hitobjects/sliderObjects/HeadCircle.js +10 -0
  10. package/dist/beatmap/hitobjects/sliderObjects/RepeatPoint.js +21 -0
  11. package/dist/beatmap/hitobjects/sliderObjects/SliderTick.js +21 -0
  12. package/dist/beatmap/hitobjects/sliderObjects/TailCircle.js +10 -0
  13. package/dist/beatmap/timings/BreakPoint.js +34 -0
  14. package/dist/beatmap/timings/DifficultyControlPoint.js +22 -0
  15. package/dist/beatmap/timings/TimingControlPoint.js +22 -0
  16. package/dist/beatmap/timings/TimingPoint.js +12 -0
  17. package/dist/constants/ParserConstants.js +19 -0
  18. package/dist/constants/PathType.js +13 -0
  19. package/dist/constants/modes.js +11 -0
  20. package/dist/constants/objectTypes.js +12 -0
  21. package/dist/constants/rankedStatus.js +16 -0
  22. package/dist/index.js +64 -0
  23. package/dist/mathutil/Interpolation.js +9 -0
  24. package/dist/mathutil/MathUtils.js +41 -0
  25. package/dist/mathutil/Vector2.js +79 -0
  26. package/dist/mods/Mod.js +9 -0
  27. package/dist/mods/ModAuto.js +21 -0
  28. package/dist/mods/ModAutopilot.js +21 -0
  29. package/dist/mods/ModDoubleTime.js +21 -0
  30. package/dist/mods/ModEasy.js +21 -0
  31. package/dist/mods/ModFlashlight.js +21 -0
  32. package/dist/mods/ModHalfTime.js +21 -0
  33. package/dist/mods/ModHardRock.js +21 -0
  34. package/dist/mods/ModHidden.js +21 -0
  35. package/dist/mods/ModNightCore.js +21 -0
  36. package/dist/mods/ModNoFail.js +21 -0
  37. package/dist/mods/ModPerfect.js +21 -0
  38. package/dist/mods/ModPrecise.js +21 -0
  39. package/dist/mods/ModReallyEasy.js +21 -0
  40. package/dist/mods/ModRelax.js +21 -0
  41. package/dist/mods/ModScoreV2.js +21 -0
  42. package/dist/mods/ModSmallCircle.js +21 -0
  43. package/dist/mods/ModSpunOut.js +21 -0
  44. package/dist/mods/ModSuddenDeath.js +21 -0
  45. package/dist/mods/ModTouchDevice.js +21 -0
  46. package/dist/tools/MapInfo.js +559 -0
  47. package/dist/utils/APIRequestBuilder.js +144 -0
  48. package/dist/utils/Accuracy.js +96 -0
  49. package/dist/utils/HitWindow.js +56 -0
  50. package/dist/utils/MapStats.js +212 -0
  51. package/dist/utils/ModUtil.js +137 -0
  52. package/dist/utils/PathApproximator.js +269 -0
  53. package/dist/utils/Precision.js +31 -0
  54. package/dist/utils/SliderPath.js +187 -0
  55. package/dist/utils/Utils.js +53 -0
  56. package/package.json +43 -0
  57. package/typings/index.d.ts +1951 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Rian8337
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `osu-base`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const osuBase = require('osu-base');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Beatmap = void 0;
4
+ const Slider_1 = require("./hitobjects/Slider");
5
+ /**
6
+ * Represents a beatmap with advanced information.
7
+ */
8
+ class Beatmap {
9
+ constructor() {
10
+ /**
11
+ * The format version of the beatmap.
12
+ */
13
+ this.formatVersion = 1;
14
+ /**
15
+ * The title of the song of the beatmap.
16
+ */
17
+ this.title = "";
18
+ /**
19
+ * The unicode title of the song of the beatmap.
20
+ */
21
+ this.titleUnicode = "";
22
+ /**
23
+ * The artist of the song of the beatmap.
24
+ */
25
+ this.artist = "";
26
+ /**
27
+ * The unicode artist of the song of the beatmap.
28
+ */
29
+ this.artistUnicode = "";
30
+ /**
31
+ * The creator of the beatmap.
32
+ */
33
+ this.creator = "";
34
+ /**
35
+ * The difficulty name of the beatmap.
36
+ */
37
+ this.version = "";
38
+ /**
39
+ * The circle size of the beatmap.
40
+ */
41
+ this.cs = 5;
42
+ /**
43
+ * The overall difficulty of the beatmap.
44
+ */
45
+ this.od = 5;
46
+ /**
47
+ * The health drain rate of the beatmap.
48
+ */
49
+ this.hp = 5;
50
+ /**
51
+ * The slider velocity of the beatmap.
52
+ */
53
+ this.sv = 1;
54
+ /**
55
+ * The slider tick rate of the beatmap.
56
+ */
57
+ this.tickRate = 1;
58
+ /**
59
+ * The amount of circles in the beatmap.
60
+ */
61
+ this.circles = 0;
62
+ /**
63
+ * The amount of sliders in the beatmap.
64
+ */
65
+ this.sliders = 0;
66
+ /**
67
+ * The amount of spinners in the beatmap.
68
+ */
69
+ this.spinners = 0;
70
+ /**
71
+ * The objects of the beatmap.
72
+ */
73
+ this.objects = [];
74
+ /**
75
+ * The timing points of the beatmap.
76
+ */
77
+ this.timingPoints = [];
78
+ /**
79
+ * The difficulty timing points of the beatmap.
80
+ */
81
+ this.difficultyTimingPoints = [];
82
+ /**
83
+ * The break points of the beatmap.
84
+ */
85
+ this.breakPoints = [];
86
+ /**
87
+ * The stack leniency of the beatmap.
88
+ */
89
+ this.stackLeniency = 0.7;
90
+ }
91
+ /**
92
+ * The amount of slider ticks in the beatmap.
93
+ */
94
+ get sliderTicks() {
95
+ const sliders = (this.objects.filter((v) => v instanceof Slider_1.Slider));
96
+ return sliders
97
+ .map((v) => v.ticks)
98
+ .reduce((acc, value) => acc + value, 0);
99
+ }
100
+ /**
101
+ * The amount of sliderends in the beatmap.
102
+ */
103
+ get sliderEnds() {
104
+ return this.sliders;
105
+ }
106
+ /**
107
+ * The amount of slider repeat points in the beatmap.
108
+ */
109
+ get sliderRepeatPoints() {
110
+ const sliders = (this.objects.filter((v) => v instanceof Slider_1.Slider));
111
+ return sliders
112
+ .map((v) => v.repeatPoints)
113
+ .reduce((acc, value) => acc + value, 0);
114
+ }
115
+ /**
116
+ * The maximum combo of the beatmap.
117
+ */
118
+ get maxCombo() {
119
+ return (this.circles +
120
+ this.sliders +
121
+ this.sliderTicks +
122
+ this.sliderRepeatPoints +
123
+ this.sliderEnds +
124
+ this.spinners);
125
+ }
126
+ /**
127
+ * Returns a time combined with beatmap-wide time offset.
128
+ *
129
+ * BeatmapVersion 4 and lower had an incorrect offset. Stable has this set as 24ms off.
130
+ *
131
+ * @param time The time.
132
+ */
133
+ getOffsetTime(time) {
134
+ return time + (this.formatVersion < 5 ? 24 : 0);
135
+ }
136
+ /**
137
+ * Gets the timing control point that applies at a given time.
138
+ *
139
+ * @param time The time.
140
+ */
141
+ timingControlPointAt(time) {
142
+ return this.getTimingPoint(time, this.timingPoints);
143
+ }
144
+ /**
145
+ * Gets the difficulty control point that applies at a given time.
146
+ *
147
+ * @param time The time.
148
+ */
149
+ difficultyControlPointAt(time) {
150
+ return this.getTimingPoint(time, this.difficultyTimingPoints);
151
+ }
152
+ /**
153
+ * Gets the timing point that applies at a given time.
154
+ *
155
+ * @param time The time.
156
+ * @param list The timing points to search in.
157
+ */
158
+ getTimingPoint(time, list) {
159
+ if (list.length === 0) {
160
+ throw new Error("No timing points have been loaded");
161
+ }
162
+ if (time < list[0].time) {
163
+ return list[0];
164
+ }
165
+ if (time >= list.at(-1).time) {
166
+ return list.at(-1);
167
+ }
168
+ let l = 0;
169
+ let r = list.length - 2;
170
+ while (l <= r) {
171
+ const pivot = l + ((r - l) >> 1);
172
+ if (list[pivot].time < time) {
173
+ l = pivot + 1;
174
+ }
175
+ else if (list[pivot].time > time) {
176
+ r = pivot - 1;
177
+ }
178
+ else {
179
+ return list[pivot];
180
+ }
181
+ }
182
+ // l will be the first control point with time > list[l].time, but we want the one before it
183
+ return list[l - 1];
184
+ }
185
+ /**
186
+ * Returns a string representative of the class.
187
+ */
188
+ toString() {
189
+ let res = this.artist + " - " + this.title + " [";
190
+ if (this.titleUnicode || this.artistUnicode) {
191
+ res += "(" + this.artistUnicode + " - " + this.titleUnicode + ")";
192
+ }
193
+ res +=
194
+ this.version +
195
+ "] mapped by " +
196
+ this.creator +
197
+ "\n" +
198
+ "\n" +
199
+ "AR" +
200
+ parseFloat(this.ar.toFixed(2)) +
201
+ " " +
202
+ "OD" +
203
+ parseFloat(this.od.toFixed(2)) +
204
+ " " +
205
+ "CS" +
206
+ parseFloat(this.cs.toFixed(2)) +
207
+ " " +
208
+ "HP" +
209
+ parseFloat(this.hp.toFixed(2)) +
210
+ "\n" +
211
+ this.circles +
212
+ " circles, " +
213
+ this.sliders +
214
+ " sliders, " +
215
+ this.spinners +
216
+ " spinners" +
217
+ "\n" +
218
+ this.maxCombo +
219
+ " max combo";
220
+ return res;
221
+ }
222
+ }
223
+ exports.Beatmap = Beatmap;