-
-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathEventsData.hx
More file actions
223 lines (204 loc) · 8.98 KB
/
EventsData.hx
File metadata and controls
223 lines (204 loc) · 8.98 KB
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
package funkin.backend.chart;
import funkin.backend.assets.Paths;
import haxe.Json;
import haxe.io.Path;
import hscript.Interp;
import hscript.Parser;
import openfl.Assets;
using StringTools;
class EventsData {
public static var defaultEventsList:Array<String> = ["HScript Call", "Camera Movement", "Camera Position", "Add Camera Zoom", "Camera Bop", "Camera Zoom", "Camera Modulo Change", "Camera Flash", "BPM Change", "Continuous BPM Change", "Time Signature Change", "Scroll Speed Change", "Alt Animation Toggle", "Play Animation"];
public static var defaultEventsParams:Map<String, Array<EventParamInfo>> = [
"HScript Call" => [
{name: "Function Name", type: TString, defValue: "myFunc"},
{name: "Function Parameters (String split with commas)", type: TString, defValue: ""}
],
"Camera Movement" => [
{name: "Camera Target", type: TStrumLine, defValue: 0},
{name: "Tween Movement?", type: TBool, defValue: true, saveIfDefault: false},
{name: "Tween Time (Steps, IF NOT CLASSIC)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4, saveIfDefault: false},
{ // since its the most used event even by default, we'll set saveIfDefault false to avoid filling up with unnecessary parameters the files - Nex
name: "Tween Ease (ex: circ, quad, cube)",
type: TDropDown(['CLASSIC', 'linear', 'back', 'bounce', 'circ', 'cube', 'elastic', 'expo', 'quad', 'quart', 'quint', 'sine', 'smoothStep', 'smootherStep']),
defValue: "CLASSIC",
saveIfDefault: false
},
{
name: "Tween Type (excluded if CLASSIC or linear, ex: InOut)",
type: TDropDown(['In', 'Out', 'InOut']),
defValue: "In",
saveIfDefault: false
}
],
"Camera Position" => [
{name: "X", type: TFloat(null, null, 10, 3), defValue: 0},
{name: "Y", type: TFloat(null, null, 10, 3), defValue: 0},
{name: "Tween Movement?", type: TBool, defValue: true, saveIfDefault: false},
{name: "Tween Time (Steps, IF NOT CLASSIC)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4, saveIfDefault: false},
{
name: "Tween Ease (ex: circ, quad, cube)",
type: TDropDown(['CLASSIC', 'linear', 'back', 'bounce', 'circ', 'cube', 'elastic', 'expo', 'quad', 'quart', 'quint', 'sine', 'smoothStep', 'smootherStep']),
defValue: "CLASSIC",
saveIfDefault: false
},
{
name: "Tween Type (excluded if CLASSIC or linear, ex: InOut)",
type: TDropDown(['In', 'Out', 'InOut']),
defValue: "In",
saveIfDefault: false
},
{name: "Is Offset?", type: TBool, defValue: false, saveIfDefault: false}
],
"Add Camera Zoom" => [
{name: "Amount", type: TFloat(-10, 10, 0.01, 2), defValue: 0.05},
{name: "Camera", type: TDropDown(['camGame', 'camHUD']), defValue: "camGame"}
],
"Camera Bop" => [
{name: "Amount", type: TFloat(-10, 10, 0.1, 2), defValue: 0.1}
],
"Camera Zoom" => [
{name: "Tween Zoom?", type: TBool, defValue: true},
{name: "New Zoom", type: TFloat(-10, 10, 0.01, 2), defValue: 1},
{name: "Camera", type: TDropDown(['camGame', 'camHUD']), defValue: "camGame"},
{name: "Tween Time (Steps)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4},
{
name: "Tween Ease (ex: circ, quad, cube)",
type: TDropDown(['SET', 'linear', 'back', 'bounce', 'circ', 'cube', 'elastic', 'expo', 'quad', 'quart', 'quint', 'sine', 'smoothStep', 'smootherStep']),
defValue: "linear"
},
{
name: "Tween Type (excluded if linear, ex: InOut)",
type: TDropDown(['In', 'Out', 'InOut']),
defValue: "In"
},
{name: "Mode", type: TDropDown(['direct', 'stage']), defValue: "direct"},
{name: "Multiplicative?", type: TBool, defValue: true}
],
"Camera Modulo Change" => [
{name: "Modulo Interval", type: TInt(1, 9999999, 1), defValue: 4},
{name: "Bump Strength", type: TFloat(0.1, 10, 0.01, 2), defValue: 1},
{name: "Every Beat Type", type: TDropDown(['BEAT', 'MEASURE', 'STEP']), defValue: 'BEAT'},
{name: "Beat Offset", type: TFloat(-10, 10, 0.25, 2), defValue: 0}
],
"Camera Flash" => [
{name: "Reversed?", type: TBool, defValue: false},
{name: "Color", type: TColorWheel, defValue: "#FFFFFF"},
{name: "Time (Steps)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4},
{name: "Camera", type: TDropDown(['camGame', 'camHUD']), defValue: "camHUD"}
],
"BPM Change" => [{name: "Target BPM", type: TFloat(1.00, 9999, 0.001, 3), defValue: 100}],
"Continuous BPM Change" => [{name: "Target BPM", type: TFloat(1.00, 9999, 0.001, 3), defValue: 100}, {name: "Time (steps)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4}],
"Time Signature Change" => [{name: "Target Numerator", type: TFloat(1), defValue: 4}, {name: "Target Denominator", type: TFloat(1), defValue: 4}, {name: "Denominator is Steps Per Beat", type: TBool, defValue: false}],
"Scroll Speed Change" => [
{name: "Tween Speed?", type: TBool, defValue: true},
{name: "New Speed", type: TFloat(0.01, 99, 0.01, 2), defValue: 1.},
{name: "Tween Time (Steps)", type: TFloat(0.25, 9999, 0.25, 2), defValue: 4},
{
name: "Tween Ease (ex: circ, quad, cube)",
type: TDropDown(['linear', 'back', 'bounce', 'circ', 'cube', 'elastic', 'expo', 'quad', 'quart', 'quint', 'sine', 'smoothStep', 'smootherStep']),
defValue: "linear"
},
{
name: "Tween Type (excluded if linear, ex: InOut)",
type: TDropDown(['In', 'Out', 'InOut']),
defValue: "In"
},
{name: "Multiplicative?", type: TBool, defValue: false}
],
"Alt Animation Toggle" => [{name: "Enable On Sing Poses", type: TBool, defValue: true}, {name: "Enable On Idle", type: TBool, defValue: true}, {name: "Strumline", type: TStrumLine, defValue: 0}],
"Play Animation" => [
{name: "Character", type: TStrumLine, defValue: 0},
{name: "Animation", type: TString, defValue: "animation"},
{name: "Is forced?", type: TBool, defValue: true},
{
name: "Animation Context",
type: TDropDown(["NONE", "SING", "DANCE", "MISS", "LOCK"]),
defValue: "NONE"
}
],
];
public static var eventsList:Array<String> = defaultEventsList.copy();
public static var eventsParams:Map<String, Array<EventParamInfo>> = defaultEventsParams.copy();
public static function getEventParams(name:String):Array<EventParamInfo> {
return eventsParams.exists(name) ? eventsParams.get(name) : [];
}
public static function reloadEvents() {
eventsList = defaultEventsList.copy();
eventsParams = defaultEventsParams.copy();
var hscriptInterp:Interp = new Interp();
hscriptInterp.variables.set("Bool", TBool);
hscriptInterp.variables.set("Int", function (?min:Int, ?max:Int, ?step:Float):EventParamType {return TInt(min, max, step);});
hscriptInterp.variables.set("Float", function (?min:Float, ?max:Float, ?step:Float, ?precision:Int):EventParamType {return TFloat(min, max, step, precision);});
hscriptInterp.variables.set("String", TString);
hscriptInterp.variables.set("StrumLine", TStrumLine);
hscriptInterp.variables.set("ColorWheel", TColorWheel);
hscriptInterp.variables.set("DropDown", Reflect.makeVarArgs(function(args:Array<Dynamic>):EventParamType {
var flatArgs = CoolUtil.deepFlatten(args);
if(flatArgs.length == 0) return TDropDown(["null"]);
return TDropDown([for (arg in flatArgs) Std.string(arg)]);
}));
hscriptInterp.variables.set("Character", TCharacter);
hscriptInterp.variables.set("Stage", TStage);
var hscriptParser:Parser = new Parser();
hscriptParser.allowJSON = hscriptParser.allowMetadata = false;
for (file in Paths.getFolderContent('data/events/', true, BOTH)) {
var ext = Path.extension(file);
if (ext != "json" && ext != "pack") continue;
var eventName:String = CoolUtil.getFilename(file);
var fileTxt:String = Assets.getText(file);
if (ext == "pack") {
var arr = fileTxt.split("________PACKSEP________");
eventName = Path.withoutExtension(arr[0]);
fileTxt = arr[2];
}
if (fileTxt.trim() == "") continue;
if (!eventsList.contains(eventName)) {
eventsList.push(eventName);
eventsParams.set(eventName, []);
}
try {
var data:EventInfoFile = cast Json.parse(fileTxt);
if (data == null || data.params == null) continue;
var finalParams:Array<EventParamInfo> = [];
for (paramData in data.params) {
try {
finalParams.push({
name: paramData.name,
type: hscriptInterp.expr(hscriptParser.parseString(paramData.type)),
defValue: paramData.defaultValue
});
} catch (e) {trace('Error parsing event param ${paramData.name} - ${eventName}: $e'); finalParams.push(null);}
}
eventsParams.set(eventName, finalParams);
} catch (e) {trace('Error parsing file $file: $e');}
}
hscriptInterp = null; hscriptParser = null;
}
}
typedef EventInfoFile = {
var params:Array<{
var name:String;
var type:String;
var defaultValue:Dynamic;
}>;
}
typedef EventInfo = {
var params:Array<EventParamInfo>;
}
typedef EventParamInfo = {
var name:String;
var type:EventParamType;
var defValue:Dynamic;
var ?saveIfDefault:Bool;
}
enum EventParamType {
TBool;
TInt(?min:Int, ?max:Int, ?step:Float);
TFloat(?min:Float, ?max:Float, ?step:Float, ?precision:Int);
TString;
TStrumLine;
TColorWheel;
TDropDown(?options:Array<String>);
TCharacter;
TStage;
}