1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-27 15:37:49 +00:00

sequencer in progress

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

View file

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

View file

@ -2,7 +2,10 @@ package;
import flixel.FlxG; import flixel.FlxG;
import flixel.FlxState; import flixel.FlxState;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.ui.FlxButton; import flixel.ui.FlxButton;
import flixel.ui.FlxSpriteButton;
import flixel.util.FlxColor;
import haxe.Json; import haxe.Json;
import openfl.events.Event; import openfl.events.Event;
import openfl.events.IOErrorEvent; import openfl.events.IOErrorEvent;
@ -13,36 +16,79 @@ import openfl.net.FileReference;
class ChartingState extends MusicBeatState class ChartingState extends MusicBeatState
{ {
var _file:FileReference; var _file:FileReference;
var sequencer:FlxTypedGroup<FlxSpriteButton>;
var notes:Array<Dynamic> = [];
override function create() override function create()
{ {
var saveButton:FlxButton = new FlxButton(0, 0, "Save", function() var saveButton:FlxButton = new FlxButton(0, 0, "Save", function()
{ {
// bullshit 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");
}
}); });
saveButton.screenCenter(); saveButton.screenCenter();
add(saveButton); add(saveButton);
createStepChart();
super.create(); 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 function onSaveComplete(_):Void
{ {
_file.removeEventListener(Event.COMPLETE, onSaveComplete); _file.removeEventListener(Event.COMPLETE, onSaveComplete);