-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.cs
170 lines (153 loc) · 6.45 KB
/
Converter.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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace osu_8K_to_7K_Converter
{
public class Converter
{
private static string[] fileContents;
public static bool convertSounds = false;
private class Chart
{
internal List<string> events = new List<string>();
internal List<string> timingPoints = new List<string>();
internal List<string> notes = new List<string>();
internal List<string> other = new List<string>(); // Lines of file not being altered.
}
public static void Convert(string file)
{
bool writeNotes = false;
bool writeEvents = false;
bool writeTimingPoints = false;
Chart chart = new Chart();
try
{
fileContents = File.ReadAllLines(file);
// Separate file into lists.
foreach (string line in fileContents)
{
switch (line)
{
case string a when a.Contains("[Events]"):
writeEvents = true;
continue;
case string b when b.Contains("[TimingPoints]"):
writeEvents = false;
writeTimingPoints = true;
continue;
case string c when c.Contains("[HitObjects]"):
writeTimingPoints = false;
writeNotes = true;
continue;
}
if (writeEvents)
{
chart.events.Add(line);
}
else if (writeTimingPoints)
{
chart.timingPoints.Add(line);
}
else if (writeNotes)
{
chart.notes.Add(line);
}
else
{
chart.other.Add(line);
}
}
// Write new version name and set key count to 7.
for (int i = 0; i < chart.other.Count; i++)
{
if (chart.other[i].Contains("Version:"))
{
chart.other[i] = $"{chart.other[i]} converted";
}
if (chart.other[i].Contains("CircleSize:"))
{
chart.other[i] = "CircleSize: 7";
break;
}
}
#region Convert keysounds to storyboard if specified.
if (convertSounds)
{
for (int i = 0; i < chart.notes.Count; i++)
{
/* Hit object syntax: x,y,time,type,hitSound,objectParams,hitSample
* Hold syntax: x,y,time,type,hitSound,endTime: hitSample
* Hit sample syntax: normalSet:additionSet:index:volume:filename */
string[] note = chart.notes[i].Split(',');
string x = note[0];
string y = note[1];
string time = note[2];
string type = note[3];
string hitSound = note[4];
string hitSample = note[note.Length - 1];
string volume;
string filename;
bool isLongNote = false;
if (System.Convert.ToInt32(hitSample.Split(':')[0]) > 3)
{
isLongNote = true;
}
if (isLongNote == true)
{
string endTime = hitSample.Split(':')[0];
volume = hitSample.Split(':')[4];
filename = hitSample.Split(':')[5];
chart.events.Add($"5,{time},0,\"{filename}\",{volume}");
chart.notes[i] = $"{x},{y},{time},{type},{hitSound},{endTime}:0:0:0:0:";
}
else
{
volume = hitSample.Split(':')[3];
filename = hitSample.Split(':')[4];
chart.events.Add($"5,{time},0,\"{filename}\",{volume}");
chart.notes[i] = $"{x},{y},{time},{type},{hitSound},0:0:0:0:";
}
}
}
#endregion Convert keysounds to storyboard if specified.
// Note Conversion.
for (int i = 0; i < chart.notes.Count; i++)
{
string[] note = chart.notes[i].Split(',');
Double.TryParse(note[0], out double xval);
// floor(x * columnNumber / 512)
int columnIndex = (int)Math.Floor(xval * 8 / 512);
string[] newColumn = {"36", "109", "182", "256", "329", "402", "475"};
if (columnIndex == 0) // Remove scratch note.
{
chart.notes.RemoveAt(i);
i--;
}
else if (columnIndex >= 1 && columnIndex <= 7)
{
note[0] = newColumn[columnIndex-1];
chart.notes[i] = string.Join(",", note);
}
}
// Write new file.
string fileName = Path.GetFileName(file);
using (StreamWriter output = new StreamWriter($"{Path.GetDirectoryName(file)}//[7K] {fileName}"))
{
chart.other.ForEach(output.WriteLine);
output.WriteLine("[Events]");
chart.events.ForEach(output.WriteLine);
output.WriteLine("[TimingPoints]");
chart.timingPoints.ForEach(output.WriteLine);
output.WriteLine("[HitObjects]");
chart.notes.ForEach(output.WriteLine);
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return;
}
}
}
}