-
Notifications
You must be signed in to change notification settings - Fork 2
/
drs2dd.py
316 lines (273 loc) · 11 KB
/
drs2dd.py
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
from __future__ import annotations
import argparse
import os
import shutil
import zipfile
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from drsxml2json import ALL_TRACK_PATHS
from drsxml2json import get_songdata_from_track_id
from drsxml2json import TRACK_ID_TO_PATH
from model.dancedash import DDAlbumInfo
from model.dancedash import DDBeatMap
from model.dancedash import DDBeatMapData
from model.dancedash import DDBeatMapInfoFile
from model.dancedash import DDDownPos
from model.dancedash import DDDownPos2D
from model.dancedash import DDJumpPos
from model.dancedash import DDJumpPos2D
from model.dancedash import DDLineNode
from model.dancedash import DDRoadBlockNode
from model.dancedash import DDSphereNode
from model.dancedash import DRS2DD_MAP_PREFIX
from model.dancedash import DRS_TO_DD_LINE_NOTE_TYPE
from model.dancedash import DRS_TO_DD_NOTE_TYPE
from model.dancedash import ORDER_COUNT_PER_BEAT
from model.dancedash import X_Y
from model.dancerush import ALBUM_NAME
from model.dancerush import DEFAULT_TRACK_DIR
from model.dancerush import DRS_DOWN
from model.dancerush import DRS_JUMP
from model.dancerush import DRSSongData
from model.dancerush import DRSSongDifficulty
from model.dancerush import DRSTrackPoint
from model.dancerush import OUTPUT_ZIP_NAME
from util import create_valid_filename
from util import get_drs_ogg_and_duration
from util import get_song_cover_path
from util import yyyymmdd_to_ticks
from util import zipdir
def map_sphere_nodes(
difficulty: DRSSongDifficulty,
total_time_seconds: float,
bps: float,
) -> list[DDSphereNode]:
spheres = []
for track_step in difficulty.track.sequence_data:
if track_step.long_point or track_step.is_down_or_up:
continue
if track_step.tick_info.end_tick:
seconds = difficulty.track.info.determine_seconds_of_tick(
track_step.tick_info.end_tick,
)
else:
seconds = track_step.tick_info.stime_ms / 1000
spheres.append(
DDSphereNode(
noteOrder=round(bps * seconds * ORDER_COUNT_PER_BEAT),
time=seconds / total_time_seconds,
position=X_Y(x=track_step.position_info.to_dance_dash_x, y=0),
noteType=DRS_TO_DD_NOTE_TYPE[track_step.kind],
),
)
return spheres
def map_line_nodes(
difficulty: DRSSongDifficulty,
total_time_seconds: float,
bps: float,
) -> list[DDLineNode]:
lines = []
for line_group_id, track_step in enumerate(difficulty.track.sequence_data, start=1):
if not track_step.long_point or track_step.is_down_or_up:
continue
track_step.long_point.insert(
0, DRSTrackPoint(
tick=track_step.tick_info.start_tick,
left_pos=track_step.position_info.left_pos,
right_pos=track_step.position_info.right_pos,
point_time=track_step.tick_info.stime_ms,
),
)
last_was_shuffle_end = False
index_in_line = 0
for drs_track_point in track_step.long_point:
last_was_shuffle_end = False
index_in_line += 1
if drs_track_point.tick:
seconds = difficulty.track.info.determine_seconds_of_tick(
drs_track_point.tick,
)
else:
seconds = drs_track_point.point_time / 1000
lines.append(
DDLineNode(
lineGroupId=line_group_id,
indexInLine=index_in_line,
noteOrder=round(bps * seconds * ORDER_COUNT_PER_BEAT),
time=seconds / total_time_seconds,
position=X_Y(x=drs_track_point.to_dance_dash_x, y=0),
noteType=DRS_TO_DD_LINE_NOTE_TYPE[track_step.kind],
),
)
if drs_track_point.left_end_pos and drs_track_point.right_end_pos:
index_in_line += 1
lines.append(
lines[-1].line_end(drs_track_point, index_in_line),
)
last_was_shuffle_end = True
if last_was_shuffle_end:
lines.append(lines[-1].tail)
return lines
def map_down_and_jump_notes(
difficulty: DRSSongDifficulty,
total_time_seconds: float,
bps: float,
) -> list[DDRoadBlockNode]:
road_blocks = []
for track_step in difficulty.track.sequence_data:
if not track_step.is_down_or_up:
continue
if track_step.tick_info.end_tick:
seconds = difficulty.track.info.determine_seconds_of_tick(
track_step.tick_info.end_tick,
)
else:
seconds = track_step.tick_info.stime_ms / 1000
note_order = round(bps * seconds * ORDER_COUNT_PER_BEAT)
if track_step.kind == DRS_JUMP:
# user jumps OVER in DD, not ON like in DRS
note_order += ORDER_COUNT_PER_BEAT / 2
elif track_step.kind == DRS_DOWN:
# user needs to duck UNDER in DD, not go down ON like in DRS
note_order += ORDER_COUNT_PER_BEAT / 16
road_blocks.append(
DDRoadBlockNode(
noteOrder=note_order,
time=seconds / total_time_seconds,
position=DDJumpPos if track_step.kind == DRS_JUMP else DDDownPos,
position2D=DDJumpPos2D if track_step.kind == DRS_JUMP else DDDownPos2D,
),
)
return road_blocks
def create_dd_tracks_from_DRSSongData(drs_song_data: DRSSongData, target_dir: str = None) -> DDBeatMapInfoFile:
if not target_dir:
target_dir = f'{DEFAULT_TRACK_DIR}/{create_valid_filename(drs_song_data.info.title_name)}/'
dd_bpm = int(
drs_song_data.difficulties.difficulty_1a.track.info.highest_bpm / 100,
)
dd_bps = dd_bpm / 60
folder_path = TRACK_ID_TO_PATH.get(drs_song_data.song_id)
song_path, song_length = get_drs_ogg_and_duration(folder_path)
if not song_path or not song_length:
print(
f'No song found for {drs_song_data.info.title_name} ({drs_song_data.song_id})',
)
return None
if not os.path.exists(target_dir):
os.makedirs(target_dir)
new_song_path = os.path.join(target_dir, drs_song_data.ogg)
shutil.copy(song_path, new_song_path)
song_path = new_song_path
if song_cover_path := get_song_cover_path(folder_path):
new_song_cover_path = os.path.join(target_dir, drs_song_data.png)
shutil.copy(song_cover_path, new_song_cover_path)
song_cover_path = new_song_cover_path
song_paths = []
for attr, difficulty in drs_song_data.difficulties.with_attrs_as_str.items():
if attr in ('difficulty_2a', 'difficulty_2b'): # 2 player difficulties
continue
song_length_f = float(song_length)
sphere_notes = map_sphere_nodes(
difficulty, song_length_f, dd_bps,
)
line_notes = map_line_nodes(
difficulty, song_length_f, dd_bps,
)
road_block_notes = map_down_and_jump_notes(
difficulty, song_length_f, dd_bps,
)
total_note_count = len(sphere_notes + line_notes + road_block_notes) # noqa
dd_beat_map = DDBeatMap(
data=DDBeatMapData(
name=f'{drs_song_data.info.title_name} {attr}',
sphereNodes=sphere_notes,
lineNodes=line_notes,
roadBlockNodes=road_block_notes,
),
BPM=dd_bpm,
NPS=str(round(total_note_count / song_length_f, 2)),
)
song_paths.append(
dd_beat_map.save_to_file(
target_dir, f'{attr}.json',
),
)
song_paths.append(
dd_beat_map.block_less.save_to_file(
target_dir, f'{attr}_blockless.json',
),
)
normal, normal_no_blocks, easy, easy_no_blocks = song_paths
create_ticks = yyyymmdd_to_ticks(str(drs_song_data.info.distribution_date))
drs_beat_map_info = DDBeatMapInfoFile(
CreateTicks=create_ticks,
CreateTime=str(create_ticks),
OstId=DRS2DD_MAP_PREFIX,
BeatMapId=DRS2DD_MAP_PREFIX + drs_song_data.song_id,
SongName=drs_song_data.info.title_name,
SongLength=song_length,
SongAuthorName=drs_song_data.info.artist_name,
Bpm=str(dd_bpm),
SongPath=os.path.basename(song_path),
CoverPath=os.path.basename(song_cover_path or '') or None,
DRS_Easy=os.path.basename(easy_no_blocks),
DRS_Normal=os.path.basename(normal_no_blocks),
DRS_Hard=os.path.basename(easy),
DRS_Expert=os.path.basename(normal),
)
drs_beat_map_info.save_to_file(target_dir)
print(f'Created {drs_song_data.info.title_name} ({drs_song_data.song_id})')
return drs_beat_map_info
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Create Dance Dash tracks from DANCERUSH STARDOM Song Data',
)
parser.add_argument(
'--song-id',
type=int,
help='ID of the song to process (number of folder)',
)
args = parser.parse_args()
if args.song_id:
song_data = get_songdata_from_track_id(args.song_id)
if not song_data:
print(f'No song data found for song id {args.song_id}')
raise SystemExit(1)
target_directory = create_valid_filename(song_data.info.title_name)
info_file = create_dd_tracks_from_DRSSongData(
song_data, target_directory,
)
print(f'Song {args.song_id} created?: {bool(info_file)}')
raise SystemExit(0)
if not os.path.exists(DEFAULT_TRACK_DIR):
os.makedirs(DEFAULT_TRACK_DIR)
tracks = []
def _process_track(song_id):
if _song_data := get_songdata_from_track_id(int(song_id)):
try:
if _info_file := create_dd_tracks_from_DRSSongData(_song_data):
tracks.append(_info_file)
except Exception as e:
print(f'Error creating song {song_id}: {e}')
with ThreadPoolExecutor() as executor:
executor.map(_process_track, ALL_TRACK_PATHS)
print(f'Created {len(tracks)} tracks')
album_info = DDAlbumInfo(
OstName='DANCERUSH STARDOM',
BeatMapIdList=sorted([track.BeatMapId for track in tracks]),
OstId=DRS2DD_MAP_PREFIX,
CoverPath='DANCERUSH_STARDOM.jpg',
CreateTime=yyyymmdd_to_ticks(datetime.now().strftime('%Y%m%d')),
).save_to_file(DEFAULT_TRACK_DIR)
print(f'Created album info file: {album_info}')
shutil.copy('resources/drs/DANCERUSH_STARDOM.jpg', DEFAULT_TRACK_DIR)
if not os.path.exists('bin'):
os.makedirs('bin')
print('Zipping tracks...')
with zipfile.ZipFile(f'bin/{OUTPUT_ZIP_NAME}', 'w', zipfile.ZIP_DEFLATED) as zipf:
zipdir(
DEFAULT_TRACK_DIR, zipf,
f'Dance Dash_Data/StreamingAssets/NewDLC/{ALBUM_NAME}',
)
print(f'Created bin/{OUTPUT_ZIP_NAME}')
raise SystemExit(0)