Funkin/source/charting/ChartingState.hx

1427 lines
36 KiB
Haxe
Raw Normal View History

2022-01-20 23:33:51 -05:00
package charting;
2021-03-01 23:00:02 -05:00
import Conductor.BPMChangeEvent;
2022-01-22 16:53:38 -05:00
import Note.NoteData;
2020-10-29 23:06:52 -04:00
import Section.SwagSection;
import SongLoad.SwagSong;
2021-09-27 22:30:38 -04:00
import dsp.FFT;
2020-10-10 05:28:44 -04:00
import flixel.FlxSprite;
2021-09-15 15:33:05 -04:00
import flixel.FlxStrip;
2020-10-13 01:18:50 -04:00
import flixel.addons.display.FlxGridOverlay;
2020-10-14 04:18:19 -04:00
import flixel.addons.ui.FlxInputText;
2020-10-11 23:52:21 -04:00
import flixel.addons.ui.FlxUI9SliceSprite;
2020-10-14 04:18:19 -04:00
import flixel.addons.ui.FlxUI;
2020-10-11 23:52:21 -04:00
import flixel.addons.ui.FlxUICheckBox;
2020-10-18 20:59:53 -04:00
import flixel.addons.ui.FlxUIDropDownMenu;
2020-10-14 04:18:19 -04:00
import flixel.addons.ui.FlxUIInputText;
2020-10-16 00:22:13 -04:00
import flixel.addons.ui.FlxUINumericStepper;
2020-10-14 04:18:19 -04:00
import flixel.addons.ui.FlxUITabMenu;
2020-10-12 23:08:08 -04:00
import flixel.addons.ui.FlxUITooltip.FlxUITooltipStyle;
2021-09-15 15:33:05 -04:00
import flixel.graphics.tile.FlxDrawTrianglesItem.DrawData;
2020-10-10 00:22:26 -04:00
import flixel.group.FlxGroup.FlxTypedGroup;
2020-10-11 23:52:21 -04:00
import flixel.group.FlxGroup;
import flixel.input.gamepad.id.SwitchJoyconLeftID;
2020-10-13 01:18:50 -04:00
import flixel.math.FlxMath;
2020-10-12 23:08:08 -04:00
import flixel.math.FlxPoint;
2020-10-31 00:25:23 -04:00
import flixel.system.FlxSound;
2020-10-10 05:28:44 -04:00
import flixel.text.FlxText;
2020-10-09 23:22:07 -04:00
import flixel.ui.FlxButton;
2020-10-10 00:22:26 -04:00
import flixel.ui.FlxSpriteButton;
import flixel.util.FlxColor;
2021-09-17 14:12:36 -04:00
import haxe.CallStack.StackItem;
2020-10-09 23:22:07 -04:00
import haxe.Json;
2022-01-22 16:53:38 -05:00
import haxe.Serializer;
2021-09-06 14:50:04 -04:00
import lime.media.AudioBuffer;
2021-01-04 18:56:30 -05:00
import lime.utils.Assets;
2021-09-16 00:34:51 -04:00
import lime.utils.Int16Array;
2020-10-09 23:22:07 -04:00
import openfl.events.Event;
import openfl.events.IOErrorEvent;
import openfl.media.Sound;
2020-10-09 23:22:07 -04:00
import openfl.net.FileReference;
import openfl.utils.ByteArray;
2021-09-27 22:30:38 -04:00
using Lambda;
2020-10-13 04:07:04 -04:00
using StringTools;
using flixel.util.FlxSpriteUtil; // add in "compiler save" that saves the JSON directly to the debug json using File.write() stuff on windows / sys
2020-10-13 04:07:04 -04:00
2020-10-09 23:22:07 -04:00
class ChartingState extends MusicBeatState
{
2020-10-09 23:22:07 -04:00
var _file:FileReference;
2020-10-11 20:24:34 -04:00
2020-10-14 04:18:19 -04:00
var UI_box:FlxUITabMenu;
2020-10-11 23:52:21 -04:00
2020-10-11 20:24:34 -04:00
/**
2020-10-11 22:05:26 -04:00
* Array of notes showing when each section STARTS in STEPS
* Usually rounded up??
2020-10-11 20:24:34 -04:00
*/
2020-10-13 04:07:04 -04:00
var curSection:Int = 0;
2021-01-13 22:38:31 -05:00
public static var lastSection:Int = 0;
2020-10-10 05:28:44 -04:00
var bpmTxt:FlxText;
var strumLine:FlxSprite;
2020-10-18 03:27:39 -04:00
var curSong:String = 'Dadbattle';
2020-10-11 20:24:34 -04:00
var amountSteps:Int = 0;
2020-10-11 23:52:21 -04:00
var bullshitUI:FlxGroup;
var highlight:FlxSprite;
2020-10-13 01:18:50 -04:00
2020-10-13 04:07:04 -04:00
var GRID_SIZE:Int = 40;
2020-10-13 01:18:50 -04:00
var dummyArrow:FlxSprite;
2020-10-13 04:07:04 -04:00
var curRenderedNotes:FlxTypedGroup<Note>;
2020-10-18 22:34:21 -04:00
var curRenderedSustains:FlxTypedGroup<FlxSprite>;
2020-10-13 04:07:04 -04:00
2020-10-13 01:18:50 -04:00
var gridBG:FlxSprite;
2020-10-09 23:22:07 -04:00
2020-10-24 05:19:13 -04:00
var _song:SwagSong;
2020-10-13 21:44:07 -04:00
2020-10-14 04:18:19 -04:00
var typingShit:FlxInputText;
2020-10-18 22:51:01 -04:00
/*
* WILL BE THE CURRENT / LAST PLACED NOTE
**/
2022-01-22 16:53:38 -05:00
var curSelectedNote:NoteData;
var tempBpm:Float = 0;
2020-10-29 23:06:52 -04:00
2021-09-20 11:32:35 -04:00
var vocals:VoicesGroup;
2020-10-31 00:25:23 -04:00
2021-01-16 23:15:29 -05:00
var leftIcon:HealthIcon;
var rightIcon:HealthIcon;
2021-09-06 14:50:04 -04:00
var audioBuf:AudioBuffer = new AudioBuffer();
var playheadTest:FlxSprite;
2021-09-20 13:21:25 -04:00
var staticSpecGrp:FlxTypedGroup<SpectogramSprite>;
override function create()
{
2021-01-13 22:38:31 -05:00
curSection = lastSection;
2021-09-06 14:50:04 -04:00
// sys.io.File.saveContent('./bitShit.txt', "swag");
2021-09-16 14:50:02 -04:00
// trace(audioBuf.sampleRate);
2021-09-06 14:50:04 -04:00
2020-10-13 01:18:50 -04:00
gridBG = FlxGridOverlay.create(GRID_SIZE, GRID_SIZE, GRID_SIZE * 8, GRID_SIZE * 16);
add(gridBG);
2021-01-16 23:15:29 -05:00
leftIcon = new HealthIcon('bf');
rightIcon = new HealthIcon('dad');
leftIcon.scrollFactor.set(1, 1);
rightIcon.scrollFactor.set(1, 1);
leftIcon.setGraphicSize(0, 45);
rightIcon.setGraphicSize(0, 45);
add(leftIcon);
add(rightIcon);
leftIcon.setPosition(0, -100);
rightIcon.setPosition(gridBG.width / 2, -100);
2021-01-06 22:38:17 -05:00
var gridBlackLine:FlxSprite = new FlxSprite(gridBG.x + gridBG.width / 2).makeGraphic(2, Std.int(gridBG.height), FlxColor.BLACK);
add(gridBlackLine);
2020-10-13 04:07:04 -04:00
curRenderedNotes = new FlxTypedGroup<Note>();
2020-10-18 22:34:21 -04:00
curRenderedSustains = new FlxTypedGroup<FlxSprite>();
2020-10-13 04:07:04 -04:00
2020-10-13 21:44:07 -04:00
if (PlayState.SONG != null)
2020-10-14 04:30:54 -04:00
_song = PlayState.SONG;
2020-10-13 21:44:07 -04:00
else
{
2022-01-20 22:55:19 -05:00
_song = SongLoad.songData = SongLoad.getDefaultSwagSong();
2020-10-13 21:44:07 -04:00
}
2020-12-25 04:09:14 -05:00
FlxG.mouse.visible = true;
FlxG.save.bind('funkin', 'ninjamuffin99');
2020-10-29 23:06:52 -04:00
tempBpm = _song.bpm;
2020-10-14 04:18:19 -04:00
addSection();
// sections = SongLoad.getSong();
2020-10-13 21:44:07 -04:00
updateGrid();
2020-10-14 04:30:54 -04:00
loadSong(_song.song);
Conductor.changeBPM(_song.bpm);
Conductor.mapBPMChanges(_song);
2020-10-10 05:28:44 -04:00
bpmTxt = new FlxText(1000, 50, 0, "", 16);
bpmTxt.scrollFactor.set();
2020-10-10 05:28:44 -04:00
add(bpmTxt);
2021-09-20 13:21:25 -04:00
strumLine = new FlxSprite(0, 50).makeGraphic(Std.int(GRID_SIZE * 8), 4);
2020-10-10 05:28:44 -04:00
add(strumLine);
2022-01-20 23:33:51 -05:00
dummyArrow = new FlxSprite().makeGraphic(GRID_SIZE, GRID_SIZE, 0xFFCC2288);
dummyArrow.alpha = 0.3;
2020-10-13 01:18:50 -04:00
add(dummyArrow);
2020-10-14 04:18:19 -04:00
var tabs = [
{name: "Song", label: 'Song'},
{name: "Section", label: 'Section'},
{name: "Note", label: 'Note'}
];
UI_box = new FlxUITabMenu(null, tabs, true);
UI_box.resize(300, 400);
2021-09-20 13:21:25 -04:00
UI_box.x = (FlxG.width / 4) * 3;
UI_box.y = 120;
2020-10-14 04:18:19 -04:00
add(UI_box);
2020-10-16 00:22:13 -04:00
addSongUI();
addSectionUI();
2020-10-19 00:01:09 -04:00
addNoteUI();
2020-10-16 00:22:13 -04:00
add(curRenderedNotes);
2020-10-18 22:34:21 -04:00
add(curRenderedSustains);
2020-10-16 00:22:13 -04:00
changeSection();
2020-10-16 00:22:13 -04:00
super.create();
}
function addSongUI():Void
{
2020-10-14 04:30:54 -04:00
var UI_songTitle = new FlxUIInputText(10, 10, 70, _song.song, 8);
2020-10-14 04:18:19 -04:00
typingShit = UI_songTitle;
var check_voices = new FlxUICheckBox(10, 25, null, null, "Has voice track", 100);
2021-01-19 21:09:47 -05:00
check_voices.checked = _song.needsVoices;
// _song.needsVoices = check_voices.checked;
2020-10-14 04:18:19 -04:00
check_voices.callback = function()
{
2020-10-14 04:30:54 -04:00
_song.needsVoices = check_voices.checked;
2020-10-14 04:18:19 -04:00
trace('CHECKED!');
};
2021-01-13 22:38:31 -05:00
var check_mute_inst = new FlxUICheckBox(10, 200, null, null, "Mute Instrumental (in editor)", 100);
check_mute_inst.checked = false;
check_mute_inst.callback = function()
{
var vol:Float = 1;
if (check_mute_inst.checked)
vol = 0;
FlxG.sound.music.volume = vol;
};
2020-10-14 04:18:19 -04:00
var saveButton:FlxButton = new FlxButton(110, 8, "Save", function()
{
saveLevel();
});
2021-09-02 18:51:08 -04:00
var saveCompiler:FlxButton = new FlxButton(110, 30, "Save compile", function()
{
saveLevel(true);
});
2020-10-14 04:18:19 -04:00
var reloadSong:FlxButton = new FlxButton(saveButton.x + saveButton.width + 10, saveButton.y, "Reload Audio", function()
{
2020-10-14 04:30:54 -04:00
loadSong(_song.song);
2020-10-14 04:18:19 -04:00
});
2020-10-17 21:47:59 -04:00
var reloadSongJson:FlxButton = new FlxButton(reloadSong.x, saveButton.y + 30, "Reload JSON", function()
{
loadJson(_song.song.toLowerCase());
});
2020-12-25 18:24:20 -05:00
var loadAutosaveBtn:FlxButton = new FlxButton(reloadSongJson.x, reloadSongJson.y + 30, 'load autosave', loadAutosave);
2020-12-25 04:09:14 -05:00
var stepperSpeed:FlxUINumericStepper = new FlxUINumericStepper(10, 80, 0.1, 1, 0.1, 10, 2);
stepperSpeed.value = SongLoad.getSpeed();
// stepperSpeed.value = _song.speed[SongLoad.curDiff];
2020-10-17 21:47:59 -04:00
stepperSpeed.name = 'song_speed';
var stepperBPM:FlxUINumericStepper = new FlxUINumericStepper(10, 65, 1, 100, 1, 999, 3);
2020-10-17 21:47:59 -04:00
stepperBPM.value = Conductor.bpm;
stepperBPM.name = 'song_bpm';
var characters:Array<String> = CoolUtil.coolTextFile(Paths.txt('characterList'));
2020-10-18 20:59:53 -04:00
var player1DropDown = new FlxUIDropDownMenu(10, 100, FlxUIDropDownMenu.makeStrIdLabelArray(characters, true), function(character:String)
{
_song.player1 = characters[Std.parseInt(character)];
updateHeads();
2020-10-18 20:59:53 -04:00
});
player1DropDown.selectedLabel = _song.player1;
var player2DropDown = new FlxUIDropDownMenu(140, 100, FlxUIDropDownMenu.makeStrIdLabelArray(characters, true), function(character:String)
{
_song.player2 = characters[Std.parseInt(character)];
updateHeads();
2020-10-18 20:59:53 -04:00
});
player2DropDown.selectedLabel = _song.player2;
2020-10-14 04:18:19 -04:00
var tab_group_song = new FlxUI(null, UI_box);
tab_group_song.name = "Song";
tab_group_song.add(UI_songTitle);
tab_group_song.add(check_voices);
2021-01-13 22:38:31 -05:00
tab_group_song.add(check_mute_inst);
2020-10-14 04:18:19 -04:00
tab_group_song.add(saveButton);
2021-09-02 18:51:08 -04:00
tab_group_song.add(saveCompiler);
2020-10-14 04:18:19 -04:00
tab_group_song.add(reloadSong);
2020-10-17 21:47:59 -04:00
tab_group_song.add(reloadSongJson);
2020-12-25 04:09:14 -05:00
tab_group_song.add(loadAutosaveBtn);
2020-10-17 21:47:59 -04:00
tab_group_song.add(stepperBPM);
tab_group_song.add(stepperSpeed);
2020-10-18 20:59:53 -04:00
tab_group_song.add(player1DropDown);
tab_group_song.add(player2DropDown);
2020-10-14 04:18:19 -04:00
UI_box.addGroup(tab_group_song);
UI_box.scrollFactor.set();
2021-09-20 13:21:25 -04:00
FlxG.camera.focusOn(gridBG.getGraphicMidpoint());
2020-10-16 00:22:13 -04:00
}
2020-10-14 04:18:19 -04:00
2020-10-16 00:22:13 -04:00
var stepperLength:FlxUINumericStepper;
var check_mustHitSection:FlxUICheckBox;
2020-10-29 23:06:52 -04:00
var check_changeBPM:FlxUICheckBox;
var stepperSectionBPM:FlxUINumericStepper;
2021-01-16 15:14:56 -05:00
var check_altAnim:FlxUICheckBox;
2020-10-13 04:07:04 -04:00
2020-10-16 00:22:13 -04:00
function addSectionUI():Void
{
var tab_group_section = new FlxUI(null, UI_box);
tab_group_section.name = 'Section';
stepperLength = new FlxUINumericStepper(10, 10, 4, 0, 0, 999, 0);
stepperLength.value = SongLoad.getSong()[curSection].lengthInSteps;
2020-10-16 00:22:13 -04:00
stepperLength.name = "section_length";
stepperSectionBPM = new FlxUINumericStepper(10, 80, 1, Conductor.bpm, 1, 999, 3);
2020-10-29 23:06:52 -04:00
stepperSectionBPM.value = Conductor.bpm;
stepperSectionBPM.name = 'section_bpm';
2020-12-26 21:46:22 -05:00
var stepperCopy:FlxUINumericStepper = new FlxUINumericStepper(110, 130, 1, 1, -999, 999, 0);
2020-10-17 21:47:59 -04:00
2020-12-26 21:46:22 -05:00
var copyButton:FlxButton = new FlxButton(10, 130, "Copy last section", function()
2020-10-17 17:33:35 -04:00
{
2020-10-17 21:47:59 -04:00
copySection(Std.int(stepperCopy.value));
2020-10-17 17:33:35 -04:00
});
2020-12-25 03:40:01 -05:00
var clearSectionButton:FlxButton = new FlxButton(10, 150, "Clear", clearSection);
var swapSection:FlxButton = new FlxButton(10, 170, "Swap section", function()
{
for (i in 0...SongLoad.getSong()[curSection].sectionNotes.length)
2020-12-25 03:40:01 -05:00
{
2022-01-22 16:53:38 -05:00
var note:Note = new Note(0, 0);
note.data = SongLoad.getSong()[curSection].sectionNotes[i];
note.data.noteData = (note.data.noteData + 4) % 8;
2022-01-22 16:53:38 -05:00
SongLoad.getSong()[curSection].sectionNotes[i] = note.data;
2020-12-25 03:40:01 -05:00
updateGrid();
}
});
2020-10-16 00:22:13 -04:00
check_mustHitSection = new FlxUICheckBox(10, 30, null, null, "Must hit section", 100);
check_mustHitSection.name = 'check_mustHit';
check_mustHitSection.checked = true;
// _song.needsVoices = check_mustHit.checked;
2020-10-29 23:06:52 -04:00
2021-01-16 15:14:56 -05:00
check_altAnim = new FlxUICheckBox(10, 400, null, null, "Alt Animation", 100);
check_altAnim.name = 'check_altAnim';
2020-10-29 23:06:52 -04:00
check_changeBPM = new FlxUICheckBox(10, 60, null, null, 'Change BPM', 100);
check_changeBPM.name = 'check_changeBPM';
2020-10-16 00:22:13 -04:00
tab_group_section.add(stepperLength);
2020-10-29 23:06:52 -04:00
tab_group_section.add(stepperSectionBPM);
2020-10-17 21:47:59 -04:00
tab_group_section.add(stepperCopy);
2020-10-16 00:22:13 -04:00
tab_group_section.add(check_mustHitSection);
2021-01-16 15:14:56 -05:00
tab_group_section.add(check_altAnim);
2020-10-29 23:06:52 -04:00
tab_group_section.add(check_changeBPM);
2020-10-17 17:33:35 -04:00
tab_group_section.add(copyButton);
2020-12-25 03:40:01 -05:00
tab_group_section.add(clearSectionButton);
tab_group_section.add(swapSection);
2020-10-16 00:22:13 -04:00
UI_box.addGroup(tab_group_section);
2020-10-10 00:22:26 -04:00
}
2020-10-09 23:22:07 -04:00
2020-10-19 00:01:09 -04:00
var stepperSusLength:FlxUINumericStepper;
var stepperPerNoteSpeed:FlxUINumericStepper;
2020-10-19 00:01:09 -04:00
function addNoteUI():Void
{
var tab_group_note = new FlxUI(null, UI_box);
tab_group_note.name = 'Note';
stepperSusLength = new FlxUINumericStepper(10, 10, Conductor.stepCrochet / 2, 0, 0, Conductor.stepCrochet * 16);
stepperSusLength.value = 0;
stepperSusLength.name = 'note_susLength';
stepperPerNoteSpeed = new FlxUINumericStepper(10, 40, 0.1, 1, 0.01, 100, 2);
stepperPerNoteSpeed.value = 1;
stepperPerNoteSpeed.name = "note_PerNoteSpeed";
var noteSpeedName:FlxText = new FlxText(40, stepperPerNoteSpeed.y, 0, "Note Speed Multiplier");
2020-10-19 00:01:09 -04:00
var applyLength:FlxButton = new FlxButton(100, 10, 'Apply');
tab_group_note.add(stepperSusLength);
tab_group_note.add(stepperPerNoteSpeed);
tab_group_note.add(noteSpeedName);
2020-10-19 00:01:09 -04:00
tab_group_note.add(applyLength);
UI_box.addGroup(tab_group_note);
}
2021-09-20 13:21:25 -04:00
// var spec:SpectogramSprite;
2021-09-17 14:12:36 -04:00
2020-10-14 04:18:19 -04:00
function loadSong(daSong:String):Void
{
if (FlxG.sound.music != null)
2020-10-31 00:25:23 -04:00
{
2020-10-14 04:18:19 -04:00
FlxG.sound.music.stop();
2020-10-31 00:25:23 -04:00
// vocals.stop();
}
2021-08-02 13:54:19 -04:00
var pathShit = Paths.inst(daSong);
if (!openfl.utils.Assets.cache.hasSound(pathShit))
{
var library = Assets.getLibrary("songs");
var symbolPath = pathShit.split(":").pop();
// @:privateAccess
// library.types.set(symbolPath, SOUND);
// @:privateAccess
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
// var callback = callbacks.add("song:" + pathShit);
openfl.utils.Assets.loadSound(pathShit).onComplete(function(_)
{
// callback();
});
}
FlxG.sound.playMusic(Paths.inst(daSong), 0.6);
2020-10-31 00:25:23 -04:00
2021-09-16 15:28:29 -04:00
var musSpec:SpectogramSprite = new SpectogramSprite(FlxG.sound.music, FlxColor.RED);
2021-09-17 14:12:36 -04:00
musSpec.x += 70;
musSpec.daHeight = FlxG.height / 2;
2021-09-16 15:28:29 -04:00
musSpec.scrollFactor.set();
// musSpec.visType = FREQUENCIES;
2021-09-16 15:28:29 -04:00
add(musSpec);
2021-09-16 00:34:51 -04:00
// trace(audioBuf.data.length);
playheadTest = new FlxSprite(0, 0).makeGraphic(2, 60, FlxColor.RED);
2021-09-16 00:34:51 -04:00
playheadTest.scrollFactor.set();
add(playheadTest);
2021-01-19 21:09:47 -05:00
// WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER
2021-09-20 13:21:25 -04:00
vocals = new VoicesGroup(daSong, _song.voiceList);
2021-09-20 11:32:35 -04:00
// vocals = new FlxSound().loadEmbedded(Paths.voices(daSong));
// FlxG.sound.list.add(vocals);
2020-10-14 04:18:19 -04:00
2021-09-20 13:21:25 -04:00
staticSpecGrp = new FlxTypedGroup<SpectogramSprite>();
add(staticSpecGrp);
2021-10-07 21:01:46 -04:00
var aBoy:ABotVis = new ABotVis(FlxG.sound.music);
// add(aBoy);
2021-10-07 21:01:46 -04:00
2021-09-20 13:21:25 -04:00
for (index => voc in vocals.members)
{
var vocalSpec:SpectogramSprite = new SpectogramSprite(voc, FlxG.random.color(0xFFAAAAAA, FlxColor.WHITE, 100));
vocalSpec.x = 70 - (50 * index);
// vocalSpec.visType = FREQUENCIES;
2021-09-20 13:21:25 -04:00
vocalSpec.daHeight = musSpec.daHeight;
vocalSpec.y = vocalSpec.daHeight;
vocalSpec.scrollFactor.set();
add(vocalSpec);
var staticVocal:SpectogramSprite = new SpectogramSprite(voc, FlxG.random.color(0xFFAAAAAA, FlxColor.WHITE, 100));
if (index == 0)
staticVocal.x -= 150;
2021-09-17 14:12:36 -04:00
2021-09-20 13:21:25 -04:00
if (index == 1)
staticVocal.x = gridBG.width;
staticVocal.daHeight = GRID_SIZE * 16;
staticVocal.visType = STATIC;
staticSpecGrp.add(staticVocal);
}
2021-09-16 15:28:29 -04:00
2020-10-14 04:18:19 -04:00
FlxG.sound.music.pause();
2021-09-17 14:12:36 -04:00
2020-10-31 00:25:23 -04:00
vocals.pause();
2020-10-14 04:18:19 -04:00
FlxG.sound.music.onComplete = function()
{
2020-10-31 00:25:23 -04:00
vocals.pause();
vocals.time = 0;
2020-10-14 04:18:19 -04:00
FlxG.sound.music.pause();
FlxG.sound.music.time = 0;
changeSection();
2020-10-14 04:18:19 -04:00
};
}
2020-10-11 23:52:21 -04:00
function generateUI():Void
{
while (bullshitUI.members.length > 0)
{
bullshitUI.remove(bullshitUI.members[0], true);
}
// general shit
var title:FlxText = new FlxText(UI_box.x + 20, UI_box.y + 20, 0);
bullshitUI.add(title);
2020-10-13 01:18:50 -04:00
/*
var loopCheck = new FlxUICheckBox(UI_box.x + 10, UI_box.y + 50, null, null, "Loops", 100, ['loop check']);
loopCheck.checked = notes[0]elected.doesLoop;
2020-10-13 01:18:50 -04:00
tooltips.add(loopCheck, {title: 'Section looping', body: "Whether or not it's a simon says style section", style: tooltipType});
bullshitUI.add(loopCheck);
2020-10-11 23:52:21 -04:00
2020-10-13 01:18:50 -04:00
*/
2020-10-11 23:52:21 -04:00
}
override function getEvent(id:String, sender:Dynamic, data:Dynamic, ?params:Array<Dynamic>)
{
if (id == FlxUICheckBox.CLICK_EVENT)
{
var check:FlxUICheckBox = cast sender;
var label = check.getLabel().text;
switch (label)
{
2020-10-16 00:22:13 -04:00
case 'Must hit section':
SongLoad.getSong()[curSection].mustHitSection = check.checked;
2021-01-16 23:15:29 -05:00
updateHeads();
2020-10-29 23:06:52 -04:00
case 'Change BPM':
SongLoad.getSong()[curSection].changeBPM = check.checked;
2020-10-30 02:52:26 -04:00
FlxG.log.add('changed bpm shit');
2021-01-16 15:14:56 -05:00
case "Alt Animation":
SongLoad.getSong()[curSection].altAnim = check.checked;
2020-10-16 00:22:13 -04:00
}
}
else if (id == FlxUINumericStepper.CHANGE_EVENT && (sender is FlxUINumericStepper))
{
var nums:FlxUINumericStepper = cast sender;
var wname = nums.name;
FlxG.log.add(wname);
if (wname == 'section_length')
{
SongLoad.getSong()[curSection].lengthInSteps = Std.int(nums.value);
updateGrid();
2020-10-11 23:52:21 -04:00
}
2020-10-17 21:47:59 -04:00
else if (wname == 'song_speed')
{
// _song.speed[SongLoad.curDiff] = nums.value;
_song.speed.normal = nums.value;
2020-10-17 21:47:59 -04:00
}
else if (wname == 'song_bpm')
{
tempBpm = nums.value;
Conductor.mapBPMChanges(_song);
Conductor.changeBPM(nums.value);
2020-10-17 21:47:59 -04:00
}
2020-10-19 00:01:09 -04:00
else if (wname == 'note_susLength')
{
2022-01-21 17:23:12 -05:00
curSelectedNote.sustainLength = nums.value;
2020-10-19 00:01:09 -04:00
updateGrid();
}
2020-10-29 23:06:52 -04:00
else if (wname == 'section_bpm')
{
SongLoad.getSong()[curSection].bpm = nums.value;
2020-10-29 23:06:52 -04:00
updateGrid();
}
2020-10-11 23:52:21 -04:00
}
// FlxG.log.add(id + " WEED " + sender + " WEED " + data + " WEED " + params);
}
var updatedSection:Bool = false;
/* this function got owned LOL
2021-03-01 23:00:02 -05:00
function lengthBpmBullshit():Float
{
if (SongLoad.getSong()[curSection].changeBPM)
return SongLoad.getSong()[curSection].lengthInSteps * (SongLoad.getSong()[curSection].bpm / _song.bpm);
2021-03-01 23:00:02 -05:00
else
return SongLoad.getSong()[curSection].lengthInSteps;
}*/
function sectionStartTime():Float
{
var daBPM:Float = _song.bpm;
var daPos:Float = 0;
for (i in 0...curSection)
{
if (SongLoad.getSong()[i].changeBPM)
2021-03-01 23:00:02 -05:00
{
daBPM = SongLoad.getSong()[i].bpm;
}
2022-01-20 23:33:51 -05:00
daPos += 4 * sectionCalc(daBPM);
}
return daPos;
2020-11-13 21:49:20 -05:00
}
2022-01-20 23:33:51 -05:00
function measureStartTime():Float
{
var daBPM:Float = _song.bpm;
var daPos:Float = sectionStartTime();
daPos = Math.floor(FlxG.sound.music.time / sectionCalc(daBPM)) * sectionCalc(daBPM);
return daPos;
}
function sectionCalc(bpm:Float)
{
return (1000 * 60 / bpm);
}
2021-09-20 22:08:24 -04:00
var p1Muted:Bool = false;
var p2Muted:Bool = false;
2020-10-10 00:22:26 -04:00
override function update(elapsed:Float)
{
2021-09-20 13:21:25 -04:00
// FlxG.camera.followLerp = CoolUtil.camLerpShit(0.05);
2021-09-17 14:12:36 -04:00
2020-11-21 05:43:04 -05:00
curStep = recalculateSteps();
2020-10-10 05:28:44 -04:00
Conductor.songPosition = FlxG.sound.music.time;
2020-10-14 04:30:54 -04:00
_song.song = typingShit.text;
2020-10-10 05:28:44 -04:00
2021-09-06 14:50:04 -04:00
playheadTest.x = FlxMath.remapToRange(Conductor.songPosition, 0, FlxG.sound.music.length, 0, FlxG.width);
strumLine.y = getYfromStrum((Conductor.songPosition - sectionStartTime()) % (Conductor.stepCrochet * SongLoad.getSong()[curSection].lengthInSteps));
2020-10-13 04:07:04 -04:00
2021-09-16 00:34:51 -04:00
/* if (FlxG.sound.music.playing)
{
var normalizedShitIDK:Int = Std.int(FlxMath.remapToRange(Conductor.songPosition, 0, FlxG.sound.music.length, 0, audioBuf.data.length));
FlxG.watch.addQuick('WEIRD AUDIO SHIT LOL', audioBuf.data[normalizedShitIDK]);
// leftIcon.scale.x = FlxMath.remapToRange(audioBuf.data[normalizedShitIDK], 0, 255, 1, 2);
}*/
2021-09-06 14:50:04 -04:00
2021-04-10 18:23:56 -04:00
if (FlxG.keys.justPressed.X)
toggleAltAnimNote();
if (curBeat % 4 == 0 && curStep >= 16 * (curSection + 1))
2020-10-13 04:07:04 -04:00
{
trace(curStep);
trace((SongLoad.getSong()[curSection].lengthInSteps) * (curSection + 1));
trace('DUMBSHIT');
2020-10-13 01:18:50 -04:00
if (SongLoad.getSong()[curSection + 1] == null)
{
addSection();
2020-10-13 04:07:04 -04:00
}
changeSection(curSection + 1, false);
2020-10-13 04:07:04 -04:00
}
2020-11-17 19:22:29 -05:00
FlxG.watch.addQuick('daBeat', curBeat);
FlxG.watch.addQuick('daStep', curStep);
2021-09-21 15:39:30 -04:00
if (FlxG.mouse.pressedMiddle)
{
if (FlxG.sound.music.playing)
{
FlxG.sound.music.pause();
vocals.pause();
}
FlxG.sound.music.time = getStrumTime(FlxG.mouse.y) + sectionStartTime();
vocals.time = FlxG.sound.music.time;
}
2021-09-20 22:08:24 -04:00
if (FlxG.mouse.pressed)
2020-10-18 22:34:21 -04:00
{
2021-09-20 22:08:24 -04:00
if (FlxG.keys.pressed.ALT)
{
if (FlxG.sound.music.playing)
{
FlxG.sound.music.pause();
vocals.pause();
}
FlxG.sound.music.time = getStrumTime(FlxG.mouse.y) + sectionStartTime();
vocals.time = FlxG.sound.music.time;
}
else
2020-10-18 22:34:21 -04:00
{
2021-09-20 22:08:24 -04:00
if (FlxG.mouse.justPressed)
2020-10-18 22:34:21 -04:00
{
2021-09-20 22:08:24 -04:00
if (FlxG.mouse.overlaps(leftIcon))
2020-10-18 22:34:21 -04:00
{
2021-09-20 22:08:24 -04:00
if (leftIcon.char == _song.player1)
2020-10-19 00:01:09 -04:00
{
2021-09-20 22:08:24 -04:00
p1Muted = !p1Muted;
leftIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
2020-10-19 00:01:09 -04:00
}
else
{
2021-09-20 22:08:24 -04:00
p2Muted = !p2Muted;
leftIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
}
vocals.members[0].volume = p1Muted ? 0 : 1;
// null check jus in case using old shit?
if (vocals.members[1] != null)
vocals.members[1].volume = p2Muted ? 0 : 1;
}
// sloppy copypaste lol deal with it!
if (FlxG.mouse.overlaps(rightIcon))
{
if (rightIcon.char == _song.player1)
{
p1Muted = !p1Muted;
rightIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
}
else
{
rightIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
p2Muted = !p2Muted;
}
vocals.members[0].volume = p1Muted ? 0 : 1;
// null check jus in case using old shit?
if (vocals.members[1] != null)
vocals.members[1].volume = p2Muted ? 0 : 1;
}
if (FlxG.mouse.overlaps(curRenderedNotes))
{
curRenderedNotes.forEach(function(note:Note)
{
if (FlxG.mouse.overlaps(note))
{
2022-01-21 17:23:12 -05:00
selectNote(note);
2021-09-20 22:08:24 -04:00
}
});
}
else
{
2022-01-21 17:23:12 -05:00
if (FlxG.mouse.overlaps(gridBG))
2021-09-20 22:08:24 -04:00
{
FlxG.log.add('added note');
addNote();
2020-10-19 00:01:09 -04:00
}
2020-10-18 22:34:21 -04:00
}
2020-10-19 21:59:00 -04:00
}
}
2020-10-18 22:34:21 -04:00
}
2022-01-21 17:23:12 -05:00
if (FlxG.mouse.pressedRight)
{
if (FlxG.mouse.overlaps(curRenderedNotes))
{
curRenderedNotes.forEach(function(note:Note)
{
if (FlxG.mouse.overlaps(note))
{
trace('tryin to delete note...');
deleteNote(note);
}
});
}
}
if (FlxG.mouse.overlaps(gridBG))
2020-10-13 01:18:50 -04:00
{
2020-10-13 04:07:04 -04:00
dummyArrow.x = Math.floor(FlxG.mouse.x / GRID_SIZE) * GRID_SIZE;
if (FlxG.keys.pressed.SHIFT)
dummyArrow.y = FlxG.mouse.y;
else
dummyArrow.y = Math.floor(FlxG.mouse.y / GRID_SIZE) * GRID_SIZE;
2020-10-13 01:18:50 -04:00
}
2020-10-13 04:37:19 -04:00
if (FlxG.keys.justPressed.ENTER)
{
2021-09-22 15:33:30 -04:00
autosaveSong();
2021-01-13 22:38:31 -05:00
lastSection = curSection;
2020-10-14 04:30:54 -04:00
PlayState.SONG = _song;
2021-09-08 11:53:20 -04:00
// JUST FOR DEBUG DARNELL STUFF, GENERALIZE THIS FOR BETTER LOADING ELSEWHERE TOO!
PlayState.storyWeek = 8;
2020-10-13 21:23:22 -04:00
FlxG.sound.music.stop();
2020-10-31 00:25:23 -04:00
vocals.stop();
2021-08-02 13:54:19 -04:00
LoadingState.loadAndSwitchState(new PlayState());
// FlxG.switchState(new PlayState());
2020-10-13 04:37:19 -04:00
}
2021-01-13 22:38:31 -05:00
if (FlxG.keys.justPressed.E)
{
changeNoteSustain(Conductor.stepCrochet);
}
if (FlxG.keys.justPressed.Q)
{
changeNoteSustain(-Conductor.stepCrochet);
}
2021-01-07 20:38:32 -05:00
if (FlxG.keys.justPressed.TAB)
{
if (FlxG.keys.pressed.SHIFT)
{
UI_box.selected_tab -= 1;
if (UI_box.selected_tab < 0)
UI_box.selected_tab = 2;
}
else
{
UI_box.selected_tab += 1;
if (UI_box.selected_tab >= 3)
UI_box.selected_tab = 0;
}
}
2020-10-14 04:18:19 -04:00
if (!typingShit.hasFocus)
2020-10-10 00:22:26 -04:00
{
2020-10-14 04:18:19 -04:00
if (FlxG.keys.justPressed.SPACE)
2020-10-10 05:28:44 -04:00
{
2020-10-14 04:18:19 -04:00
if (FlxG.sound.music.playing)
{
FlxG.sound.music.pause();
2020-10-31 00:25:23 -04:00
vocals.pause();
2020-10-14 04:18:19 -04:00
}
else
2020-10-31 00:25:23 -04:00
{
vocals.play();
2020-10-14 04:18:19 -04:00
FlxG.sound.music.play();
2020-10-31 00:25:23 -04:00
}
2020-10-10 05:28:44 -04:00
}
2020-10-14 04:18:19 -04:00
if (FlxG.keys.justPressed.R)
{
2022-01-20 23:33:51 -05:00
if (FlxG.keys.pressed.CONTROL)
resetSection(BEGINNING);
else if (FlxG.keys.pressed.SHIFT)
resetSection(MEASURE);
2021-01-07 20:38:32 -05:00
else
2022-01-20 23:33:51 -05:00
resetSection(SECTION);
2021-01-06 23:02:23 -05:00
}
if (FlxG.mouse.wheel != 0)
{
FlxG.sound.music.pause();
vocals.pause();
2021-09-20 13:21:25 -04:00
var ctrlMod:Float = FlxG.keys.pressed.CONTROL ? 0.1 : 1;
var shiftMod:Float = FlxG.keys.pressed.SHIFT ? 2 : 1;
FlxG.sound.music.time -= (FlxG.mouse.wheel * Conductor.stepCrochet * 0.4 * ctrlMod * shiftMod);
2021-01-06 23:02:23 -05:00
vocals.time = FlxG.sound.music.time;
2020-10-14 04:18:19 -04:00
}
2020-10-14 00:05:55 -04:00
if (FlxG.keys.justReleased.S)
{
FlxG.sound.music.pause();
vocals.pause();
#if HAS_PITCH
FlxG.sound.music.pitch = 1;
vocals.pitch = 1;
#end
}
2020-12-25 18:24:20 -05:00
if (!FlxG.keys.pressed.SHIFT)
2020-10-14 04:18:19 -04:00
{
2020-12-25 18:24:20 -05:00
if (FlxG.keys.pressed.W || FlxG.keys.pressed.S)
{
var daTime:Float = 700 * FlxG.elapsed;
2020-10-14 00:05:55 -04:00
2021-09-16 15:28:29 -04:00
if (FlxG.keys.pressed.CONTROL)
daTime *= 0.2;
2020-12-25 18:24:20 -05:00
if (FlxG.keys.pressed.W)
{
FlxG.sound.music.pause();
vocals.pause();
2020-12-25 18:24:20 -05:00
FlxG.sound.music.time -= daTime;
vocals.time = FlxG.sound.music.time;
2020-12-25 18:24:20 -05:00
}
else
{
if (FlxG.keys.justPressed.S)
{
FlxG.sound.music.play();
vocals.play();
2020-12-25 18:24:20 -05:00
#if HAS_PITCH
FlxG.sound.music.pitch = 0.5;
vocals.pitch = 0.5;
#end
}
}
// FlxG.sound.music.time += daTime;
// vocals.time = FlxG.sound.music.time;
2020-10-14 04:18:19 -04:00
}
2020-12-25 18:24:20 -05:00
}
else
{
if (FlxG.keys.justPressed.W || FlxG.keys.justPressed.S)
{
var daTime:Float = Conductor.stepCrochet * 2;
2020-10-31 00:25:23 -04:00
2020-12-25 18:24:20 -05:00
if (FlxG.keys.justPressed.W)
{
FlxG.sound.music.pause();
vocals.pause();
2020-12-25 18:24:20 -05:00
FlxG.sound.music.time -= daTime;
vocals.time = FlxG.sound.music.time;
2020-12-25 18:24:20 -05:00
}
else
{
if (FlxG.keys.justPressed.S)
{
// FlxG.sound.music.time += daTime;
FlxG.sound.music.play();
vocals.play();
2020-12-25 18:24:20 -05:00
#if HAS_PITCH
FlxG.sound.music.pitch = 0.2;
vocals.pitch = 0.2;
#end
}
}
2020-12-25 18:24:20 -05:00
}
2020-10-14 00:05:55 -04:00
}
2020-10-13 04:07:04 -04:00
}
2020-10-29 23:06:52 -04:00
_song.bpm = tempBpm;
2020-10-14 04:30:54 -04:00
2020-10-29 23:06:52 -04:00
/* if (FlxG.keys.justPressed.UP)
Conductor.changeBPM(Conductor.bpm + 1);
if (FlxG.keys.justPressed.DOWN)
Conductor.changeBPM(Conductor.bpm - 1); */
2020-10-10 05:28:44 -04:00
2020-12-09 13:53:46 -05:00
var shiftThing:Int = 1;
if (FlxG.keys.pressed.SHIFT)
shiftThing = 4;
2021-01-06 23:02:23 -05:00
if (FlxG.keys.justPressed.RIGHT || FlxG.keys.justPressed.D)
2020-12-09 13:53:46 -05:00
changeSection(curSection + shiftThing);
2021-01-06 23:02:23 -05:00
if (FlxG.keys.justPressed.LEFT || FlxG.keys.justPressed.A)
2020-12-09 13:53:46 -05:00
changeSection(curSection - shiftThing);
2020-10-13 04:07:04 -04:00
2021-09-20 13:21:25 -04:00
bpmTxt.text = bpmTxt.text = Std.string(FlxMath.roundDecimal(Conductor.songPosition / 1000, 3))
2020-12-09 13:53:46 -05:00
+ " / "
2021-09-20 13:21:25 -04:00
+ Std.string(FlxMath.roundDecimal(FlxG.sound.music.length / 1000, 3))
2020-12-09 13:53:46 -05:00
+ "\nSection: "
+ curSection;
2020-10-10 00:22:26 -04:00
super.update(elapsed);
}
2021-01-13 22:38:31 -05:00
function changeNoteSustain(value:Float):Void
{
2021-01-20 07:19:48 -05:00
if (curSelectedNote != null)
2021-01-13 22:38:31 -05:00
{
2022-01-21 17:23:12 -05:00
curSelectedNote.sustainLength += value;
curSelectedNote.sustainLength = Math.max(curSelectedNote.sustainLength, 0);
2021-01-13 22:38:31 -05:00
}
updateNoteUI();
updateGrid();
}
2021-04-10 18:23:56 -04:00
function toggleAltAnimNote():Void
{
if (curSelectedNote != null)
{
2022-01-21 17:23:12 -05:00
trace('ALT NOTE SHIT');
curSelectedNote.altNote = !curSelectedNote.altNote;
trace(curSelectedNote.altNote);
2021-04-10 18:23:56 -04:00
}
}
2020-11-21 05:43:04 -05:00
function recalculateSteps():Int
{
var lastChange:BPMChangeEvent = {
stepTime: 0,
songTime: 0,
bpm: 0
}
for (i in 0...Conductor.bpmChangeMap.length)
2020-11-21 05:43:04 -05:00
{
if (FlxG.sound.music.time > Conductor.bpmChangeMap[i].songTime)
lastChange = Conductor.bpmChangeMap[i];
2020-11-21 05:43:04 -05:00
}
curStep = lastChange.stepTime + Math.floor((FlxG.sound.music.time - lastChange.songTime) / Conductor.stepCrochet);
2020-11-21 05:43:04 -05:00
updateBeat();
return curStep;
}
2022-01-20 23:33:51 -05:00
function resetSection(songBeginning:SongResetType = SECTION):Void
2021-01-06 23:02:23 -05:00
{
updateGrid();
FlxG.sound.music.pause();
vocals.pause();
2022-01-20 23:33:51 -05:00
switch (songBeginning)
2021-01-07 20:38:32 -05:00
{
2022-01-20 23:33:51 -05:00
case SECTION:
// Basically old shit from changeSection???
FlxG.sound.music.time = sectionStartTime();
case BEGINNING:
FlxG.sound.music.time = 0;
curSection = 0;
case MEASURE:
FlxG.sound.music.time = measureStartTime(); // Math.floor(FlxG.mouse.y / GRID_SIZE) * GRID_SIZE
default:
2021-01-07 20:38:32 -05:00
}
2021-01-06 23:02:23 -05:00
vocals.time = FlxG.sound.music.time;
updateCurStep();
updateGrid();
updateSectionUI();
}
2020-10-13 04:07:04 -04:00
function changeSection(sec:Int = 0, ?updateMusic:Bool = true):Void
{
trace('changing section' + sec);
if (SongLoad.getSong()[sec] != null)
2020-10-13 04:07:04 -04:00
{
curSection = sec;
2020-10-30 02:52:26 -04:00
updateGrid();
2020-10-13 04:07:04 -04:00
if (updateMusic)
{
FlxG.sound.music.pause();
2020-10-31 00:25:23 -04:00
vocals.pause();
2020-10-13 04:07:04 -04:00
/*var daNum:Int = 0;
2021-03-01 23:00:02 -05:00
var daLength:Float = 0;
while (daNum <= sec)
{
daLength += lengthBpmBullshit();
daNum++;
}*/
2020-10-13 04:07:04 -04:00
FlxG.sound.music.time = sectionStartTime();
2020-10-31 00:25:23 -04:00
vocals.time = FlxG.sound.music.time;
updateCurStep();
2020-10-13 04:07:04 -04:00
}
2020-10-16 00:22:13 -04:00
2020-10-29 23:06:52 -04:00
updateGrid();
2020-10-16 00:22:13 -04:00
updateSectionUI();
2020-10-13 04:07:04 -04:00
}
}
2020-10-17 21:47:59 -04:00
function copySection(?sectionNum:Int = 1)
2020-10-17 17:33:35 -04:00
{
2020-10-17 21:47:59 -04:00
var daSec = FlxMath.maxInt(curSection, sectionNum);
2020-10-17 17:33:35 -04:00
2022-01-22 16:53:38 -05:00
for (noteShit in SongLoad.getSong()[daSec - sectionNum].sectionNotes)
2020-10-17 17:33:35 -04:00
{
2022-01-22 16:53:38 -05:00
var strum = noteShit.strumTime + Conductor.stepCrochet * (SongLoad.getSong()[daSec].lengthInSteps * sectionNum);
2020-10-18 22:18:06 -04:00
2022-01-22 16:53:38 -05:00
var copiedNote:Note = new Note(strum, noteShit.noteData);
copiedNote.data.sustainLength = noteShit.sustainLength;
SongLoad.getSong()[daSec].sectionNotes.push(copiedNote.data);
2020-10-17 17:33:35 -04:00
}
updateGrid();
}
2020-10-16 00:22:13 -04:00
function updateSectionUI():Void
{
var sec = SongLoad.getSong()[curSection];
2020-10-16 00:22:13 -04:00
stepperLength.value = sec.lengthInSteps;
check_mustHitSection.checked = sec.mustHitSection;
2021-01-16 15:14:56 -05:00
check_altAnim.checked = sec.altAnim;
2020-10-29 23:06:52 -04:00
check_changeBPM.checked = sec.changeBPM;
stepperSectionBPM.value = sec.bpm;
2021-01-16 23:15:29 -05:00
updateHeads();
}
function updateHeads():Void
{
if (check_mustHitSection.checked)
{
leftIcon.changeIcon(_song.player1);
rightIcon.changeIcon(_song.player2);
2021-09-20 22:08:24 -04:00
leftIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
rightIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
2021-01-16 23:15:29 -05:00
}
else
{
leftIcon.changeIcon(_song.player2);
rightIcon.changeIcon(_song.player1);
2021-09-20 22:08:24 -04:00
leftIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
rightIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
2021-01-16 23:15:29 -05:00
}
leftIcon.setGraphicSize(0, 45);
rightIcon.setGraphicSize(0, 45);
leftIcon.height *= 0.6;
rightIcon.height *= 0.6;
2020-10-16 00:22:13 -04:00
}
2020-10-19 00:01:09 -04:00
function updateNoteUI():Void
{
2021-01-20 07:19:48 -05:00
if (curSelectedNote != null)
2022-01-21 17:23:12 -05:00
stepperSusLength.value = curSelectedNote.sustainLength;
2020-10-19 00:01:09 -04:00
}
2020-10-13 04:07:04 -04:00
function updateGrid():Void
{
2021-09-20 13:21:25 -04:00
// null if checks jus cuz i put updateGrid() in some weird places!
if (staticSpecGrp != null)
{
staticSpecGrp.forEach(function(spec)
{
if (spec != null)
spec.generateSection(sectionStartTime(), (Conductor.stepCrochet * 32) / 1000);
});
}
2021-09-17 14:12:36 -04:00
2020-10-13 04:07:04 -04:00
while (curRenderedNotes.members.length > 0)
{
curRenderedNotes.remove(curRenderedNotes.members[0], true);
}
2020-10-18 22:34:21 -04:00
while (curRenderedSustains.members.length > 0)
{
curRenderedSustains.remove(curRenderedSustains.members[0], true);
}
2022-01-22 16:53:38 -05:00
var sectionInfo:Array<NoteData> = SongLoad.getSong()[curSection].sectionNotes;
2020-10-13 04:07:04 -04:00
if (SongLoad.getSong()[curSection].changeBPM && SongLoad.getSong()[curSection].bpm > 0)
2020-10-29 23:06:52 -04:00
{
Conductor.changeBPM(SongLoad.getSong()[curSection].bpm);
FlxG.log.add('CHANGED BPM!');
2020-10-29 23:06:52 -04:00
}
else
{
2021-03-01 23:00:02 -05:00
// get last bpm
var daBPM:Float = _song.bpm;
for (i in 0...curSection)
if (SongLoad.getSong()[i].changeBPM)
daBPM = SongLoad.getSong()[i].bpm;
Conductor.changeBPM(daBPM);
2020-10-29 23:06:52 -04:00
}
2020-10-18 22:34:21 -04:00
/* // PORT BULLSHIT, INCASE THERE'S NO SUSTAIN DATA FOR A NOTE
for (sec in 0...SongLoad.getSong().length)
2020-10-18 22:34:21 -04:00
{
for (notesse in 0...SongLoad.getSong()[sec].sectionNotes.length)
2020-10-18 22:34:21 -04:00
{
if (SongLoad.getSong()[sec].sectionNotes[notesse][2] == null)
2020-10-18 22:34:21 -04:00
{
trace('SUS NULL');
SongLoad.getSong()[sec].sectionNotes[notesse][2] = 0;
2020-10-18 22:34:21 -04:00
}
}
}
*/
2020-10-13 04:07:04 -04:00
for (i in sectionInfo)
{
2022-01-21 17:23:12 -05:00
var daNoteInfo = i.noteData;
var daStrumTime = i.strumTime;
var daSus = i.sustainLength;
2020-10-13 04:07:04 -04:00
2020-10-18 22:18:06 -04:00
var note:Note = new Note(daStrumTime, daNoteInfo % 4);
2022-01-22 16:53:38 -05:00
note.data.sustainLength = daSus;
2020-10-13 04:07:04 -04:00
note.setGraphicSize(GRID_SIZE, GRID_SIZE);
note.updateHitbox();
2020-10-18 22:18:06 -04:00
note.x = Math.floor(daNoteInfo * GRID_SIZE);
note.y = Math.floor(getYfromStrum((daStrumTime - sectionStartTime()) % (Conductor.stepCrochet * SongLoad.getSong()[curSection].lengthInSteps)));
2020-10-13 04:07:04 -04:00
curRenderedNotes.add(note);
2020-10-18 22:51:01 -04:00
if (daSus > 0)
{
2020-10-21 16:12:32 -04:00
var sustainVis:FlxSprite = new FlxSprite(note.x + (GRID_SIZE / 2),
2020-10-29 23:06:52 -04:00
note.y + GRID_SIZE).makeGraphic(8, Math.floor(FlxMath.remapToRange(daSus, 0, Conductor.stepCrochet * 16, 0, gridBG.height)));
2020-10-18 22:51:01 -04:00
curRenderedSustains.add(sustainVis);
}
2020-10-13 04:07:04 -04:00
}
}
private function addSection(lengthInSteps:Int = 16):Void
{
2020-10-29 23:06:52 -04:00
var sec:SwagSection = {
lengthInSteps: lengthInSteps,
bpm: _song.bpm,
changeBPM: false,
mustHitSection: true,
sectionNotes: [],
2021-01-16 15:14:56 -05:00
typeOfSection: 0,
altAnim: false
2020-10-29 23:06:52 -04:00
};
SongLoad.getSong().push(sec);
2020-10-13 04:07:04 -04:00
}
2020-10-19 00:01:09 -04:00
function selectNote(note:Note):Void
{
var swagNum:Int = 0;
for (i in SongLoad.getSong()[curSection].sectionNotes)
2020-10-19 00:01:09 -04:00
{
2022-01-22 16:53:38 -05:00
if (i.strumTime == note.data.strumTime && i.noteData % 4 == note.data.noteData)
2020-10-19 00:01:09 -04:00
{
curSelectedNote = SongLoad.getSong()[curSection].sectionNotes[swagNum];
2020-10-19 00:01:09 -04:00
}
swagNum += 1;
}
updateGrid();
updateNoteUI();
}
2020-10-13 21:23:22 -04:00
function deleteNote(note:Note):Void
{
for (i in SongLoad.getSong()[curSection].sectionNotes)
2020-10-13 21:23:22 -04:00
{
if (i.strumTime == note.data.strumTime && i.noteData % 4 == note.data.noteData)
2020-10-13 21:23:22 -04:00
{
2021-09-16 00:56:49 -04:00
var placeIDK:Int = Std.int(((Math.floor(dummyArrow.y / GRID_SIZE) * GRID_SIZE)) / 40);
placeIDK = Std.int(Math.min(placeIDK, 15));
placeIDK = Std.int(Math.max(placeIDK, 1));
trace(placeIDK);
FlxG.sound.play(Paths.sound('funnyNoise/funnyNoise-0' + placeIDK));
2020-10-13 21:23:22 -04:00
FlxG.log.add('FOUND EVIL NUMBER');
SongLoad.getSong()[curSection].sectionNotes.remove(i);
2020-10-13 21:23:22 -04:00
}
}
2020-10-28 22:47:10 -04:00
updateGrid();
}
2020-12-25 03:40:01 -05:00
function clearSection():Void
{
SongLoad.getSong()[curSection].sectionNotes = [];
2020-12-25 03:40:01 -05:00
updateGrid();
}
2020-10-28 22:47:10 -04:00
function clearSong():Void
{
for (daSection in 0...SongLoad.getSong().length)
2020-10-28 22:47:10 -04:00
{
SongLoad.getSong()[daSection].sectionNotes = [];
2020-10-28 22:47:10 -04:00
}
2020-10-13 21:23:22 -04:00
updateGrid();
}
2020-10-13 01:18:50 -04:00
private function addNote():Void
{
var noteStrum = getStrumTime(dummyArrow.y) + sectionStartTime();
2020-10-18 22:51:01 -04:00
var noteData = Math.floor(FlxG.mouse.x / GRID_SIZE);
var noteSus = 0;
2021-04-10 18:23:56 -04:00
var noteAlt = false;
2020-10-18 22:51:01 -04:00
2021-09-16 00:34:51 -04:00
// FlxG.sound.play(Paths.sound('pianoStuff/piano-00' + FlxG.random.int(1, 9)), FlxG.random.float(0.01, 0.3));
switch (noteData)
{
case 0:
FlxG.sound.play(Paths.sound('pianoStuff/piano-015'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-013'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-009'), FlxG.random.float(0.1, 0.3));
case 1:
FlxG.sound.play(Paths.sound('pianoStuff/piano-015'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-012'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-009'), FlxG.random.float(0.1, 0.3));
case 2:
FlxG.sound.play(Paths.sound('pianoStuff/piano-015'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-011'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-009'), FlxG.random.float(0.1, 0.3));
case 3:
FlxG.sound.play(Paths.sound('pianoStuff/piano-014'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-011'), FlxG.random.float(0.1, 0.3));
FlxG.sound.play(Paths.sound('pianoStuff/piano-010'), FlxG.random.float(0.1, 0.3));
}
var bullshit:Int = Std.int((Math.floor(dummyArrow.y / GRID_SIZE) * GRID_SIZE) / 40);
FlxG.sound.play(Paths.sound('pianoStuff/piano-00' + Std.string((bullshit % 8) + 1)), FlxG.random.float(0.3, 0.6));
// trace('bullshit $bullshit'); // trace(Math.floor(dummyArrow.y / GRID_SIZE) * GRID_SIZE);
2022-01-21 17:23:12 -05:00
var daNewNote:Note = new Note(noteStrum, noteData);
daNewNote.sustainLength = noteSus;
2022-01-22 16:58:59 -05:00
daNewNote.data.altNote = noteAlt;
2022-01-22 16:53:38 -05:00
SongLoad.getSong()[curSection].sectionNotes.push(daNewNote.data);
2020-10-18 20:59:53 -04:00
curSelectedNote = SongLoad.getSong()[curSection].sectionNotes[SongLoad.getSong()[curSection].sectionNotes.length - 1];
2020-10-13 05:55:00 -04:00
2021-01-06 22:38:17 -05:00
if (FlxG.keys.pressed.CONTROL)
{
2022-01-21 17:23:12 -05:00
// SongLoad.getSong()[curSection].sectionNotes.push([noteStrum, (noteData + 4) % 8, noteSus, noteAlt]);
2021-01-06 22:38:17 -05:00
}
trace(noteStrum);
2020-10-13 05:55:00 -04:00
trace(curSection);
2020-10-13 04:07:04 -04:00
updateGrid();
2020-10-19 00:01:09 -04:00
updateNoteUI();
2020-12-25 04:09:14 -05:00
2022-01-22 16:53:38 -05:00
autosaveSong();
2020-10-13 01:18:50 -04:00
}
function getStrumTime(yPos:Float):Float
{
2020-10-13 05:36:45 -04:00
return FlxMath.remapToRange(yPos, gridBG.y, gridBG.y + gridBG.height, 0, 16 * Conductor.stepCrochet);
2020-10-13 04:07:04 -04:00
}
2020-10-13 05:55:00 -04:00
function getYfromStrum(strumTime:Float):Float
2020-10-13 04:07:04 -04:00
{
2020-10-13 05:55:00 -04:00
return FlxMath.remapToRange(strumTime, 0, 16 * Conductor.stepCrochet, gridBG.y, gridBG.y + gridBG.height);
2020-10-13 01:18:50 -04:00
}
/*
2021-03-01 23:00:02 -05:00
function calculateSectionLengths(?sec:SwagSection):Int
{
2021-03-01 23:00:02 -05:00
var daLength:Int = 0;
for (i in SongLoad.getSong())
2021-03-01 23:00:02 -05:00
{
var swagLength = i.lengthInSteps;
2021-03-01 23:00:02 -05:00
if (i.typeOfSection == Section.COPYCAT)
swagLength * 2;
2021-03-01 23:00:02 -05:00
daLength += swagLength;
if (sec != null && sec == i)
{
trace('swag loop??');
break;
}
}
2021-03-01 23:00:02 -05:00
return daLength;
}*/
2020-10-10 05:28:44 -04:00
private var daSpacing:Float = 0.3;
2020-10-13 21:44:07 -04:00
function loadLevel():Void
{
trace(SongLoad.getSong());
2020-10-13 21:44:07 -04:00
}
2020-10-13 04:37:19 -04:00
function getNotes():Array<Dynamic>
2020-10-10 00:22:26 -04:00
{
2020-10-13 04:07:04 -04:00
var noteData:Array<Dynamic> = [];
for (i in SongLoad.getSong())
2020-10-13 04:07:04 -04:00
{
2020-10-18 20:59:53 -04:00
noteData.push(i.sectionNotes);
2020-10-13 04:07:04 -04:00
}
2020-10-13 04:37:19 -04:00
return noteData;
}
2020-10-17 21:47:59 -04:00
function loadJson(song:String):Void
{
PlayState.SONG = SongLoad.loadFromJson(song.toLowerCase(), song.toLowerCase());
2021-04-19 04:35:39 -04:00
LoadingState.loadAndSwitchState(new ChartingState());
2020-10-17 21:47:59 -04:00
}
2020-12-25 04:09:14 -05:00
function loadAutosave():Void
{
PlayState.SONG = SongLoad.parseJSONshit(FlxG.save.data.autosave);
2020-12-25 04:09:14 -05:00
FlxG.resetState();
}
2020-12-25 04:09:14 -05:00
function autosaveSong():Void
{
2022-01-22 16:53:38 -05:00
FlxG.save.data.autosave = _song;
trace(FlxG.save.data.autosave);
2020-12-25 04:09:14 -05:00
FlxG.save.flush();
}
2021-09-02 18:51:08 -04:00
private function saveLevel(?debugSavepath:Bool = false)
2020-10-13 04:37:19 -04:00
{
2020-10-10 00:22:26 -04:00
var json = {
"song": _song
2020-10-10 00:22:26 -04:00
};
var data:String = Json.stringify(json);
2021-09-02 18:51:08 -04:00
#if sys
// quick workaround, since it easier to load into hashlink, thus quicker/nicer to test?
// should get this auto-saved into a file or somethin
var filename = _song.song.toLowerCase();
2021-09-02 18:51:08 -04:00
if (debugSavepath)
{
// file path to assumingly your assets folder in your SOURCE CODE assets folder!!!
// update this later so the save button ONLY appears when you compile in debug mode!
2021-09-02 18:51:08 -04:00
sys.io.File.saveContent('../../../../assets/preload/data/$filename/$filename.json', data);
}
else
sys.io.File.saveContent('./$filename.json', data);
#else
2020-10-10 00:22:26 -04:00
if ((data != null) && (data.length > 0))
{
_file = new FileReference();
_file.addEventListener(Event.COMPLETE, onSaveComplete);
_file.addEventListener(Event.CANCEL, onSaveCancel);
_file.addEventListener(IOErrorEvent.IO_ERROR, onSaveError);
2020-10-18 22:18:06 -04:00
_file.save(data.trim(), _song.song.toLowerCase() + ".json");
2020-10-10 00:22:26 -04:00
}
#end
}
2020-10-09 23:22:07 -04:00
function onSaveComplete(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
FlxG.log.notice("Successfully saved LEVEL DATA.");
}
/**
* Called when the save file dialog is cancelled.
*/
function onSaveCancel(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
}
/**
* Called if there is an error while saving the gameplay recording.
*/
function onSaveError(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
FlxG.log.error("Problem saving Level data");
}
}
2022-01-20 23:33:51 -05:00
enum SongResetType
{
BEGINNING;
MEASURE; // not sure if measure is 1/4 of a "SECTION" which is definitely a... bar.. right? its nerd shit whatever
SECTION;
}