1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-19 21:33:06 +00:00

sequencer in progress

This commit is contained in:
Cameron Taylor 2020-10-09 21:22:26 -07:00
parent daa41dafe1
commit 29615f24f7
2 changed files with 65 additions and 18 deletions

View file

@ -2,6 +2,7 @@
"lineEnds": {
"leftCurly": "both",
"rightCurly": "both",
"emptyCurly": "break",
"objectLiteralCurly": {
"leftCurly": "after"
}

View file

@ -2,7 +2,10 @@ package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.ui.FlxButton;
import flixel.ui.FlxSpriteButton;
import flixel.util.FlxColor;
import haxe.Json;
import openfl.events.Event;
import openfl.events.IOErrorEvent;
@ -13,36 +16,79 @@ import openfl.net.FileReference;
class ChartingState extends MusicBeatState
{
var _file:FileReference;
var sequencer:FlxTypedGroup<FlxSpriteButton>;
var notes:Array<Dynamic> = [];
override function create()
{
var saveButton:FlxButton = new FlxButton(0, 0, "Save", function()
{
// bullshit
var json = {
"song": "Bopeebo",
"bpm": 100,
"sections": 15
};
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);
_file.save(data, json.song + ".json");
}
saveLevel();
});
saveButton.screenCenter();
add(saveButton);
createStepChart();
super.create();
}
function createStepChart()
{
sequencer = new FlxTypedGroup<FlxSpriteButton>();
add(sequencer);
for (r in 0...2)
{
notes.push([]);
for (i in 0...16)
{
notes[r].push(false);
var seqBtn:FlxSpriteButton = new FlxSpriteButton((35 * r) + 10, (35 * i) + 50, null, function()
{
notes[r][i] = !notes[r][i];
});
seqBtn.makeGraphic(30, 30, FlxColor.WHITE);
seqBtn.ID = i + (16 * r);
sequencer.add(seqBtn);
}
}
}
override function update(elapsed:Float)
{
sequencer.forEach(function(spr:FlxSpriteButton)
{
if (notes[Std.int(spr.ID / 16)][spr.ID % 16])
spr.alpha = 1;
else
spr.alpha = 0.5;
});
super.update(elapsed);
}
private function saveLevel()
{
var json = {
"song": "Bopeebo",
"bpm": 100,
"sections": 15
};
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);
_file.save(data, json.song + ".json");
}
}
function onSaveComplete(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);