-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapWrapper.cs
More file actions
366 lines (315 loc) · 12.7 KB
/
MapWrapper.cs
File metadata and controls
366 lines (315 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using Parser.Map;
using Parser.Map.Difficulty.V3.Base;
using Parser.Map.Difficulty.V3.Grid;
using System.Numerics;
namespace MapPostprocessor
{
public class MapWrapper
{
public DifficultySet Difficulty { get; set; }
public List<NoteWrapper> Notes { get; set; }
public List<BombWrapper> Bombs { get; set; }
public List<WallWrapper> Walls { get; set; }
public List<ChainWrapper> Chains { get; set; }
private bool CompareSlider(Note note, BeatmapColorGridObjectWithTail slider) {
if (Math.Round(note.BpmTime, 2) != Math.Round(slider.BpmTime, 2)) return false;
if (note.x == slider.x && note.y == slider.y)
return true;
if (note.customData != null && note.customData.coordinates != null)
{
if (slider.customData != null && slider.customData.coordinates != null)
{
if (
Math.Round(note.customData.coordinates[0], 2) == Math.Round(slider.customData.coordinates[0], 2) &&
Math.Round(note.customData.coordinates[1], 2) == Math.Round(slider.customData.coordinates[1], 2))
return true;
} else
{
if (
Math.Round(note.customData.coordinates[0] + 4 / 2) == slider.x &&
Math.Round(note.customData.coordinates[1]) == slider.y
)
return true;
}
}
return false;
}
private bool CompareSliderTail(Note note, BeatmapColorGridObjectWithTail slider) {
if (Math.Round(note.BpmTime, 2) != Math.Round(slider.TailBpmTime, 2)) return false;
if (note.x == slider.tx && note.y == slider.ty)
return true;
if (note.customData != null && note.customData.coordinates != null)
{
if (slider.customData != null && slider.customData.tailCoordinates != null)
{
if (
Math.Round(note.customData.coordinates[0], 2) == Math.Round(slider.customData.tailCoordinates[0], 2) &&
Math.Round(note.customData.coordinates[1], 2) == Math.Round(slider.customData.tailCoordinates[1], 2))
return true;
} else
{
if (
Math.Round(note.customData.coordinates[0] + 4 / 2) == slider.tx &&
Math.Round(note.customData.coordinates[1]) == slider.ty
)
return true;
}
}
return false;
}
private float LerpUnclamped(float a, float b, float t) {
return a + (b - a) * t;
}
public static void BezierCurve(
Vector2 p0,
Vector2 p1,
Vector2 p2,
float t,
out Vector2 pos,
out Vector2 tangent) {
float num = 1f - t;
pos = num * num * p0 + 2f * num * t * p1 + t * t * p2;
tangent = (float)(2.0 * (1.0 - (double)t)) * (p1 - p0) + 2f * t * (p2 - p1);
}
private void AddScoringTypeAndChains(DifficultyV3 difficulty) {
foreach (var note in Notes) {
if (note.Note.Color == 1 || note.Note.Color == 0) {
note.ScoringType = ScoringType.Normal;
} else {
note.ScoringType = ScoringType.NoScore;
}
}
foreach (var slider in difficulty.Arcs) {
var head = Notes.FirstOrDefault(n => CompareSlider(n.Note, slider));
if (head != null) {
if (head.ScoringType == ScoringType.Normal) {
head.ScoringType = ScoringType.ArcHead;
} else if (head.ScoringType == ScoringType.ArcTail) {
head.ScoringType = ScoringType.ArcHeadArcTail;
}
}
var tail = Notes.FirstOrDefault(n => CompareSliderTail(n.Note, slider));
//if (head) {
// head.tail = tail;
//}
//slider.tail = tail;
if (tail != null) {
if (tail.ScoringType == ScoringType.Normal) {
tail.ScoringType = ScoringType.ArcTail;
} else if (tail.ScoringType == ScoringType.ArcHead) {
tail.ScoringType = ScoringType.ArcHeadArcTail;
}
}
}
var chains = new List<ChainWrapper>();
foreach (var slider in difficulty.Chains) {
var head = Notes.FirstOrDefault(n => CompareSlider(n.Note, slider));
if (head != null) {
if (head.ScoringType == ScoringType.Normal) {
head.ScoringType = ScoringType.ChainHead;
} else if (head.ScoringType == ScoringType.ArcTail) {
head.ScoringType = ScoringType.ChainHeadArcTail;
} else if (head.ScoringType == ScoringType.ArcHead) {
head.ScoringType = ScoringType.ChainHeadArcHead;
} else if (head.ScoringType == ScoringType.ArcHeadArcTail) {
head.ScoringType = ScoringType.ChainHeadArcHeadArcTail;
}
//head.sliderhead = slider;
}
for (var i = 1; i < slider.SliceCount; ++i) {
var chain = new Note {
x = slider.x,
y = slider.y,
CutDirection = 8,
Color = slider.Color,
};
chain.Seconds = LerpUnclamped(slider.Seconds, slider.TailInSeconds, i / (slider.SliceCount - 1));
Vector3 vector3_1 = new Vector3(head.X, head.Y, 0f);
float horizontalPosition = slider.tx;
if (slider.customData?.tailCoordinates != null) {
horizontalPosition = slider.customData?.tailCoordinates[0] + 4 / 2 ?? 0;
}
if (horizontalPosition <= -1000 || horizontalPosition >= 1000) {
horizontalPosition = horizontalPosition < 0 ? horizontalPosition / 1000 + 1 : horizontalPosition / 1000 - 1;
}
float tailX = GenericWrapper<BeatmapGridObject>.GetHorizontalPosition(horizontalPosition);
float verticalPosition = slider.ty;
if (slider.customData?.tailCoordinates != null) {
verticalPosition = slider.customData?.tailCoordinates[1] ?? 0;
}
if (verticalPosition <= -1000 || verticalPosition >= 1000) {
verticalPosition = verticalPosition < 0 ? verticalPosition / 1000 + 1 : verticalPosition / 1000 - 1;
}
float tailY = GenericWrapper<BeatmapGridObject>.HighestJumpPosYForLineLayer(verticalPosition);
Vector3 vector3_2 = new Vector3(tailX, tailY, 0f);
Vector2 p2 = new Vector2(vector3_2.X - vector3_1.X, vector3_2.Y - vector3_1.Y);
float magnitude = p2.Length();
float f = (float)(((double)NoteCutDirectionExtensions.RotationAngle((NoteCutDirection)slider.CutDirection) - 90.0 + (double)head.cutDirectionAngleOffset) * (Math.PI / 180.0));
Vector2 p1 = (0.5f * magnitude * new Vector2((float)Math.Cos(f), (float)Math.Sin(f)));
int sliceCount = slider.SliceCount;
float squishAmount = slider.Squish;
var index = i;
float t = (float)index / (float)(sliceCount - 1);
Vector2 pos;
Vector2 tangent;
BezierCurve(new Vector2(0.0f, 0.0f), p1, p2, t * squishAmount, out pos, out tangent);
var arcSlider = difficulty.Arcs.FirstOrDefault(n => CompareSlider(chain, n));
chains.Add(new ChainWrapper {
Note = chain,
SliceIndex = i,
ScoringType = arcSlider != null ? ScoringType.ChainLinkArcHead : ScoringType.ChainLink,
chainRotation = NoteCutDirectionExtensions.SignedAngle(new Vector2(0.0f, -1f), tangent),
chainX = pos.X,
chainY = pos.Y,
});
}
}
Chains = chains;
}
public void SetIds() {
var allElements = new List<IWrapper<BeatmapGridObject>>();
allElements.AddRange(Notes);
allElements.AddRange(Bombs);
allElements.AddRange(Chains);
foreach (var mapnote in allElements) {
var lineIndex = mapnote.LineIndex;
var lineLayer = mapnote.LineLayer;
var colorType = mapnote.Color;
var cutDirection = mapnote.CutDirection;
var scoringType = mapnote.ScoringType + 2;
var id = lineIndex * 1000 + lineLayer * 100 + colorType * 10 + cutDirection;
mapnote.Id = id;
mapnote.IdWithScoring = id + (int)scoringType * 10000;
var altscoringType = scoringType;
var legacyScoringType = scoringType;
if (mapnote.ScoringType == ScoringType.ChainHead) {
altscoringType = ScoringType.ArcHead + 2;
} else if (mapnote.ScoringType == ScoringType.ArcHead) {
altscoringType = ScoringType.ChainHead + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcTail) {
altscoringType = ScoringType.ArcTail + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcHead) {
altscoringType = ScoringType.ArcHead + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcHeadArcTail) {
altscoringType = ScoringType.ArcTail + 2;
} else if (mapnote.ScoringType == ScoringType.ChainLinkArcHead) {
altscoringType = ScoringType.ChainLink + 2;
} else if (mapnote.ScoringType == ScoringType.ArcHeadArcTail) {
altscoringType = ScoringType.ArcHead + 2;
}
if (mapnote.ScoringType == ScoringType.ArcHeadArcTail) {
legacyScoringType = ScoringType.ArcTail + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcTail) {
legacyScoringType = ScoringType.ChainHead + 2;
} else if (mapnote.ScoringType == ScoringType.ChainLinkArcHead) {
legacyScoringType = ScoringType.ChainLink + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcHead) {
legacyScoringType = ScoringType.ChainHead + 2;
} else if (mapnote.ScoringType == ScoringType.ChainHeadArcHeadArcTail) {
legacyScoringType = ScoringType.ChainHead + 2;
}
mapnote.IdWithAlternativeScoring = id + (int)altscoringType * 10000;
mapnote.IdWithLegacyScoring = id + (int)legacyScoringType * 10000;
}
}
private static float getVerticalPosition(float lineLayer) {
return 0.25f + 0.6f * lineLayer;
}
private static float getHorizontalPosition(float lineIndex) {
return (-(4 - 1) * 0.5f + lineIndex) * 0.6f;
}
private static Vector2 get2DNoteOffset(float noteLineIndex, float noteLineLayer) {
return new Vector2(getHorizontalPosition(noteLineIndex), getVerticalPosition(noteLineLayer));
}
public static float SignedAngleToLine(Vector2 vec, Vector2 line)
{
float f1 = NoteCutDirectionExtensions.SignedAngle(vec, line);
float f2 = NoteCutDirectionExtensions.SignedAngle(vec, -line);
return (double) Math.Abs(f1) >= (double) Math.Abs(f2) ? f2 : f1;
}
private static void processNotesByColorType(List<NoteWrapper> notesWithTheSameColorTypeList) {
if (notesWithTheSameColorTypeList.Count != 2) return;
var theSameColorType1 = notesWithTheSameColorTypeList[0];
var theSameColorType2 = notesWithTheSameColorTypeList[1];
if (
theSameColorType1.CutDirection != theSameColorType2.CutDirection &&
theSameColorType1.CutDirection != (int)NoteCutDirection.Any &&
theSameColorType2.CutDirection != (int)NoteCutDirection.Any
)
return;
NoteWrapper noteData1;
NoteWrapper noteData2;
if (theSameColorType1.CutDirection != 8) {
noteData1 = theSameColorType1;
noteData2 = theSameColorType2;
} else {
noteData1 = theSameColorType2;
noteData2 = theSameColorType1;
}
var line1 = get2DNoteOffset(noteData2.LineIndex, noteData2.LineLayer) - get2DNoteOffset(noteData1.LineIndex, noteData1.LineLayer);
var line2 = SignedAngleToLine(
noteData1.CutDirection == (int)NoteCutDirection.Any ? new Vector2(0.0f, 1f) : NoteCutDirectionExtensions.Direction((NoteCutDirection)noteData1.CutDirection),
line1
);
if (noteData2.CutDirection == (int)NoteCutDirection.Any && noteData1.CutDirection == (int)NoteCutDirection.Any) {
noteData1.cutDirectionAngleOffset = line2;
noteData2.cutDirectionAngleOffset = line2;
} else {
if (Math.Abs(line2) > 40) return;
noteData1.cutDirectionAngleOffset = line2;
if (noteData2.CutDirection == (int)NoteCutDirection.Any && noteData1.CutDirection > (int)NoteCutDirection.Right) {
noteData2.cutDirectionAngleOffset = line2 + 45;
} else {
noteData2.cutDirectionAngleOffset = line2;
}
}
}
private static void processTimingGroups(MapWrapper map) {
List<NoteWrapper>? group = null;
List<NoteWrapper>? previousGroup = null;
float groupTime = 0;
var processGroup = () => {
var leftNotes = new List<NoteWrapper>();
var rightNotes = new List<NoteWrapper>();
if (group != null) {
foreach (var note in group)
{
(note.Color == 1 ? leftNotes : rightNotes).Add(note);
}
processNotesByColorType(leftNotes);
processNotesByColorType(rightNotes);
previousGroup = group;
}
};
var notes = map.Notes;
for (var i = 0; i < notes.Count; i++) {
var note = notes[i];
if (note.Color == 0 || note.Color == 1) {
if (group == null) {
group = [note];
groupTime = note.Note.BpmTime;
} else {
if (Math.Abs(groupTime - note.Note.BpmTime) < 0.0001) {
group.Add(note);
} else {
processGroup();
group = null;
i--;
}
}
}
}
processGroup();
}
public static MapWrapper Process(DifficultySet difficulty) {
var map = new MapWrapper { Difficulty = difficulty };
map.Notes = difficulty.Data.Notes.Select(n => new NoteWrapper { Note = n }).ToList();
map.Bombs = difficulty.Data.Bombs.Select(b => new BombWrapper { Note = b }).ToList();
map.Walls = difficulty.Data.Walls.Select(w => new WallWrapper { Note = w }).ToList();
map.AddScoringTypeAndChains(difficulty.Data);
processTimingGroups(map);
map.SetIds();
return map;
}
}
}