This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
196 lines (173 loc) · 4.65 KB
/
Main.hx
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
import DateTools;
import src.WriteBeatmap;
import captain.Command;
import Std.parseFloat;
import src.SearchBeatmap;
import src.EncodeAudio;
import Console;
class Main {
static macro function getDefine(key:String):haxe.macro.Expr {
return macro $v{haxe.macro.Context.definedValue(key)};
}
static macro function getBuildTime() {
return macro $v{DateTools.format(Date.now(), "%Y-%m-%d at %H:%M:%S")};
}
static function main() {
final command = new Command(Sys.args());
command.name = "osu-beatmod";
command.options = [
{
name: "path",
shortName: "p",
description: "Path of the osu! Songs folder.",
required: true
},
{
name: "beatmap",
shortName: "b",
description: "Name of a beatmap to find.",
required: true
},
{
name: "difficulty",
shortName: "d",
description: "Name of the map difficulty.",
required: true
},
{
name: "bpm",
shortName: "bpm",
description: "BPM for the modified beatmap. Required if speed isn't supplied."
},
{
name: "speed",
shortName: "s",
description: "Speed multiplier for the modified beatmap. Required if bpm isn't supplied."
},
{
name: "hp",
shortName: "hp",
description: "HP drain rate for the modified beatmap."
},
{
name: "cs",
shortName: "cs",
description: "Circle size for the modified beatmap."
},
{
name: "od",
shortName: "od",
description: "Overall difficulty for the modified beatmap."
},
{
name: "ar",
shortName: "ar",
description: "Approach rate for the modified beatmap."
},
{
name: "help",
shortName: "h",
boolean: true,
description: "Display this help text."
},
{
name: "version",
shortName: "v",
boolean: true,
description: "Show the version."
},
];
var beatmap = switch (command.getOption("beatmap")) {
case Some(value): value;
case None: "None";
}
var difficulty = switch (command.getOption("difficulty")) {
case Some(value): value;
case None: "None";
}
var bpm = switch (command.getOption("bpm")) {
case Some(value): value;
case None: "None";
}
var speed = switch (command.getOption("speed")) {
case Some(value): value;
case None: "None";
}
var hp = switch (command.getOption("hp")) {
case Some(value): value;
case None: "None";
}
var cs = switch (command.getOption("cs")) {
case Some(value): value;
case None: "None";
}
var od = switch (command.getOption("od")) {
case Some(value): value;
case None: "None";
}
var ar = switch (command.getOption("ar")) {
case Some(value): value;
case None: "None";
}
final path = switch (command.getOption("path")) {
case Some(value): value;
case None: "None";
}
final displayHelp = switch (command.getOption("help")) {
case Some(value): true;
case None: false;
};
final displayVersion = switch (command.getOption("version")) {
case Some(value): true;
case None: false;
};
if (displayHelp) {
Console.println(command.getInstructions());
return;
}
if (displayVersion) {
Console.println('${command.name} version ${getDefine("version") == null ? "dev" : getDefine("version")}, built on ${getBuildTime()}');
return;
}
if (path == "None") {
Console.println(command.getInstructions());
return;
}
if (beatmap == "None") {
Console.println(command.getInstructions());
return;
}
if (difficulty == "None") {
Console.println(command.getInstructions());
return;
}
if (bpm == "None" && speed == "None") {
Console.println(command.getInstructions());
Console.println("\nYou can't use both --bpm and --speed.");
return;
}
// here all required arguments are fulfilled
beatmap = beatmap.toLowerCase();
difficulty = difficulty.toLowerCase();
var foundBeatmap = searchBeatmap(path, beatmap, difficulty);
if (foundBeatmap.fail == true) {
return;
}
var targetBPM = 0.0, targetSpeed = 0.0;
if (bpm != "None" && speed == "None") {
targetBPM = parseFloat(bpm);
targetSpeed = targetBPM / foundBeatmap.originalBPM;
} else if (bpm == "None" && speed != "None") {
targetBPM = parseFloat(speed) * foundBeatmap.originalBPM;
targetSpeed = parseFloat(speed);
}
Console.println("Beatmap found! Generating the modified beatmap...");
var encoderResponse = encodeAudio(foundBeatmap.beatmapRootPath, foundBeatmap.audioFilename, targetBPM, targetSpeed);
if (encoderResponse.fail == true) {
Console.println("Something went wrong while encoding the audio.");
return;
}
writeBeatmap(foundBeatmap.beatmapFilePath, foundBeatmap.beatmapRootPath, encoderResponse.newAudioFilename, targetBPM, targetSpeed, hp, cs, od, ar);
Console.println("Done!");
}
}