2020-10-09 22:39:52 -04:00
|
|
|
package;
|
|
|
|
|
2020-10-09 23:22:07 -04:00
|
|
|
import flixel.FlxG;
|
2020-10-09 22:39:52 -04:00
|
|
|
import flixel.FlxState;
|
2020-10-09 23:22:07 -04:00
|
|
|
import flixel.ui.FlxButton;
|
|
|
|
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-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-09 22:39:52 -04:00
|
|
|
override function create()
|
|
|
|
{
|
2020-10-09 23:22:07 -04:00
|
|
|
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, "swag.json");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
saveButton.screenCenter();
|
|
|
|
add(saveButton);
|
|
|
|
|
2020-10-09 22:39:52 -04:00
|
|
|
super.create();
|
|
|
|
}
|
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
|
|
|
}
|