This repository was archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSchmovinEvent.hx
310 lines (258 loc) · 5.36 KB
/
SchmovinEvent.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
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
/**
* @ Author: 4mbr0s3 2
* @ Create Time: 2021-06-22 13:03:47
* @ Modified by: 4mbr0s3 2
* @ Modified time: 2021-11-13 10:12:08
*/
package schmovin;
import flixel.math.FlxMath;
import schmovin.SchmovinTimeline;
import schmovin.note_mods.ISchmovinNoteMod.ISchmovinNoteMod;
interface ISchmovinEvent
{
public function TimelineUpdate(currentBeat:Float):Void;
public function GetModName():String;
public function GetPlayer():Int;
public function GetTargetPercent(player:Int):Float;
public function SetTimeline(t:SchmovinTimeline):Void;
public function GetIndex():Int;
public function SetIndex(index:Int):Void;
public function GetBeat():Float;
public function GetBeatLength():Float;
}
class SchmovinEventNull implements ISchmovinEvent
{
var _timeline:SchmovinTimeline;
public function new() {}
public function TimelineUpdate(currentBeat:Float) {}
// (Violates interface segregation)
public function GetTargetPercent(player:Int)
{
return 0;
}
public function GetModName()
{
return null;
}
public function SetTimeline(t:SchmovinTimeline)
{
_timeline = t;
}
public function GetPlayer()
{
return 0;
}
public function GetBeat()
{
return 0;
}
public function GetBeatLength()
{
return 0;
}
public function GetIndex()
{
return -1;
}
public function SetIndex(index:Int) {}
}
class SchmovinEventEase implements ISchmovinEvent
{
var _beat:Float = 0;
var _length:Float = 0;
var _easeFunction:Float->Float;
var _targetPercent:Float = 0;
var _mod:ISchmovinNoteMod;
var _player:Int = 0;
var _done = false;
var _timeline:SchmovinTimeline;
var _index = -1;
public function GetBeat()
{
return _beat;
}
public function GetBeatLength()
{
return _length;
}
public function GetIndex()
{
return _index;
}
public function SetIndex(index:Int)
{
_index = index;
}
public function SetTimeline(t:SchmovinTimeline)
{
_timeline = t;
}
public function GetPreviousEvent()
{
return _timeline.GetPreviousEvent(this);
}
public function GetPlayer()
{
return _player;
}
public function new(beat:Float, length:Float, easeFunc:Float->Float, targetPercent:Float, mod:ISchmovinNoteMod, player:Int)
{
_beat = beat;
_length = length;
_easeFunction = easeFunc;
_targetPercent = targetPercent;
_mod = mod;
_player = player;
}
public function GetModName()
{
return _mod.GetName();
}
public function GetTargetPercent(player:Int)
{
return _targetPercent;
}
public function TimelineUpdate(currentBeat:Float)
{
var endBeat = _beat + _length;
var isOverlapping = currentBeat > _beat && currentBeat <= endBeat;
if (isOverlapping)
{
// Costly, so we're moving it here (when it's actually needed)
var lastPercent = GetPreviousEvent().GetTargetPercent(_player);
_done = false;
var progress = (currentBeat - _beat) / _length;
var percent = FlxMath.lerp(lastPercent, _targetPercent, _easeFunction(progress));
_mod.SetPercent(percent, _player);
}
else if (!_done && currentBeat > endBeat) // Reached the end
{
_done = true;
_mod.SetPercent(_targetPercent, _player);
}
}
}
class SchmovinEventSet implements ISchmovinEvent
{
var _timeline:SchmovinTimeline;
var _beat:Float = 0;
var _targetPercent:Float = 0;
var _mod:ISchmovinNoteMod;
var _player:Int = 0;
var _done = false;
var _index = -1;
public function GetBeat()
{
return _beat;
}
public function GetBeatLength()
{
return 0;
}
public function GetIndex()
{
return _index;
}
public function SetIndex(index:Int)
{
_index = index;
}
public function GetPreviousEvent()
{
return _timeline.GetPreviousEvent(this);
}
public function GetModName()
{
return _mod.GetName();
}
public function GetPlayer()
{
return _player;
}
public function SetTimeline(t:SchmovinTimeline)
{
_timeline = t;
}
public function new(beat:Float, targetPercent:Float, mod:ISchmovinNoteMod, player:Int)
{
_beat = beat;
_targetPercent = targetPercent;
_mod = mod;
_player = player;
}
public function GetTargetPercent(player:Int)
{
return _targetPercent;
}
public function TimelineUpdate(currentBeat:Float)
{
// var prevEvent = GetPreviousEvent();
// var isOverlapping = currentBeat <= _beat && currentBeat > prevEvent.GetBeat() + prevEvent.GetBeatLength();
var isOverlapping = currentBeat <= _beat;
if (isOverlapping)
{
// _mod.SetPercent(prevEvent.GetTargetPercent(_player), _player);
_done = false;
}
else if (!_done)
{
_mod.SetPercent(_targetPercent, _player);
_done = true;
}
}
}
class SchmovinEventFunction implements ISchmovinEvent
{
var _timeline:SchmovinTimeline;
public function GetBeat()
{
return _beat;
}
public function GetBeatLength()
{
return 0;
}
public function GetIndex()
{
return -1;
}
public function SetIndex(index:Int) {}
public function GetModName()
{
return null;
}
public function SetTimeline(t:SchmovinTimeline)
{
_timeline = t;
}
public function GetPlayer()
{
return -1;
}
var _callback:Void->Void;
var _done = false;
var _beat:Float;
public function new(beat:Float, callback:Void->Void)
{
_beat = beat;
_callback = callback;
}
public function TimelineUpdate(currentBeat:Float):Void
{
var isOverlapping = currentBeat <= _beat;
if (isOverlapping)
{
_done = false;
}
else if (!_done)
{
_callback();
_done = true;
}
}
// Violates interface segregation lol
public function GetTargetPercent(player:Int):Float
{
return 0;
}
}