forked from CaptainKirb49/Forever-Engine-Reboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChartingState.hx
563 lines (458 loc) · 15.7 KB
/
ChartingState.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
package meta.state.charting;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.addons.display.FlxBackdrop;
import flixel.addons.display.FlxGridOverlay;
import flixel.addons.display.FlxTiledSprite;
import flixel.addons.display.shapes.FlxShapeBox;
import flixel.addons.ui.FlxInputText;
import flixel.addons.ui.FlxUI;
import flixel.addons.ui.FlxUICheckBox;
import flixel.addons.ui.FlxUIDropDownMenu;
import flixel.addons.ui.FlxUIInputText;
import flixel.addons.ui.FlxUINumericStepper;
import flixel.addons.ui.FlxUITabMenu;
import flixel.graphics.FlxGraphic;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup;
import flixel.math.FlxMath;
import flixel.system.FlxSound;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxColor;
import flixel.util.FlxGradient;
import gameObjects.*;
import gameObjects.userInterface.*;
import gameObjects.userInterface.notes.*;
import gameObjects.userInterface.notes.Strumline.UIStaticArrow;
import haxe.Json;
import haxe.io.Bytes;
import lime.media.AudioBuffer;
import meta.MusicBeat.MusicBeatState;
import meta.data.*;
import meta.data.Section.SwagSection;
import meta.data.Song.SwagSong;
import meta.data.dependency.Discord;
import meta.subState.charting.*;
import openfl.events.Event;
import openfl.events.IOErrorEvent;
import openfl.geom.ColorTransform;
import openfl.geom.Rectangle;
import openfl.media.Sound;
import openfl.net.FileReference;
import openfl.utils.ByteArray;
using StringTools;
#if !html5
import sys.thread.Thread;
#end
As the name implies, this is the class where all of the charting state stuff happens, so when you press 7 the game
state switches to this one, where you get to chart songs and such. I'm planning on overhauling this entirely in the future
and making it both more practical and more user friendly.
class ChartingState extends MusicBeatState
{
var _song:SwagSong;
var songMusic:FlxSound;
var vocals:FlxSound;
private var keysTotal = 8;
var strumLine:FlxSprite;
var camHUD:FlxCamera;
var camGame:FlxCamera;
var strumLineCam:FlxObject;
public static var songPosition:Float = 0;
public static var curSong:SwagSong;
public static var gridSize:Int = 50;
private var dummyArrow:FlxSprite;
private var curRenderedNotes:FlxTypedGroup<Note>;
private var curRenderedSustains:FlxTypedGroup<Note>;
private var curRenderedSections:FlxTypedGroup<FlxBasic>;
private var arrowGroup:FlxTypedSpriteGroup<UIStaticArrow>;
override public function create()
{
//
super.create();
generateBackground();
if (PlayState.SONG != null)
_song = PlayState.SONG;
else
_song = Song.loadFromJson('test', 'test');
loadSong(_song.song);
Conductor.changeBPM(_song.bpm);
Conductor.mapBPMChanges(_song);
generateGrid();
curRenderedNotes = new FlxTypedGroup<Note>();
curRenderedSustains = new FlxTypedGroup<Note>();
curRenderedSections = new FlxTypedGroup<FlxBasic>();
generateNotes();
add(curRenderedSections);
add(curRenderedSustains);
add(curRenderedNotes);
strumLineCam = new FlxObject(0, 0);
strumLineCam.screenCenter(X);
// epic strum line
strumLine = new FlxSprite(0, 0).makeGraphic(Std.int(FlxG.width / 2), 2);
add(strumLine);
strumLine.screenCenter(X);
// cursor
dummyArrow = new FlxSprite().makeGraphic(gridSize, gridSize);
add(dummyArrow);
// and now the epic note thingies
arrowGroup = new FlxTypedSpriteGroup<UIStaticArrow>(0, 0);
for (i in 0...keysTotal)
{
var typeReal:Int = i;
if (typeReal > 3)
typeReal -= 4;
var newArrow:UIStaticArrow = ForeverAssets.generateUIArrows(((FlxG.width / 2) - ((keysTotal / 2) * gridSize)) + ((i - 1) * gridSize),
-76, typeReal, 'chart editor');
newArrow.ID = i;
newArrow.setGraphicSize(gridSize);
newArrow.updateHitbox();
newArrow.alpha = 0.9;
newArrow.antialiasing = true;
// lol silly idiot
newArrow.playAnim('static');
arrowGroup.add(newArrow);
}
add(arrowGroup);
arrowGroup.x -= 1;
// code from the playstate so I can separate the camera and hud
camGame = new FlxCamera();
camHUD = new FlxCamera();
camHUD.bgColor.alpha = 0;
FlxG.cameras.reset(camGame);
FlxG.cameras.add(camHUD);
FlxCamera.defaultCameras = [camGame];
FlxG.camera.follow(strumLineCam);
FlxG.mouse.useSystemCursor = false; // Use system cursor because it's prettier
FlxG.mouse.visible = true; // Hide mouse on start
}
var hitSoundsPlayed:Array<Note> = [];
override public function update(elapsed:Float)
{
if (FlxG.keys.justPressed.SPACE)
{
if (songMusic.playing)
{
songMusic.pause();
vocals.pause();
// playButtonAnimation('pause');
}
else
{
vocals.play();
songMusic.play();
// reset note tick sounds
hitSoundsPlayed = [];
// playButtonAnimation('play');
}
}
var scrollSpeed:Float = 0.75;
if (FlxG.mouse.wheel != 0)
{
songMusic.pause();
vocals.pause();
songMusic.time = Math.max(songMusic.time - (FlxG.mouse.wheel * Conductor.stepCrochet * scrollSpeed), 0);
songMusic.time = Math.min(songMusic.time, songMusic.length);
vocals.time = songMusic.time;
}
// strumline camera stuffs!
Conductor.songPosition = songMusic.time;
strumLine.y = getYfromStrum(Conductor.songPosition);
strumLineCam.y = strumLine.y + (FlxG.height / 3);
arrowGroup.y = strumLine.y;
coolGradient.y = strumLineCam.y - (FlxG.height / 2);
coolGrid.y = strumLineCam.y - (FlxG.height / 2);
super.update(elapsed);
///*
if (FlxG.mouse.x > (fullGrid.x)
&& FlxG.mouse.x < (fullGrid.x + fullGrid.width)
&& FlxG.mouse.y > 0
&& FlxG.mouse.y < (getYfromStrum(songMusic.length)))
{
var fakeMouseX = FlxG.mouse.x - fullGrid.x;
dummyArrow.x = (Math.floor((fakeMouseX) / gridSize) * gridSize) + fullGrid.x;
if (FlxG.keys.pressed.SHIFT)
dummyArrow.y = FlxG.mouse.y;
else
dummyArrow.y = Math.floor(FlxG.mouse.y / gridSize) * gridSize;
// moved this in here for the sake of not dying
if (FlxG.mouse.justPressed)
{
if (!FlxG.mouse.overlaps(curRenderedNotes))
{
// add note funny
var noteStrum = getStrumTime(dummyArrow.y);
var notesSection = Math.floor(noteStrum / (Conductor.stepCrochet * 16));
var noteData = adjustSide(Math.floor((dummyArrow.x - fullGrid.x) / gridSize), _song.notes[notesSection].mustHitSection);
var noteSus = 0; // ninja you will NOT get away with this
//noteCleanup(notesSection, noteStrum, noteData);
//_song.notes[notesSection].sectionNotes.push([noteStrum, noteData, noteSus]);
generateChartNote(noteData, noteStrum, noteSus, 0, notesSection);
//updateSelection(_song.notes[notesSection].sectionNotes[_song.notes[notesSection].sectionNotes.length - 1], notesSection, true);
//isPlacing = true;
}
else
{
curRenderedNotes.forEachAlive(function(note:Note)
{
if (FlxG.mouse.overlaps(note))
{
if (FlxG.keys.pressed.CONTROL)
{
// selectNote(note);
}
else
{
// delete the epic note
//var notesSection = getSectionfromY(note.y);
// persona 3 mass destruction
//destroySustain(note, notesSection);
//noteCleanup(notesSection, note.strumTime, note.rawNoteData);
note.kill();
curRenderedNotes.remove(note);
note.destroy();
//
}
}
// lol
});
}
}
}
//
if (FlxG.keys.justPressed.ENTER)
{
songPosition = songMusic.time;
PlayState.SONG = _song;
ForeverTools.killMusic([songMusic, vocals]);
Main.switchState(this, new PlayState());
}
}
override public function stepHit() {
// call all rendered notes lol
curRenderedNotes.forEach(function(epicNote:Note)
{
if ((epicNote.y > (strumLineCam.y - (FlxG.height / 2) - epicNote.height))
|| (epicNote.y < (strumLineCam.y + (FlxG.height / 2))))
{
epicNote.alive = true;
epicNote.visible = true;
// do epic note calls for strum stuffs
if (Math.floor(Conductor.songPosition / Conductor.stepCrochet) == Math.floor(epicNote.strumTime / Conductor.stepCrochet)
&& (!hitSoundsPlayed.contains(epicNote)))
{
hitSoundsPlayed.push(epicNote);
}
} else {
epicNote.alive = false;
epicNote.visible = false;
}
});
super.stepHit();
}
function getStrumTime(yPos:Float):Float
{
return FlxMath.remapToRange(yPos, 0, (songMusic.length / Conductor.stepCrochet) * gridSize, 0, songMusic.length);
}
function getYfromStrum(strumTime:Float):Float
{
return FlxMath.remapToRange(strumTime, 0, songMusic.length, 0, (songMusic.length / Conductor.stepCrochet) * gridSize);
}
var fullGrid:FlxTiledSprite;
function generateGrid()
{
// create new sprite
var base:FlxSprite = FlxGridOverlay.create(gridSize, gridSize, gridSize * 2, gridSize * 2, true, FlxColor.WHITE, FlxColor.BLACK);
fullGrid = new FlxTiledSprite(null, gridSize * keysTotal, gridSize);
// base graphic change data
var newAlpha = (26 / 255);
base.graphic.bitmap.colorTransform(base.graphic.bitmap.rect, new ColorTransform(1, 1, 1, newAlpha));
fullGrid.loadGraphic(base.graphic);
fullGrid.screenCenter(X);
// fullgrid height
fullGrid.height = (songMusic.length / Conductor.stepCrochet) * gridSize;
add(fullGrid);
}
public var sectionLineGraphic:FlxGraphic;
public var sectionCameraGraphic:FlxGraphic;
public var sectionStepGraphic:FlxGraphic;
private function regenerateSection(section:Int, placement:Float)
{
// this will be used to regenerate a box that shows what section the camera is focused on
// oh and section information lol
var sectionLine:FlxSprite = new FlxSprite(FlxG.width / 2 - (gridSize * (keysTotal / 2)) - (extraSize / 2), placement);
sectionLine.frames = sectionLineGraphic.imageFrame;
sectionLine.alpha = (88 / 255);
// section camera
var sectionExtend:Float = 0;
if (_song.notes[section].mustHitSection)
sectionExtend = (gridSize * (keysTotal / 2));
var sectionCamera:FlxSprite = new FlxSprite(FlxG.width / 2 - (gridSize * (keysTotal / 2)) + (sectionExtend), placement);
sectionCamera.frames = sectionCameraGraphic.imageFrame;
sectionCamera.alpha = (88 / 255);
curRenderedSections.add(sectionCamera);
// set up section numbers
for (i in 0...2)
{
var sectionNumber:FlxText = new FlxText(0, sectionLine.y - 12, 0, Std.string(section), 20);
// set the x of the section number
sectionNumber.x = sectionLine.x - sectionNumber.width - 5;
if (i == 1)
sectionNumber.x = sectionLine.x + sectionLine.width + 5;
sectionNumber.setFormat(Paths.font("vcr.ttf"), 24, FlxColor.WHITE);
sectionNumber.antialiasing = false;
sectionNumber.alpha = sectionLine.alpha;
curRenderedSections.add(sectionNumber);
}
for (i in 1...Std.int(_song.notes[section].lengthInSteps / 4))
{
// create a smaller section stepper
var sectionStep:FlxSprite = new FlxSprite(FlxG.width / 2 - (gridSize * (keysTotal / 2)) - (extraSize / 2),
placement + (i * (gridSize * 4)));
sectionStep.frames = sectionStepGraphic.imageFrame;
sectionStep.alpha = sectionLine.alpha;
curRenderedSections.add(sectionStep);
}
curRenderedSections.add(sectionLine);
}
var sectionsMax = 0;
function generateNotes()
{
// GENERATING THE GRID NOTES!
curRenderedNotes.clear();
curRenderedSustains.clear();
//sectionsMax = 1;
generateSection();
for (section in 0..._song.notes.length)
{
sectionsMax = section;
regenerateSection(section, 16 * gridSize * section);
for (i in _song.notes[section].sectionNotes)
{
// note stuffs
var daNoteAlt = 0;
if (i.length > 2)
daNoteAlt = i[3];
generateChartNote(i[1], i[0], i[2], daNoteAlt, section);
}
}
// lolll
//sectionsMax--;
}
var extraSize = 6;
function generateSection() {
// pregenerate assets so it doesnt destroy your ram later
sectionLineGraphic = FlxG.bitmap.create(gridSize * keysTotal + extraSize, 2, FlxColor.WHITE);
sectionCameraGraphic = FlxG.bitmap.create(Std.int(gridSize * (keysTotal / 2)), 16 * gridSize, FlxColor.fromRGB(43, 116, 219));
sectionStepGraphic = FlxG.bitmap.create(gridSize * keysTotal + extraSize, 1, FlxColor.WHITE);
}
function loadSong(daSong:String):Void
{
if (songMusic != null)
songMusic.stop();
if (vocals != null)
vocals.stop();
songMusic = new FlxSound().loadEmbedded(Paths.inst(daSong), false, true);
if (_song.needsVoices)
vocals = new FlxSound().loadEmbedded(Paths.voices(daSong), false, true);
else
vocals = new FlxSound();
FlxG.sound.list.add(songMusic);
FlxG.sound.list.add(vocals);
songMusic.play();
vocals.play();
if (curSong == _song)
songMusic.time = songPosition;
curSong = _song;
songPosition = 0;
pauseMusic();
songMusic.onComplete = function()
{
ForeverTools.killMusic([songMusic, vocals]);
loadSong(daSong);
};
//
}
private function generateChartNote(daNoteInfo, daStrumTime, daSus, daNoteAlt, noteSection)
{
var note:Note = ForeverAssets.generateArrow(PlayState.assetModifier, daStrumTime, daNoteInfo % 4, 0, daNoteAlt, false, null);
// I love how there's 3 different engines that use this exact same variable name lmao
note.rawNoteData = daNoteInfo;
note.sustainLength = daSus;
note.setGraphicSize(gridSize, gridSize);
note.updateHitbox();
note.screenCenter(X);
note.x -= ((gridSize * (keysTotal / 2)) - (gridSize / 2));
note.x += Math.floor(adjustSide(daNoteInfo, _song.notes[noteSection].mustHitSection) * gridSize);
note.y = Math.floor(getYfromStrum(daStrumTime));
curRenderedNotes.add(note);
generateSustain(daStrumTime, daNoteInfo, daSus, daNoteAlt, note);
}
private function generateSustain(daStrumTime:Float = 0, daNoteInfo:Int = 0, daSus:Float = 0, daNoteAlt:Float = 0, note:Note)
{
/*
if (daSus > 0)
{
//prevNote = note;
var constSize = Std.int(gridSize / 3);
var sustainVis:Note = new Note(daStrumTime + (Conductor.stepCrochet * daSus) + Conductor.stepCrochet, daNoteInfo % 4, daNoteAlt, prevNote, true);
sustainVis.setGraphicSize(constSize,
Math.floor(FlxMath.remapToRange((daSus / 2) - constSize, 0, Conductor.stepCrochet * verticalSize, 0, gridSize * verticalSize)));
sustainVis.updateHitbox();
sustainVis.x = note.x + constSize;
sustainVis.y = note.y + (gridSize / 2);
var sustainEnd:Note = new Note(daStrumTime + (Conductor.stepCrochet * daSus) + Conductor.stepCrochet, daNoteInfo % 4, daNoteAlt, sustainVis, true);
sustainEnd.setGraphicSize(constSize, constSize);
sustainEnd.updateHitbox();
sustainEnd.x = sustainVis.x;
sustainEnd.y = note.y + (sustainVis.height) + (gridSize / 2);
// loll for later
sustainVis.rawNoteData = daNoteInfo;
sustainEnd.rawNoteData = daNoteInfo;
curRenderedSustains.add(sustainVis);
curRenderedSustains.add(sustainEnd);
//
// set the note at the current note map
curNoteMap.set(note, [sustainVis, sustainEnd]);
}
*/
}
var coolGrid:FlxBackdrop;
var coolGradient:FlxSprite;
private function generateBackground()
{
coolGrid = new FlxBackdrop(null, 1, 1, true, true, 1, 1);
coolGrid.loadGraphic(Paths.image('UI/forever/base/chart editor/grid'));
coolGrid.alpha = (32 / 255);
add(coolGrid);
// gradient
coolGradient = FlxGradient.createGradientFlxSprite(FlxG.width, FlxG.height,
FlxColor.gradient(FlxColor.fromRGB(188, 158, 255, 200), FlxColor.fromRGB(80, 12, 108, 255), 16));
coolGradient.alpha = (32 / 255);
add(coolGradient);
}
function adjustSide(noteData:Int, sectionTemp:Bool)
{
return (sectionTemp ? ((noteData + 4) % 8) : noteData);
}
function pauseMusic()
{
songMusic.time = Math.max(songMusic.time, 0);
songMusic.time = Math.min(songMusic.time, songMusic.length);
resyncVocals();
songMusic.pause();
vocals.pause();
}
function resyncVocals():Void
{
vocals.pause();
songMusic.play();
Conductor.songPosition = songMusic.time;
vocals.time = Conductor.songPosition;
vocals.play();
}
//
}