-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lyrics.cs
112 lines (94 loc) · 5.2 KB
/
Lyrics.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
110
111
112
using OpenTK;
using OpenTK.Graphics;
using StorybrewCommon.Mapset;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Storyboarding.Util;
using StorybrewCommon.Subtitles;
using System;
using System.IO;
using static StorybrewCommon.Assets;
namespace StorybrewScripts
{
public class Lyrics : StoryboardObjectGenerator
{
[Configurable] public bool romanized = false;
public override void Generate() {
var l = GetLayer(LAYER_LYRIC);
var beat = (int)Beatmap.GetTimingPointAt(0).BeatDuration;
var path = $"{ProjectPath}/assetlibrary/" + (romanized ? "lyric romanized" : "lyric") + ".txt";
var position = new Vector2(20, 390);
AddDependency(path);
var font = LoadFont(FOLDER_FONT, new FontDescription() {
FontPath = "assetlibrary/KFhimaji.otf",
FontSize = 46,
Color = Color4.White
}
);
var stars = new OsbSpritePool(l, HUD_STAR, OsbOrigin.Centre);
foreach (var line in File.ReadAllLines(path)) {
var arg = line.Split(new[] {' '}, 2);
int o; if (!String.IsNullOrEmpty(arg[0]) & int.TryParse(arg[0], out o)) {
var startTime = int.Parse(arg[0]) + OFFSET;
var endTime = startTime;
var text = arg[1];
var width = 0f;
var starDelay = 0;
var fadeInDelay = 0;
var fadeOutDelay = 0;
var letterX = 0f;
foreach (var letter in text) {
if (letter == '-') endTime += beat/4;
if (letter != '-') width += font.GetTexture(letter.ToString()).BaseWidth * .5f;
}
// Stars
for (var i=0; i<width; i+=15) {
var random = Random(-200, 100);
var StartTime = startTime + random;
var EndTime = endTime + random;
var startDir = Random(Math.PI*4);
var endDir = startDir + Random(-Math.PI, Math.PI);
var startPos = new Vector2(position.X + i + Random(-8, 8), position.Y + 15 + Random(-16, 16));
var endPos = new Vector2(
startPos.X + (float)Math.Sin(Random(Math.PI*2)) * 10,
startPos.Y + (float)Math.Cos(Random(Math.PI*2)) * 10
);
var s = stars.Get(StartTime + starDelay, EndTime + starDelay + 500);
if (!s.AdditiveAt(StartTime + starDelay))
s.Additive(StartTime + starDelay);
if (s.ScaleAt(StartTime + starDelay).X != .5f)
s.Scale(StartTime + starDelay, .5f);
s.Move (StartTime + starDelay, EndTime + starDelay + 500, startPos, endPos);
s.Rotate(StartTime + starDelay, EndTime + starDelay + 500, startDir, endDir);
s.Fade (StartTime + starDelay, StartTime+ starDelay + 300, 0, .4f);
s.Fade (EndTime + starDelay, EndTime + starDelay + 500, .4f, 0);
starDelay += 100;
}
// Texts
foreach (var letter in text) {
var texture = font.GetTexture(letter.ToString());
if (!texture.IsEmpty & letter != '-') {
var distance = (endTime - startTime) / beat / 2;
var startDir = 0;
var endDir = startDir + Random(-Math.PI/24, Math.PI/24);
var startPos = new Vector2(position.X + letterX, position.Y) + texture.OffsetFor(OsbOrigin.Centre) * .5f;
var endPos = new Vector2(
startPos.X + (float)Math.Sin(Random(Math.PI)) * distance,
startPos.Y + (float)Math.Cos(Random(Math.PI)) * (distance + 1) /* More vertical movement */
);
var s = l.CreateSprite(texture.Path, OsbOrigin.Centre, startPos);
s.Scale (startTime + fadeInDelay - 200, .5f);
s.Move (startTime + fadeInDelay - 200, endTime + fadeInDelay, startPos, endPos);
s.Fade (startTime + fadeInDelay - 200, startTime+ fadeInDelay, 0, .9);
s.Fade (endTime + fadeOutDelay- 200, endTime + fadeOutDelay, .9, 0);
s.Rotate(OsbEasing.OutElasticHalf, startTime + fadeInDelay - 200, startTime + fadeInDelay + 2000, startDir, endDir);
}
fadeOutDelay += 5;
if (letter != '-') letterX += texture.BaseWidth * .5f;
if (letter == '-') fadeInDelay += beat/4;
}
}
}
}
}
}