This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SchmovinClient.hx
118 lines (97 loc) · 2.93 KB
/
SchmovinClient.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
/**
* @ Author: 4mbr0s3 2
* @ Create Time: 2021-06-22 12:05:21
* @ Modified by: 4mbr0s3 2
* @ Modified time: 2021-11-13 10:42:20
*/
package schmovin;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween.FlxTweenManager;
import flixel.tweens.FlxTween.TweenCallback;
import hscript.Interp;
import hscript.Parser;
import schmovin.SchmovinTimeline;
using schmovin.SchmovinUtil;
class SchmovinClient
{
var _timeline:SchmovinTimeline;
var _state:PlayState;
var _instance:SchmovinInstance;
var _tween:FlxTweenManager = new FlxTweenManager();
public function Initialize() {}
public function ParseHScript(script:String)
{
_timeline.ClearEvents();
var parser = new Parser();
var ast = parser.parseString(script);
var interp = new Interp();
interp.variables.set('FlxEase', FlxEase);
interp.variables.set('Alt', Alt);
interp.variables.set('Math', Math);
interp.variables.set('E', E);
interp.variables.set('S', S);
interp.variables.set('F', F);
interp.variables.set('Ease', Ease);
interp.variables.set('Set', Set);
interp.variables.set('Func', Func);
var res = interp.execute(ast);
SchmovinAdapter.GetInstance().Log('Executed hscript: ${res}');
return res;
}
public function Destroy() {}
function GetElapsedInBeats(elapsed:Float)
{
return elapsed * 1000 / SchmovinAdapter.GetInstance().GetCrotchetNow();
}
public function Update(elapsed:Float)
{
_tween.update(GetElapsedInBeats(elapsed));
}
public function new(instance:SchmovinInstance, timeline:SchmovinTimeline, state:PlayState)
{
_instance = instance;
_timeline = timeline;
_state = state;
Initialize();
}
function Ease(beat:Float, length:Float, easeFunc:Float->Float, target:Float, mod:String, player:Int = -1)
{
_timeline.Ease(beat, length, easeFunc, target, mod, player);
}
function E(barstep:Array<Float>, length:Float, easeFunc:Float->Float, target:Float, mod:String, player:Int = -1)
{
_timeline.Ease(BarStepToBeats(barstep[0], barstep[1]), length, easeFunc, target, mod, player);
}
function Set(beat:Float, target:Float, mod:String, player:Int = -1)
{
_timeline.Set(beat, target, mod, player);
}
function S(barstep:Array<Float>, target:Float, mod:String, player:Int = -1)
{
_timeline.Set(BarStepToBeats(barstep[0], barstep[1]), target, mod, player);
}
function Func(beat:Float, callback:Void->Void)
{
_timeline.Func(beat, callback);
}
function F(barstep:Array<Float>, callback:Void->Void)
{
Func(BarStepToBeats(barstep[0], barstep[1]), callback);
}
function T(barstep:Array<Float>, object:Dynamic, length:Float, easeFunc:Float->Float, values:Dynamic, onComplete:TweenCallback = null,
onUpdate:TweenCallback = null)
{
F(barstep, () ->
{
_tween.tween(object, values, length, {ease: easeFunc, onComplete: onComplete, onUpdate: onUpdate});
});
}
function Alt(num:Int)
{
return ((num % 2) - 0.5) / 0.5;
}
inline function BarStepToBeats(bar:Float, step:Float)
{
return (bar - 1) * 4 + (step - 1) / 4.0;
}
}