This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectHighlight.cs
109 lines (103 loc) · 4.54 KB
/
ObjectHighlight.cs
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
using OpenTK;
using StorybrewCommon.Mapset;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Storyboarding.CommandValues;
using StorybrewCommon.Animations;
using System;
namespace StorybrewScripts
{
class ObjectHighlight : StoryboardObjectGenerator
{
public override void Generate()
{
Cursor(88200, 109810);
Cursor(153285, 173539, true);
Cursor(174980, 196590);
Cursor(196675, 218285, true);
}
void Cursor(int StartTime, int EndTime, bool pixels = false)
{
var cursorLayer = GetLayer("");
var sprite = cursorLayer.CreateSprite(pixels ? "sb/p.png" : "sb/hl.png");
sprite.Fade(StartTime, StartTime + 1000, 0, 0.6);
sprite.Fade(EndTime, EndTime + 1000, 0.6, 0);
sprite.Scale(StartTime, 70);
sprite.Additive(StartTime);
sprite.Color(StartTime, "#BC62F5");
sprite.Rotate(StartTime, Math.PI / 4);
Action<OsuHitObject> GetSliderMovement = objects =>
{
var keyframe = new KeyframedValue<Vector2>(null);
var timeStep = Beatmap.GetTimingPointAt((int)objects.StartTime).BeatDuration / 64;
var startTime = objects.StartTime;
while (true)
{
var endTime = startTime + timeStep;
var complete = objects.EndTime - startTime < 1;
if (complete) endTime = objects.EndTime;
keyframe.Add(startTime, objects.PositionAtTime(startTime));
if (complete) break;
startTime += timeStep;
}
if (pixels) keyframe.Simplify2dKeyframes(1.5, v => v);
keyframe.ForEachPair((start, end) =>
{
sprite.Move(start.Time, end.Time, start.Value, end.Value);
});
};
OsuHitObject lastObj = null;
foreach (var hit in Beatmap.HitObjects)
{
if (hit.StartTime >= StartTime - 5 && hit.StartTime <= EndTime + 5)
{
if (lastObj == null)
{
if (hit is OsuSlider) GetSliderMovement(hit);
}
else
{
if (lastObj is OsuSlider)
{
if (lastObj.EndPosition != hit.Position) sprite.Move(OsbEasing.Out, lastObj.EndTime, hit.StartTime, lastObj.EndPosition, hit.Position);
sprite.Rotate(OsbEasing.Out, lastObj.EndTime, hit.StartTime, Math.PI / 4, -Math.PI / 4);
}
else if (lastObj is OsuCircle)
{
if (lastObj.Position != hit.Position) sprite.Move(OsbEasing.Out, lastObj.StartTime, hit.StartTime, lastObj.Position, hit.Position);
sprite.Rotate(OsbEasing.Out, lastObj.EndTime, hit.StartTime, -Math.PI / 4, Math.PI / 4);
}
if (hit is OsuSlider)
{
GetSliderMovement(hit);
}
}
lastObj = hit;
}
}
using (var pool = new SpritePool(GetLayer(""), pixels ? "sb/p.png" : "sb/hl.png", (pooledSprite, start, end) =>
{
pooledSprite.Scale(start, pixels ? 5 : 0.35);
pooledSprite.Color(start, pixels ? "#BC62F5" : "#7FACF5");
pooledSprite.Additive(start);
if (pixels) pooledSprite.Rotate(start, Math.PI / 4);
}))
{
var lastPos = new CommandPosition(0, 0);
for (var i = StartTime; i < EndTime; i += (int)Beatmap.GetTimingPointAt(StartTime).BeatDuration / 24)
{
var pos = sprite.PositionAt(i);
if (pos != lastPos)
{
var trail = pool.Get(i, i + (pixels ? 1000 : 750));
if (pixels) trail.Move(OsbEasing.InBack, i, i + 1000, pos, new Vector2(pos.X, pos.Y + 150));
else trail.Move(i, pos);
trail.Fade(i, i + (pixels ? 1000 : 750), pixels ? 0.5 : 0.3, 0);
}
lastPos = pos;
}
}
if (!pixels) cursorLayer.Discard(sprite);
}
}
}