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
/
SchmovinStandalone.hx
213 lines (187 loc) · 5.25 KB
/
SchmovinStandalone.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
/**
* @ Author: 4mbr0s3 2
* @ Create Time: 2021-06-22 11:55:58
* @ Modified by: 4mbr0s3 2
*/
package schmovin;
import Song.SwagSong;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.math.FlxMath;
import flixel.util.FlxColor;
using SchmovinUtil.SchmovinUtil;
/**
* Version of Schmovin without any dependencies on Groovin'.
* This should be used by other engines.
* Check out the comments for each public function to see where to put them in the engine code.
*/
class SchmovinStandalone
{
public function new() {}
private var instance:SchmovinInstance;
public static var holdNoteSubdivisions:Int = 4;
function ShouldRun():Bool
{
if (Std.is(FlxG.state.subState, PauseSubState))
return true;
return FlxG.state.subState == null;
}
/**
* Call this in PlayState right after the following line:
*
* openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
* @param state
*/
public function OnGameOver(state:PlayState)
{
instance.Destroy();
}
/**
* Before calling this, make sure to set the SchmovinAdapter instance so Schmovin' properly works.
* Call this in PlayState between the following lines:
*
* FlxG.cameras.reset(camGame);
* FlxG.cameras.add(camHUD);
* @param camGame
* @param camHUD
*/
public function AfterCameras(camGame:FlxCamera, camHUD:FlxCamera)
{
instance = SchmovinInstance.Create();
instance.state = cast FlxG.state;
instance.camHUD = camHUD;
instance.camGame = camGame;
InitializeCamBelowGame();
instance.InitializeCameras();
instance.InitializeSchmovin();
}
function InitializeCamBelowGame()
{
instance.camBelowGame = new FlxCamera();
instance.camBelowGame.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(instance.camBelowGame);
instance.layerBelowGame = new FlxTypedGroup<FlxBasic>();
instance.layerBelowGame.cameras = [instance.camBelowGame];
instance.state.add(instance.layerBelowGame);
}
/**
* Call this when exiting the PlayState.
* @param nextState
*/
public function OnExitPlayState(nextState:FlxState)
{
instance.Destroy();
}
function InitializeAboveHUD()
{
instance.layerAboveHUD = new FlxTypedGroup<FlxBasic>();
instance.layerAboveHUD.cameras = [instance.camHUD];
instance.state.add(instance.layerAboveHUD);
}
/**
* Call this after all UI elements have their cameras set to camHUD in PlayState.create().
* @param state
*/
public function PostUI(state:PlayState)
{
state.strumLineNotes.cameras = [instance.camNotes];
state.notes.cameras = [instance.camNotes];
FlxCamera.defaultCameras = [instance.camGameCopy];
InitializeAboveHUD();
}
/**
* Call this from the PlayState's draw method before calling the superclass method.
* @param state
*/
public function PreDraw(state:PlayState)
{
if (instance.camPath == null)
return;
instance.notePathRenderer.PreDraw();
}
/**
* Call this from the PlayState's draw method after calling the superclass method.
* @param state
*/
public function PostDraw(state:PlayState)
{
if (instance.camPath == null)
return;
instance.holdNoteRenderer.PreDraw();
}
/**
* Call this before startTimer in PlayState.startCountdown().
* @param state
*/
public function OnCountdown(state:PlayState)
{
instance.InitializeFakeExplosionReceptors();
}
/**
* Call this at the start of PlayState.Update().
* @param state
* @param elapsed
*/
public function Update(state:PlayState, elapsed:Float)
{
instance.Update(elapsed);
UpdateReceptors();
}
function UpdateReceptors()
{
var currentBeat = GetCurrentBeat();
for (receptorIndex in 0...instance.state.strumLineNotes.length)
{
var receptor = instance.state.strumLineNotes.members[receptorIndex];
instance.timeline.UpdateNotes(currentBeat, receptor, SchmovinUtil.GetPlayerOfTotalColumn(receptorIndex), receptorIndex);
}
instance.UpdateFakeExplosionReceptors();
}
// Taken from GroovinConductor
public static function HasBPMChanges()
{
return Conductor.bpmChangeMap.length > 0;
}
// Taken from GroovinConductor
public static function GetSortedBPMChanges()
{
var sortedChanges = Conductor.bpmChangeMap.copy();
sortedChanges.sort((e1, e2) ->
{
return e1.songTime < e2.songTime ? -1 : 1;
});
sortedChanges.insert(0, {songTime: 0, stepTime: 0, bpm: PlayState.SONG.bpm});
return sortedChanges;
}
// Taken from GroovinConductor
public static function GetCurrentBeat()
{
return SchmovinAdapter.GetInstance().GetCurrentBeat();
}
// Taken from GroovinConductor
public static function GetCrotchetFromBPM(bpm:Float)
{
return 60000.0 / bpm;
}
/**
* Call this after the following line of code:
* daNote.y = (strumLine.y - (Conductor.songPosition - daNote.strumTime) * (0.45 * FlxMath.roundDecimal(SONG.speed, 2)));
*
* Make sure to comment out or remove the clipping rectangle code if it's still there.
* @param state
* @param strumLine
* @param daNote
* @param SONG
* @return Bool
*/
public function PostNotePosition(state:PlayState, strumLine:FlxSprite, daNote:Note, SONG:SwagSong):Bool
{
if (daNote.alive && daNote.visible)
instance.timeline.UpdateNotes(GetCurrentBeat(), daNote, daNote.GetPlayer());
return true;
}
}