-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSMFile.hx
150 lines (134 loc) · 4.25 KB
/
SMFile.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
import haxe.ds.StringMap;
import SMUtils.SwagSection;
// Ye olde format:
// typedef FNFJson = {
// song: String,
// sectionLengths: Array<Dynamic>,
// sections: Int,
// notes: Array<SwagSection>,
// events: Array<Dynamic>,
// bpm: Float,
// needsVoices: Bool,
// speed: Float,
// player1: String,
// player2: String,
// gfVersion: String,
// stage: String,
// validScore: Bool
// };
typedef FNFJson = {
var song:String;
var notes:Array<SwagSection>;
var events:Array<Dynamic>;
var bpm:Float;
var needsVoices:Bool;
var speed:Float;
var player1:String;
var player2:String;
var gfVersion:String;
var stage:String;
var validScore:Bool;
}
typedef SongConfig = {
?song:String,
?speed:Float,
?player1:String,
?player2:String,
?gfVersion:String
};
class SMFile
{
public var extraHeaderTags:StringMap<String>;
public var bpms:Array<Array<Float>>;
public var charts:Array<SMChart>;
public var title:String;
public var chartOffset:Float;
public function new(filecontent:String)
{
bpms = [];
charts = [];
extraHeaderTags = new StringMap();
_parseChart(filecontent);
}
function _parseChart(chartstr:String)
{
var currHeaderEntry = '';
var parsingTag = false;
for(i in 0...chartstr.length)
{
var ch = chartstr.charAt(i);
switch (ch)
{
case SMUtils.TAG_START:
parsingTag = true;
case SMUtils.TAG_END:
parsingTag = false;
var parsedentry = SMUtils.parseEntry(currHeaderEntry);
if(!parsedentry.shouldParse)
{
currHeaderEntry = '';
continue;
}
switch (parsedentry.tag)
{
case 'BPMS':
bpms = SMUtils.parseBPMStr(parsedentry.value);
case 'NOTES':
charts.push(new SMChart(parsedentry.value));
case 'OFFSET':
chartOffset = Std.parseFloat(parsedentry.value);
case 'TITLE':
title = parsedentry.value;
default:
extraHeaderTags.set(parsedentry.tag, parsedentry.value);
}
currHeaderEntry = '';
default:
if(parsingTag)
currHeaderEntry += ch;
}
}
}
public static inline function getOrDefault<T>(val:Null<T>, defaultVal:T)
{
if(val == null)
return defaultVal;
return val;
}
public function makeFNFChart(chartIndex=0, song_config:SongConfig=null, flipchart=false)
{
if(song_config == null)
song_config = {};
// var fnfjson:FNFJson = {
// song: getOrDefault(song_config.song, extraHeaderTags.get('TITLE')),
// sectionLengths: [],
// sections: 0,
// notes: [],
// events: [],
// bpm: bpms[0][1],
// needsVoices: false,
// speed: getOrDefault(song_config.speed, 1.0),
// player1: getOrDefault(song_config.player1, 'bf'),
// player2: getOrDefault(song_config.player2, 'dad'),
// gfVersion: getOrDefault(song_config.gfVersion, 'gf'),
// stage: '',
// validScore: true
// };
var fnfjson:FNFJson = {
song: getOrDefault(song_config.song, extraHeaderTags.get('TITLE')),
notes: [],
events: [],
bpm: bpms[0][1],
needsVoices: false,
speed: getOrDefault(song_config.speed, 1.0),
player1: getOrDefault(song_config.player1, 'bf'),
player2: getOrDefault(song_config.player2, 'dad'),
gfVersion: getOrDefault(song_config.gfVersion, 'gf'),
stage: '',
validScore: true
};
var fnfchart = charts[chartIndex].toFNF(bpms, chartOffset, flipchart);
fnfjson.notes = fnfjson.notes.concat(fnfchart);
return { song: fnfjson };
}
}