-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_to_quaver.go
99 lines (92 loc) · 3.2 KB
/
convert_to_quaver.go
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
package main
import (
"fmt"
"os"
"sort"
"strconv"
)
func (conf *ProgramConfig) ConvertBmsToQua(fileData BMSFileData, outputPath string) error {
quaFile, e := os.Create(outputPath)
if e != nil {
return e
}
defer quaFile.Close()
// flush contents to qua
_ = WriteLine(quaFile, "AudioFile: virtual")
_ = WriteLine(quaFile, "SongPreviewTime: -1")
bg := fileData.Metadata.StageFile
// always prefer banner in the quaver client because of the way song previews are displayed
if len(fileData.Metadata.Banner) > 0 {
bg = fileData.Metadata.Banner
}
if len(bg) != 0 {
_ = WriteLine(quaFile, "BackgroundFile: "+bg)
}
_ = WriteLine(quaFile, "MapId: -1")
_ = WriteLine(quaFile, "MapSetId: -1")
_ = WriteLine(quaFile, "Mode: Keys7")
scratchKey := "True"
if conf.NoScratchLane {
scratchKey = "False"
}
_ = WriteLine(quaFile, fmt.Sprintf("HasScratchKey: %s", scratchKey))
_ = WriteLine(quaFile, fmt.Sprintf("Title: '%s'", fileData.Metadata.Title))
_ = WriteLine(quaFile, fmt.Sprintf("Artist: '%s'", fileData.Metadata.Artist))
_ = WriteLine(quaFile, "Source: BMS")
_ = WriteLine(quaFile, fmt.Sprintf("Tags: '%s'", fileData.Metadata.Tags))
_ = WriteLine(quaFile, fmt.Sprintf("Creator: '%s'", AppendSubArtistsToArtist(fileData.Metadata.Artist, fileData.Metadata.SubArtists)))
_ = WriteLine(quaFile, fmt.Sprintf("DifficultyName: '%s'", GetDifficultyName(fileData.Metadata.Difficulty, fileData.Metadata.Subtitle, conf.NoScratchLane)))
_ = WriteLine(quaFile, "Description: Converted from BMS")
_ = WriteLine(quaFile, "EditorLayers: []")
// Process Hit Sound Paths
_ = WriteLine(quaFile, "CustomAudioSamples:")
for _, m := range fileData.Audio.StringArray {
_ = WriteLine(quaFile, "- Path: "+m)
}
// Process Sound Effects
_ = WriteLine(quaFile, "SoundEffects:")
for _, s := range fileData.SoundEffects {
_ = WriteLine(quaFile, "- StartTime: "+strconv.Itoa(int(s.StartTime)))
_ = WriteLine(quaFile, " Sample: "+strconv.Itoa(s.Sample))
_ = WriteLine(quaFile, " Volume: "+strconv.Itoa(s.Volume))
}
// Process Timing Points
_ = WriteLine(quaFile, "TimingPoints:")
keys := make([]float64, len(fileData.TimingPoints))
i := 0
for k := range fileData.TimingPoints {
keys[i] = k
i++
}
sort.Float64s(keys)
for _, k := range keys {
_ = WriteLine(quaFile, fmt.Sprintf("- StartTime: %f", k))
_ = WriteLine(quaFile, fmt.Sprintf(" Bpm: %f", fileData.TimingPoints[k]))
}
// Process Slider Velocities (joke)
_ = WriteLine(quaFile, "SliderVelocities: []")
// Process Hit Objects
_ = WriteLine(quaFile, "HitObjects:")
for lane, objects := range fileData.HitObjects {
if lane == 8 && conf.NoScratchLane {
continue
}
for _, obj := range objects {
_ = WriteLine(quaFile, "- StartTime: "+strconv.Itoa(int(obj.StartTime)))
_ = WriteLine(quaFile, " Lane: "+strconv.Itoa(lane))
if obj.IsLongNote && int(obj.EndTime) > int(obj.StartTime) {
_ = WriteLine(quaFile, " EndTime: "+strconv.Itoa(int(obj.EndTime)))
}
if obj.KeySounds != nil {
_ = WriteLine(quaFile, " KeySounds:")
_ = WriteLine(quaFile, " - Sample: "+strconv.Itoa(obj.KeySounds.Sample))
_ = WriteLine(quaFile, " Volume: "+strconv.Itoa(obj.KeySounds.Volume))
}
}
}
e = quaFile.Sync()
if e != nil {
return e
}
return nil
}