1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-10-31 20:04:32 +00:00

save data bullshit

This commit is contained in:
Cameron Taylor 2020-10-09 20:22:07 -07:00
parent 4d4a724d72
commit 427ca3cb03
4 changed files with 92 additions and 13 deletions

View file

@ -1,11 +1,77 @@
package;
import flixel.FlxG;
import flixel.FlxState;
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;
class ChartingState extends FlxState
class ChartingState extends MusicBeatState
{
var _file:FileReference;
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, "swag.json");
}
});
saveButton.screenCenter();
add(saveButton);
super.create();
}
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");
}
}

View file

@ -9,7 +9,7 @@ class Main extends Sprite
public function new()
{
super();
addChild(new FlxGame(0, 0, TitleState));
addChild(new FlxGame(0, 0, ChartingState));
#if !mobile
addChild(new FPS(10, 3, 0xFFFFFF));

View file

@ -15,18 +15,16 @@ class MusicBeatState extends FlxTransitionableState
super.create();
}
private function everyBeat():Void
override function update(elapsed:Float)
{
if (Conductor.songPosition > lastBeat + Conductor.crochet - Conductor.safeZoneOffset
|| Conductor.songPosition < lastBeat + Conductor.safeZoneOffset)
{
if (Conductor.songPosition > lastBeat + Conductor.crochet)
{
beatHit();
}
}
everyStep();
super.update(elapsed);
}
/**
* CHECKS EVERY FRAME
*/
private function everyStep():Void
{
if (Conductor.songPosition > lastStep + Conductor.stepCrochet - Conductor.safeZoneOffset
@ -43,6 +41,9 @@ class MusicBeatState extends FlxTransitionableState
{
totalSteps += 1;
lastStep += Conductor.stepCrochet;
if (totalSteps % 4 == 0)
beatHit();
}
public function beatHit():Void

View file

@ -424,6 +424,9 @@ class PlayState extends MusicBeatState
openSubState(new PauseSubState());
}
FlxG.watch.addQuick('VOL', vocals.amplitudeLeft);
FlxG.watch.addQuick('VOLRight', vocals.amplitudeRight);
healthHeads.setGraphicSize(Std.int(FlxMath.lerp(100, healthHeads.width, 0.98)));
healthHeads.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)) - (healthHeads.width / 2);
@ -512,8 +515,6 @@ class PlayState extends MusicBeatState
FlxG.switchState(new PlayState());
}
}
everyBeat();
everyStep();
// better streaming of shit
if (health <= 0)
@ -1021,6 +1022,17 @@ class PlayState extends MusicBeatState
}
}
override function stepHit()
{
if (vocals.time > Conductor.songPosition + Conductor.stepCrochet || vocals.time < Conductor.songPosition - Conductor.stepCrochet)
{
vocals.pause();
vocals.time = Conductor.songPosition;
vocals.play();
}
super.stepHit();
}
override function beatHit()
{
super.beatHit();