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 3
/
Copy pathSchmovinInstance.hx
211 lines (168 loc) · 5.43 KB
/
SchmovinInstance.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
/**
* @ Author: 4mbr0s3 2
* @ Create Time: 2021-08-22 19:49:42
* @ Modified by: 4mbr0s3 2
* @ Modified time: 2021-11-14 10:30:11
*/
package schmovin;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.util.FlxColor;
import openfl.filters.ShaderFilter;
import schmovin.SchmovinRenderers.ISchmovinRenderer;
import schmovin.SchmovinRenderers.SchmovinHoldNoteRenderer;
import schmovin.SchmovinRenderers.SchmovinNotePathRenderer;
import schmovin.shaders.PlaneRaymarcher;
import schmovin.util.FlxCameraCopy;
using StringTools;
class SchmovinInstance
{
public var camHUD:FlxCamera;
public var camGame:FlxCamera;
public var camBelowGame:FlxCamera;
public var camGameCopy:FlxCameraCopy;
public var camAboveGame:FlxCamera;
public var camPath:FlxCameraCopy;
public var camNotes:FlxCameraCopy;
public var planeRaymarcher:PlaneRaymarcher;
public var planeRaymarcherFilter:ShaderFilter;
public var timeline:SchmovinTimeline;
private var _client:SchmovinClient;
public var holdNoteRenderer:ISchmovinRenderer;
public var notePathRenderer:ISchmovinRenderer;
public var state:PlayState;
public var layerBelowGame:FlxTypedGroup<FlxBasic>;
public var layerAboveGame:FlxTypedGroup<FlxBasic>;
public var layerAboveHUD:FlxTypedGroup<FlxBasic>;
public var fakeExplosionReceptors:FlxTypedGroup<FlxSprite>;
public function SetClient(client:SchmovinClient)
{
_client.Destroy();
_client = client;
}
private function new() {}
public static function IsPixelStage()
{
return PlayState.curStage.startsWith('school');
}
public function InitializeFakeExplosionReceptors()
{
fakeExplosionReceptors = new FlxTypedGroup<FlxSprite>();
SchmovinAdapter.GetInstance().Log('Initialized fake explosion receptors');
fakeExplosionReceptors.cameras = [camNotes];
if (IsPixelStage())
CreatePixelExplosionReceptors();
else
CreateNormalExplosionReceptors();
state.add(fakeExplosionReceptors);
}
function CreatePixelExplosionReceptors()
{
for (i in 0...state.strumLineNotes.length)
{
var receptor:FlxSprite = new FlxSprite(0, state.strumLine.y);
var realReceptor = state.strumLineNotes.members[i];
receptor.frames = realReceptor.frames;
receptor.animation.copyFrom(realReceptor.animation);
receptor.setGraphicSize(Std.int(receptor.width * PlayState.daPixelZoom));
receptor.updateHitbox();
receptor.antialiasing = false;
receptor.animation.play('confirm');
fakeExplosionReceptors.add(receptor);
}
}
function CreateNormalExplosionReceptors()
{
for (i in 0...state.strumLineNotes.length)
{
var receptor:FlxSprite = new FlxSprite(0, state.strumLine.y);
var realReceptor = state.strumLineNotes.members[i];
receptor.frames = realReceptor.frames;
receptor.animation.copyFrom(realReceptor.animation);
receptor.antialiasing = true;
receptor.setGraphicSize(Std.int(receptor.width * 0.7));
receptor.animation.play('confirm');
fakeExplosionReceptors.add(receptor);
}
}
public function UpdateFakeExplosionReceptors()
{
if (fakeExplosionReceptors == null)
return;
for (index in 0...state.strumLineNotes.length)
{
var explosion = fakeExplosionReceptors.members[index];
var target = state.strumLineNotes.members[index];
target.visible = target.animation.name != 'confirm';
explosion.visible = !target.visible;
if (!explosion.visible)
continue;
explosion.animation.frameIndex = target.animation.frameIndex;
explosion.shader = target.shader;
var targetPos = target.getPosition();
explosion.centerOffsets();
explosion.centerOrigin();
var offsetX = -(explosion.width - target.width) / 2;
var offsetY = -(explosion.height - target.height) / 2;
explosion.setPosition(targetPos.x + offsetX, targetPos.y + offsetY);
explosion.angle = target.angle;
explosion.scale.copyFrom(target.scale);
}
}
public function InitializeCameras()
{
camGameCopy = new FlxCameraCopy(camGame);
camGameCopy.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(camGameCopy);
camAboveGame = new FlxCamera();
camAboveGame.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(camAboveGame);
layerAboveGame = new FlxTypedGroup<FlxBasic>();
layerAboveGame.cameras = [camAboveGame];
state.add(layerAboveGame);
planeRaymarcher = new PlaneRaymarcher();
planeRaymarcherFilter = new ShaderFilter(planeRaymarcher.shader);
camPath = new FlxCameraCopy(state.camHUD);
camPath.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(camPath);
camNotes = new FlxCameraCopy(state.camHUD);
camNotes.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(camNotes);
}
public function InitializeSchmovin()
{
timeline = SchmovinTimeline.Create(state, this);
SwitchClient();
InitializeRenderers();
}
public function IsClientNull()
{
return Std.is(_client, SchmovinClientNull);
}
function SwitchClient()
{
_client = new SchmovinClientNull(this, timeline, state);
SchmovinAdapter.GetInstance().ForEveryMod([this, timeline, state]);
}
public function InitializeRenderers()
{
holdNoteRenderer = new SchmovinHoldNoteRenderer(state, [camNotes], timeline, this);
notePathRenderer = new SchmovinNotePathRenderer(state, [camPath], timeline, this);
}
public static function Create()
{
return new SchmovinInstance();
}
public function Destroy()
{
_client.Destroy();
}
public function Update(elapsed:Float)
{
_client.Update(elapsed);
timeline.Update(SchmovinAdapter.GetInstance().GetCurrentBeat());
}
}