2020-10-09 22:39:52 -04:00
|
|
|
package;
|
|
|
|
|
2020-10-09 23:22:07 -04:00
|
|
|
import flixel.FlxG;
|
2020-10-10 05:28:44 -04:00
|
|
|
import flixel.FlxSprite;
|
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-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;
|
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;
|
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-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;
|
2020-10-09 23:22:07 -04:00
|
|
|
import haxe.Json;
|
|
|
|
import openfl.events.Event;
|
|
|
|
import openfl.events.IOErrorEvent;
|
|
|
|
import openfl.events.IOErrorEvent;
|
|
|
|
import openfl.events.IOErrorEvent;
|
|
|
|
import openfl.net.FileReference;
|
2020-10-09 22:39:52 -04:00
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
using StringTools;
|
|
|
|
|
2020-10-09 23:22:07 -04:00
|
|
|
class ChartingState extends MusicBeatState
|
2020-10-09 22:39:52 -04:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
var sectionInfo:Array<Dynamic>;
|
2020-10-13 01:18:50 -04:00
|
|
|
|
2020-10-10 05:28:44 -04:00
|
|
|
var bpmTxt:FlxText;
|
|
|
|
|
|
|
|
var strumLine:FlxSprite;
|
2020-10-16 00:22:13 -04:00
|
|
|
var curSong:String = 'Tutorial';
|
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-13 01:18:50 -04:00
|
|
|
var gridBG:FlxSprite;
|
2020-10-09 23:22:07 -04:00
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
var _song:Song;
|
2020-10-13 21:44:07 -04:00
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
var typingShit:FlxInputText;
|
2020-10-16 07:03:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* What part of the SECTION it's on, relative to the grid.
|
|
|
|
*/
|
|
|
|
var page:Int = 1;
|
2020-10-14 04:18:19 -04:00
|
|
|
|
2020-10-09 22:39:52 -04:00
|
|
|
override function create()
|
|
|
|
{
|
2020-10-13 01:18:50 -04:00
|
|
|
gridBG = FlxGridOverlay.create(GRID_SIZE, GRID_SIZE, GRID_SIZE * 8, GRID_SIZE * 16);
|
|
|
|
add(gridBG);
|
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
curRenderedNotes = new FlxTypedGroup<Note>();
|
|
|
|
|
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
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
_song = new Song(curSong, [], Conductor.bpm, 0);
|
2020-10-13 21:44:07 -04:00
|
|
|
}
|
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
addSection();
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
// sections = _song.notes;
|
2020-10-13 21:44:07 -04:00
|
|
|
|
|
|
|
updateGrid();
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
loadSong(_song.song);
|
|
|
|
Conductor.changeBPM(_song.bpm);
|
2020-10-10 05:28:44 -04:00
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
bpmTxt = new FlxText(1000, 50, 0, "", 16);
|
|
|
|
bpmTxt.scrollFactor.set();
|
2020-10-10 05:28:44 -04:00
|
|
|
add(bpmTxt);
|
|
|
|
|
|
|
|
strumLine = new FlxSprite(0, 50).makeGraphic(Std.int(FlxG.width / 2), 4);
|
|
|
|
add(strumLine);
|
|
|
|
|
2020-10-13 01:18:50 -04:00
|
|
|
dummyArrow = new FlxSprite().makeGraphic(GRID_SIZE, GRID_SIZE);
|
|
|
|
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);
|
|
|
|
UI_box.x = FlxG.width / 2;
|
|
|
|
UI_box.y = 20;
|
|
|
|
add(UI_box);
|
|
|
|
|
2020-10-16 00:22:13 -04:00
|
|
|
addSongUI();
|
|
|
|
addSectionUI();
|
|
|
|
|
|
|
|
add(curRenderedNotes);
|
|
|
|
|
|
|
|
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);
|
2020-10-14 04:30:54 -04:00
|
|
|
check_voices.checked = true;
|
|
|
|
_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!');
|
|
|
|
};
|
|
|
|
|
|
|
|
var saveButton:FlxButton = new FlxButton(110, 8, "Save", function()
|
|
|
|
{
|
|
|
|
saveLevel();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
tab_group_song.add(saveButton);
|
|
|
|
tab_group_song.add(reloadSong);
|
|
|
|
|
|
|
|
UI_box.addGroup(tab_group_song);
|
2020-10-16 07:03:10 -04:00
|
|
|
UI_box.scrollFactor.set();
|
|
|
|
|
|
|
|
FlxG.camera.follow(strumLine);
|
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-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 = _song.notes[curSection].lengthInSteps;
|
|
|
|
stepperLength.name = "section_length";
|
|
|
|
|
|
|
|
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;
|
|
|
|
check_mustHitSection.callback = function()
|
|
|
|
{
|
|
|
|
// _song.needsVoices = check_mustHit.checked;
|
|
|
|
trace('CHECKED!');
|
|
|
|
};
|
|
|
|
|
|
|
|
tab_group_section.add(stepperLength);
|
|
|
|
tab_group_section.add(check_mustHitSection);
|
|
|
|
|
|
|
|
UI_box.addGroup(tab_group_section);
|
2020-10-10 00:22:26 -04:00
|
|
|
}
|
2020-10-09 23:22:07 -04:00
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
function loadSong(daSong:String):Void
|
|
|
|
{
|
|
|
|
if (FlxG.sound.music != null)
|
|
|
|
FlxG.sound.music.stop();
|
|
|
|
|
|
|
|
FlxG.sound.playMusic('assets/music/' + daSong + '.mp3', 0.6);
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
FlxG.sound.music.onComplete = function()
|
|
|
|
{
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
FlxG.sound.music.time = 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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 = curNoteSelected.doesLoop;
|
|
|
|
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':
|
|
|
|
_song.notes[curSection].mustHitSection = check.checked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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')
|
|
|
|
{
|
|
|
|
_song.notes[curSection].lengthInSteps = Std.int(nums.value);
|
2020-10-16 07:03:10 -04:00
|
|
|
updateGrid();
|
2020-10-11 23:52:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FlxG.log.add(id + " WEED " + sender + " WEED " + data + " WEED " + params);
|
|
|
|
}
|
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
var updatedSection:Bool = false;
|
|
|
|
|
2020-10-10 00:22:26 -04:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
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
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
strumLine.y = getYfromStrum(Conductor.songPosition % (Conductor.stepCrochet * _song.notes[curSection].lengthInSteps));
|
2020-10-13 04:07:04 -04:00
|
|
|
|
|
|
|
if (curBeat % 4 == 0)
|
|
|
|
{
|
2020-10-16 07:03:10 -04:00
|
|
|
if (curStep > (_song.notes[curSection].lengthInSteps) * (curSection + 1))
|
2020-10-13 04:07:04 -04:00
|
|
|
{
|
2020-10-16 07:03:10 -04:00
|
|
|
trace(curStep);
|
|
|
|
trace((_song.notes[curSection].lengthInSteps) * (curSection + 1));
|
|
|
|
trace('DUMBSHIT');
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
if (_song.notes[curSection + 1] == null)
|
2020-10-13 04:07:04 -04:00
|
|
|
{
|
|
|
|
addSection();
|
|
|
|
}
|
2020-10-13 01:18:50 -04:00
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
changeSection(curSection + 1, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
if (FlxG.mouse.x > gridBG.x
|
|
|
|
&& FlxG.mouse.x < gridBG.x + gridBG.width
|
|
|
|
&& FlxG.mouse.y > gridBG.y
|
|
|
|
&& FlxG.mouse.y < gridBG.y + (GRID_SIZE * _song.notes[curSection].lengthInSteps))
|
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;
|
|
|
|
|
|
|
|
if (FlxG.mouse.justPressed)
|
|
|
|
{
|
2020-10-13 21:23:22 -04:00
|
|
|
if (FlxG.mouse.overlaps(curRenderedNotes))
|
|
|
|
{
|
|
|
|
curRenderedNotes.forEach(function(note:Note)
|
|
|
|
{
|
|
|
|
if (FlxG.mouse.overlaps(note))
|
|
|
|
{
|
|
|
|
deleteNote(note);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.log.add('added note');
|
|
|
|
addNote();
|
|
|
|
}
|
2020-10-13 04:07:04 -04:00
|
|
|
}
|
2020-10-13 01:18:50 -04:00
|
|
|
}
|
|
|
|
|
2020-10-13 04:37:19 -04:00
|
|
|
if (FlxG.keys.justPressed.ENTER)
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
PlayState.SONG = _song;
|
2020-10-13 21:23:22 -04:00
|
|
|
FlxG.sound.music.stop();
|
2020-10-13 04:37:19 -04:00
|
|
|
FlxG.switchState(new PlayState());
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FlxG.sound.music.play();
|
2020-10-10 05:28:44 -04:00
|
|
|
}
|
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
if (FlxG.keys.justPressed.R)
|
|
|
|
{
|
|
|
|
if (FlxG.keys.pressed.SHIFT)
|
|
|
|
changeSection();
|
|
|
|
else
|
|
|
|
changeSection(curSection);
|
|
|
|
}
|
2020-10-14 00:05:55 -04:00
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
if (FlxG.keys.pressed.W || FlxG.keys.pressed.S)
|
|
|
|
{
|
|
|
|
FlxG.sound.music.pause();
|
2020-10-14 00:05:55 -04:00
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
var daTime:Float = 700 * FlxG.elapsed;
|
2020-10-14 00:05:55 -04:00
|
|
|
|
2020-10-14 04:18:19 -04:00
|
|
|
if (FlxG.keys.pressed.W)
|
|
|
|
{
|
|
|
|
FlxG.sound.music.time -= daTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FlxG.sound.music.time += daTime;
|
2020-10-14 00:05:55 -04:00
|
|
|
}
|
2020-10-13 04:07:04 -04:00
|
|
|
}
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
_song.bpm = Conductor.bpm;
|
|
|
|
|
2020-10-10 05:28:44 -04:00
|
|
|
if (FlxG.keys.justPressed.UP)
|
|
|
|
Conductor.changeBPM(Conductor.bpm + 1);
|
|
|
|
if (FlxG.keys.justPressed.DOWN)
|
|
|
|
Conductor.changeBPM(Conductor.bpm - 1);
|
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
if (FlxG.keys.justPressed.RIGHT)
|
|
|
|
changeSection(curSection + 1);
|
|
|
|
if (FlxG.keys.justPressed.LEFT)
|
|
|
|
changeSection(curSection - 1);
|
|
|
|
|
|
|
|
bpmTxt.text = "BPM: " + Conductor.bpm + "\nSection: " + curSection;
|
2020-10-10 00:22:26 -04:00
|
|
|
super.update(elapsed);
|
|
|
|
}
|
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
function changeSection(sec:Int = 0, ?updateMusic:Bool = true):Void
|
|
|
|
{
|
2020-10-16 07:03:10 -04:00
|
|
|
trace('changing section' + sec);
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
if (_song.notes[sec] != null)
|
2020-10-13 04:07:04 -04:00
|
|
|
{
|
|
|
|
curSection = sec;
|
|
|
|
updateGrid();
|
|
|
|
|
|
|
|
if (updateMusic)
|
|
|
|
{
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
|
|
|
|
var daNum:Int = 0;
|
|
|
|
var daLength:Int = 0;
|
|
|
|
while (daNum <= sec)
|
|
|
|
{
|
2020-10-16 07:03:10 -04:00
|
|
|
daLength += _song.notes[daNum].lengthInSteps;
|
2020-10-13 04:07:04 -04:00
|
|
|
daNum++;
|
|
|
|
}
|
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
FlxG.sound.music.time = (daLength - (_song.notes[sec].lengthInSteps)) * Conductor.stepCrochet;
|
|
|
|
updateCurStep();
|
2020-10-13 04:07:04 -04:00
|
|
|
}
|
2020-10-16 00:22:13 -04:00
|
|
|
|
|
|
|
updateSectionUI();
|
2020-10-13 04:07:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 00:22:13 -04:00
|
|
|
function updateSectionUI():Void
|
|
|
|
{
|
|
|
|
var sec = _song.notes[curSection];
|
|
|
|
|
|
|
|
stepperLength.value = sec.lengthInSteps;
|
|
|
|
check_mustHitSection.checked = sec.mustHitSection;
|
|
|
|
}
|
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
function updateGrid():Void
|
|
|
|
{
|
|
|
|
while (curRenderedNotes.members.length > 0)
|
|
|
|
{
|
|
|
|
curRenderedNotes.remove(curRenderedNotes.members[0], true);
|
|
|
|
}
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
var sectionInfo:Array<Dynamic> = _song.notes[curSection].notes;
|
2020-10-13 04:07:04 -04:00
|
|
|
|
|
|
|
for (i in sectionInfo)
|
|
|
|
{
|
|
|
|
var daNoteInfo = i[1];
|
|
|
|
|
|
|
|
var note:Note = new Note(i[0], daNoteInfo);
|
|
|
|
note.setGraphicSize(GRID_SIZE, GRID_SIZE);
|
|
|
|
note.updateHitbox();
|
|
|
|
note.x = Math.floor(i[1] * GRID_SIZE);
|
2020-10-13 05:55:00 -04:00
|
|
|
note.y = getYfromStrum(note.strumTime) % gridBG.height;
|
2020-10-13 04:07:04 -04:00
|
|
|
|
|
|
|
curRenderedNotes.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addSection(lengthInSteps:Int = 16):Void
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
_song.notes.push(new Section(lengthInSteps));
|
2020-10-13 04:07:04 -04:00
|
|
|
}
|
|
|
|
|
2020-10-13 21:23:22 -04:00
|
|
|
function deleteNote(note:Note):Void
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
for (i in _song.notes[curSection].notes)
|
2020-10-13 21:23:22 -04:00
|
|
|
{
|
|
|
|
if (i[0] == note.strumTime && i[1] == note.noteData)
|
|
|
|
{
|
|
|
|
FlxG.log.add('FOUND EVIL NUMBER');
|
2020-10-14 04:30:54 -04:00
|
|
|
_song.notes[curSection].notes.remove(i);
|
2020-10-13 21:23:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateGrid();
|
|
|
|
}
|
|
|
|
|
2020-10-13 01:18:50 -04:00
|
|
|
private function addNote():Void
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
_song.notes[curSection].notes.push([
|
2020-10-13 21:23:22 -04:00
|
|
|
Math.round(getStrumTime(dummyArrow.y) + (curSection * (Conductor.stepCrochet * 32))),
|
2020-10-13 05:36:45 -04:00
|
|
|
Math.floor(FlxG.mouse.x / GRID_SIZE)
|
|
|
|
]);
|
2020-10-13 05:55:00 -04:00
|
|
|
|
|
|
|
trace(getStrumTime(dummyArrow.y) + (curSection * (Conductor.stepCrochet * 16)));
|
|
|
|
trace(curSection);
|
|
|
|
|
2020-10-13 04:07:04 -04:00
|
|
|
updateGrid();
|
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
|
|
|
}
|
|
|
|
|
2020-10-16 07:03:10 -04:00
|
|
|
function calculateSectionLengths(?sec:Section):Int
|
|
|
|
{
|
|
|
|
var daLength:Int = 0;
|
|
|
|
|
|
|
|
for (i in _song.notes)
|
|
|
|
{
|
|
|
|
var swagLength = i.lengthInSteps;
|
|
|
|
|
|
|
|
if (i.typeOfSection == Section.COPYCAT)
|
|
|
|
swagLength * 2;
|
|
|
|
|
|
|
|
daLength += swagLength;
|
|
|
|
|
|
|
|
if (sec != null && sec == i)
|
|
|
|
{
|
|
|
|
trace('swag loop??');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-10-14 04:30:54 -04:00
|
|
|
trace(_song.notes);
|
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> = [];
|
|
|
|
|
2020-10-14 04:30:54 -04:00
|
|
|
for (i in _song.notes)
|
2020-10-13 04:07:04 -04:00
|
|
|
{
|
|
|
|
noteData.push(i.notes);
|
|
|
|
}
|
|
|
|
|
2020-10-13 04:37:19 -04:00
|
|
|
return noteData;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function saveLevel()
|
|
|
|
{
|
2020-10-10 00:22:26 -04:00
|
|
|
var json = {
|
2020-10-14 04:30:54 -04:00
|
|
|
"song": _song.song,
|
2020-10-13 04:07:04 -04:00
|
|
|
"bpm": Conductor.bpm,
|
2020-10-14 04:30:54 -04:00
|
|
|
"sections": _song.notes.length,
|
|
|
|
'notes': _song.notes
|
2020-10-10 00:22:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
var data:String = Json.stringify(json);
|
|
|
|
|
|
|
|
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-13 04:37:19 -04:00
|
|
|
_file.save(data.trim(), json.song.toLowerCase() + ".json");
|
2020-10-13 04:07:04 -04:00
|
|
|
_file.browse();
|
2020-10-10 00:22:26 -04:00
|
|
|
}
|
2020-10-09 22:39:52 -04:00
|
|
|
}
|
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");
|
|
|
|
}
|
2020-10-09 22:39:52 -04:00
|
|
|
}
|